Repository navigation
fix(ai): a run ended before it starts never launches its adapter; compact test waits for the run events - #670
Conversation
When two turns or compacts start on one thread at once, the newer run ends the older one during its setup. The run guard still called the older run's adapter, so its CLI launched alongside the newer run and the two overlapped. The guard now holds the ending on an AbortSignal and returns the ending event without calling the adapter when the run was already ended. The compaction test waited on opening the session event stream, which says nothing about the compact run, so its running check raced the server. It now opens the stream first and waits for both compact runs to announce themselves. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 28 minutes. View limit details
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. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified in the changes guarding canceled runs against adapter startup and correcting the compaction test’s timing.
No open issues 🎉
What changed in this PR
Prevents superseded AI runs from launching their adapters after cancellation and fixes the compaction test’s premature running-state check.
Changes:
- Uses an abort signal to track run endings and skip adapter startup for already-ended runs.
- Adds a regression test for takeover during setup.
- Makes the compaction test wait for two distinct run events before checking session state.
| File | Description |
|---|---|
packages/core/test/core-api.it.test.ts |
Waits for distinct run events before asserting compaction is running. |
packages/ai/test/ai.test.ts |
Tests cancellation before adapter startup and extracts shared server setup. |
packages/ai/src/server/run-guard.ts |
Checks cancellation before launching the adapter. |
packages/ai/src/server/chat-server.ts |
Uses abort controllers for run-ending events. |
.changeset/ai-run-guard-ended-before-start.md |
Records the AI package patch release. |
Review effort: Balanced
Why
core-api.it.test.ts > rpc wire > chat > compaction > compact runs as its own turn, never overlaps another, marks the boundary and keeps the historyfailed on CI (PR #664, shard 4) and locally withexpected false to be trueon therunningread. The RCA found a test defect and, behind it, a product bug.Test defect
chatKit().events(sessionId)only opens the session stream and resolves on headers; it waits for nothing. The test fired two compacts and readsessions.metabefore either run had written its row (15 of 15 instrumented runs read before any run announced itself; a 150ms delay beforedrivereproduces the exact CI assertion). The test now opens the stream first and waits for twoconciv.session-runevents with distinct run ids, which the server emits only after the running row exists.Product bug
Once the test waited on the real signal the two compacts ran concurrently and 9 of 30 runs failed the overlap assertion.
guardedAdapterinpackages/ai/src/server/run-guard.tsalways calledadapter.chatStreamand raced the first chunk against the run's ending, even when the ending had already fired. A run ended by a takeover before reaching the model still launched its CLI and was killed afterwards, so two CLI runs overlapped.Fix: the run's ending is an
AbortController(the platform's settled-state primitive) instead of aPromiseWithResolvers;guardedchecksended.abortedbefore starting the adapter and yields the ending event without launching anything.endRunsand the silence timeout callabort(event)where they calledresolve(event). Changeset for@conciv/ai.Regression case in the existing
packages/ai/test/ai.test.tsthroughcreateChatServer: a newer run ends an older one held in its setup, and only the newer adapter runs. It fails on the old code withexpected ['second', 'first'] to deeply equal ['second'].Verification
rpc wire > chatgroup 5 of 5.🤖 Generated with Claude Code