Skip to content

Conversation

@celia-oai
Copy link
Contributor

@celia-oai celia-oai commented Nov 1, 2025

Add cancellation registry and $/cancelRequest, so that long-running Json-RPC endpoints can orchestrate their own cancellation logic. This is in line with the LSP protocol (doc). Registered cancellation for login_chatgpt, so $/cancelRequest performs the same as the legacy cancelLoginGpt endpoint.

@celia-oai celia-oai force-pushed the dev/cc/add-cancel-pattern branch 4 times, most recently from a9debc6 to fe3e787 Compare November 1, 2025 01:57
@etraut-openai etraut-openai added the oai-pr PRs posted by Codex team members label Nov 1, 2025
@celia-oai celia-oai force-pushed the dev/cc/add-cancel-pattern branch 2 times, most recently from 49e3a84 to 37b6a71 Compare November 1, 2025 03:29
@celia-oai celia-oai changed the title tmp [app-server] Add cancellation registry and $/cancelRequest Nov 1, 2025
@celia-oai celia-oai force-pushed the dev/cc/add-cancel-pattern branch from 37b6a71 to 65586a3 Compare November 1, 2025 03:31
@celia-oai celia-oai force-pushed the dev/cc/add-cancel-pattern branch from 65586a3 to 2b1b3ea Compare November 1, 2025 05:11
@celia-oai celia-oai force-pushed the dev/cc/add-cancel-pattern branch from 2b1b3ea to 18b3fd8 Compare November 1, 2025 05:14
@celia-oai celia-oai marked this pull request as ready for review November 1, 2025 05:31
Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +27 to +35
pub(crate) fn insert<F>(&self, id: RequestId, f: F)
where
F: Fn() + Send + 'static,
{
self.inner
.lock()
.unwrap_or_else(PoisonError::into_inner)
.insert(id, Box::new(f));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Badge Allow FnOnce cancellation callbacks

The new registry only accepts F: Fn() + Send + 'static, which means every cancellation action must implement Fn. That rules out the most common patterns for cancelling background work, e.g. signalling a tokio::sync::oneshot::Sender or taking ownership of an abort handle, because closures such as move || tx.send(()) are only FnOnce. Trying to register one of those today will not compile, so long-running requests that rely on a one-shot cancel signal still cannot integrate with $/cancelRequest, defeating the purpose of this feature. Please change the registry to handle FnOnce callbacks (e.g. by storing them behind an Option/Mutex so they can be invoked exactly once).

Useful? React with 👍 / 👎.

#[serde(rename = "$/cancelRequest")]
#[ts(rename = "$/cancelRequest")]
#[strum(serialize = "$/cancelRequest")]
CancelRequest(CancelRequestParams),
Copy link
Contributor

Choose a reason for hiding this comment

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

ah very interesting that this is done as a notification. makes sense after reading https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#cancelRequest

Copy link
Contributor

@owenlin0 owenlin0 Nov 1, 2025

Choose a reason for hiding this comment

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

ah, looks like this might not be applicable to login. the use case for a $/cancelRequest call seems to be:

  1. client makes a request to server
  2. server is processing, no response sent yet
  3. client sends a $/cancelRequest notification
  4. server responds to the original request with a response with ErrorCodes.RequestCancelled

so this seems generally useful to interrupt long-running operations.

whereas with chatgpt login, we do:

  1. client makes an account/login request
  2. server immediately responds with {"login_id": uuid, "auth_url": }, where the url needs to be opened in a webview on the client
  3. user authenticates via the webview
  4. server sends a notification to the client indicating the login was successful

the auth URL looks like:
https://auth.openai.com/oauth/authorize?response_type=code&client_id=app_EMoamEEZ73f0CkXaXp7hrann&redirect_uri=http%3A%2F%2Flocalhost%3A1455%2Fauth%2Fcallback&scope=openid%20profile%20email%20offline_access&code_challenge=[code]&code_challenge_method=S256&id_token_add_organizations=true&codex_cli_simplified_flow=true&state=[state]&originator=codex_cli_rs

So the codex process starts up an HTTP server on port 1455 to listen for the redirect after login is successful, and then update its auth storage. Asking codex, looks like it'll time out in 10 mins if user doesn't complete login flow and there's no cancellation. We expose the CancelChatGptLogin request as a way to immedately cancel the login, mostly for UX I think (i.e. they can render a "cancel login" button in their UI).

tldr my 2c: based on our convo with pavel, I think we actually want to name it account/login/start and pair it with account/login/cancel since the login request returns immediately with a URL

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for the back and forth on this!

@celia-oai
Copy link
Contributor Author

closed in favor of accounts/login/cancel

@celia-oai celia-oai closed this Nov 3, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

oai-pr PRs posted by Codex team members

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants