Skip to content

[Prototype] Add multi-connection IPC support to pyrefly TSP#3199

Draft
heejaechang wants to merge 1 commit intofacebook:mainfrom
heejaechang:feature/tsp-multi-connection
Draft

[Prototype] Add multi-connection IPC support to pyrefly TSP#3199
heejaechang wants to merge 1 commit intofacebook:mainfrom
heejaechang:feature/tsp-multi-connection

Conversation

@heejaechang
Copy link
Copy Markdown

Teach the server to advertise and manage extra read-only channels for new TSP capabilities.

Teach the server to advertise and manage extra read-only channels for Pylance, and restore the numeric protocol wire form so cross-repo type round-tripping stays compatible with the shared contract.
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Apr 22, 2026

Hi @heejaechang!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@heejaechang heejaechang marked this pull request as draft April 22, 2026 01:21
Copy link
Copy Markdown
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some initial thoughts, but checking it out now to look closer

Comment thread pyrefly/lib/tsp/server.rs
// but will only respond to TSP protocol requests
capabilities(indexing_mode, initialization_params)
let mut result = capabilities(indexing_mode, initialization_params);
result.base.experimental = Some(serde_json::json!({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of exposing all of base, can we instead add a enable_multi_connection API and call it here?

Comment thread pyrefly/lib/tsp/server.rs
))
})?;

let extra_server = Self::with_connection(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clever to use an Arc server in order for both servers to use the same memory. If we keep this approach (I wonder about instead abstracting around connections), we should document it clearly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am testing an alternate approach here: 9e45b56

what do you think?

Comment thread pyrefly/lib/tsp/server.rs
);
drop(extra_connections);

std::thread::spawn(move || {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we abstract this out of here?

Comment thread pyrefly/lib/tsp/server.rs
}
}

fn get_pipe_name(&self, params: &ConnectionRequestParams) -> Result<String, ResponseError> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be a lot cleaner within the same module as ConnectionRequestParams. but I guess the protocol generation script doesn't allow that?

Comment thread pyrefly/lib/tsp/server.rs
})
}

fn handle_extra_request<'a>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's sketchy that a non-extra server can still call this function. maybe we need two server structs with two impls

}

pub fn ipc(pipe_name: &str) -> std::io::Result<(Self, MessageReader, IoThread)> {
#[cfg(windows)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize this is OS-dependent. did we consider TCP? it seems like it could be simpler + just as fast in practice?

Copy link
Copy Markdown
Author

@heejaechang heejaechang Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chose IPC so we don't need to worry about exposing the connection to remote? (also things like vscode will auto detect tcp port being opened, and try to open forward channel by default and etc for remote vscode case) we could support tcp as well, but if we are not planning to support remote case yet, I think ipc is simpler.

and when ipc is used, client and server is on the same machine so we don't need to worry about client/server on different OSes and etc.

@kinto0 kinto0 self-assigned this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants