fix(server): keep provider notification consumers alive past startSession #6538
main fromrefs/pull/6538/head·merged by juliusmarminge View on GitHubFixes #5781.
What Changed#
CursorAdapter, GrokAdapter and CodexAdapter fork their notification consumer with Effect.forkChild inside startSession. That makes the consumer a child of the calling fiber, and Effect interrupts a fiber's children when it completes, so the consumer dies the moment startSession returns and every notification the provider streams afterwards is dropped.
Each adapter switches to Effect.forkIn with the session scope it already has:
| File | |
|---|---|
CursorAdapter.ts:877 | Effect.forkIn(ctx.scope) |
GrokAdapter.ts:879 | Effect.forkIn(ctx.scope) |
CodexAdapter.ts:1733 | Effect.forkIn(sessionScope) |
Why#
The user-visible symptom is a thread that sits on "Working" forever: the request succeeds, the provider streams its whole turn, and nothing is projected.
Nothing else needed to change. Cursor and Grok already create a session scope, store it on the session context, and close it during teardown; Codex does the same with a local sessionScope. Only the fork target was wrong. CodexSessionRuntime one layer down already uses Effect.forkIn(runtimeScope), so this makes the adapters consistent with the pattern the codebase already follows.
On the tests#
The existing tests cannot catch this, which is worth being explicit about. They call startSession directly from the test fiber, and that fiber never completes, so the consumer stays alive and the bug is invisible. Any test written that way passes with or without the fix.
Each new test instead runs startSession in a fiber and joins it, which is what production does, then asserts that a notification arriving afterwards is still projected.
Verified by mutation, one adapter at a time:
Grok with fix: pass 488ms forkChild restored: fail 10.4s
Cursor with fix: pass forkChild restored: fail 10.4s
Codex with fix: pass forkChild restored: fail 10.0s
They also run on the live clock. Under the default test clock the timeouts wait on virtual time that never advances, so a regression would hang until the suite timeout instead of failing at the assertion. Without TestClock.withLive the failing case took 60s instead of 10s.
Verification#
Run on Linux, since the mock ACP wrapper is a POSIX shell script and these suites do not run on Windows:
apps/server/src/provider/Layers/— 350 tests pass- server typecheck exits 0
- lint clean
UI Changes#
None.
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes (n/a)
- I included a video for animation/interaction changes (n/a)
Note
Medium Risk Touches core provider session lifecycle and fiber scoping for Codex, Cursor, and Grok; wrong scope/fork behavior could drop events or leak fibers, but the change is narrow and covered by new regression tests.
Overview
Fixes threads stuck on Working after startSession returns: provider streams kept running but nothing reached the UI because the runtime notification consumers were forked with Effect.forkChild on the startSession fiber. Effect interrupts children when that fiber finishes, so consumers died as soon as the request completed.
Codex, Cursor, and Grok adapters now fork event/notification consumers with Effect.forkIn on the existing session scope (sessionScope / ctx.scope), so they outlive the caller and keep projecting deltas and turn lifecycle until teardown.
Each adapter gets a regression test that runs startSession in a short-lived fiber (matching production), then asserts post-start streaming still works; tests use TestClock.withLive so timeouts fail fast on regression instead of hanging the suite.
Note
Fix provider notification consumers to persist past startSession completion#
In CodexAdapter, CursorAdapter, and GrokAdapter, the notification/event consumer fibers were forked as children of the startSession caller fiber, causing them to be interrupted when startSession returned. This meant runtime events and session notifications stopped flowing to the adapter event stream after session startup.
- Replaces
Effect.forkChildwithEffect.forkIn(sessionScope)(orctx.scope) in each adapter'sstartSessionflow, tying the consumer fiber lifetime to the session scope instead of the calling fiber. - Adds regression tests to each adapter verifying that events continue to be emitted after the
startSessionfiber completes.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved 8c0bc32
Straightforward bug fix changing
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Effect.forkChildtoEffect.forkIn(sessionScope)in three adapter files to prevent notification consumers from being interrupted when the startSession fiber completes. The production changes are minimal single-line fixes, with most additions being comprehensive regression tests.juliusmarminge merged thisafca73d
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
caf290c0-e470-4cbc-9708-b98c5afcc6b2You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share