codex icon indicating copy to clipboard operation
codex copied to clipboard

[app-server] let idle auto-attached threads unload

Open chess-oai opened this issue 4 months ago • 2 comments

summary

  • distinguish implicit observer attachments from explicit retaining subscriptions while preserving event and server-request delivery
  • allow idle core-created threads with no explicit subscribers to reach the existing 30-minute unload lifecycle
  • use retaining-subscriber semantics for running resume overrides and preserve the full idle grace period across coalesced watcher edges

why

app-server auto-attaches every initialized connection to internally created threads so clients can observe events and answer requests. those delivery-only attachments currently share subscription bookkeeping with explicit thread/start, thread/resume, and thread/fork requests, so the idle-unload watcher never sees zero subscribers. this leaves otherwise idle threads and their session resources loaded indefinitely

testing

  • just test -p codex-app-server --test-threads=2 (936 passed, 1 skipped)
  • focused implicit/explicit, mixed-state, reactivation, coalesced-edge, and running-resume regressions
  • just fix -p codex-app-server
  • just fmt

chess-oai avatar Jul 03 '26 05:07 chess-oai


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

github-actions[bot] avatar Jul 03 '26 05:07 github-actions[bot]

I refreshed this fix onto current main (6c00dc087e) and resolved the two app-server conflicts without changing the protocol or isolation boundaries.

Refreshed commit: https://github.com/zierocode/codex/commit/fb3ab904c27fcdef6f035dcd7dc59229212476e2 Branch: https://github.com/zierocode/codex/tree/codex/idle-auto-attached-threads

Verification on the refreshed tree:

  • just test -p codex-app-server: 981 passed, 1 skipped
  • just fix -p codex-app-server and just fmt: clean
  • focused coverage includes implicit delivery without retention, implicit-to-explicit upgrade, connection removal, and last-explicit-subscriber behavior
  • exact installed-tag RED/GREEN validation plus a 30-minute runtime soak confirmed MCP child processes and RSS return to baseline after idle unload

The repository currently limits new pull requests to collaborators, so I cannot open a replacement PR from the fork. A maintainer can cherry-pick fb3ab904c27fcdef6f035dcd7dc59229212476e2 or update this PR head with the refreshed tree. I am not signing or accepting the CLA on behalf of the original author.

zierocode avatar Jul 21 '26 20:07 zierocode

I independently reproduced the lifecycle issue from #11324 and prepared a current-main fork patch that overlaps this draft while adding coverage for two ownership paths and the unload race:

  • Draft fork PR: https://github.com/freaksdotcom/codex/pull/1
  • Commit: https://github.com/freaksdotcom/codex/commit/1985ff4ba1a5e689232f5cd8c0767952f875317d
  • Branch: https://github.com/freaksdotcom/codex/tree/agent/dispose-mcp-on-last-unsubscribe

During review, I found that normal turn/start and inline review/start could still submit work from an Auto-attached connection without upgrading it to retaining ownership. Near the unload deadline, those paths could also race the closing commit. The fork patch adds a serialized admission helper under the pending-unload lock and calls it immediately before normal turn and inline-review submission. The request either wins with Auto→Explicit ownership established or fails after closing is committed.

Additional regression coverage includes:

  • real automatic event delivery through an internally spawned child
  • direct turn/start ownership upgrade without resume
  • committed-closing rejection without mutating the Auto attachment
  • exact 30-minute deadline and resubscription reset
  • last-owner unsubscribe/disconnect grace
  • transcript-preserving cold resume
  • inline-review submission

Focused tests pass, along with just fix -p codex-app-server, just fmt, and git diff --check. The upstream repository currently rejects PR creation from this account, so a maintainer would need to compare/cherry-pick the fork commit or incorporate the additional admission/test changes into this draft.

freaksdotcom avatar Jul 26 '26 19:07 freaksdotcom