Repository navigation
fix(orchestration): preserve completed prompt dispatches - #15941
haoliangli wants to merge 1 commit into
Conversation
A worker can report completion before prompt verification times out. Treat that durable completion as authoritative instead of overwriting it with a stale prompt-delivery failure.
📝 WalkthroughWalkthroughThe Merge Risk: 🟡 Moderate · up to The fix preserves completed work after a prompt-verification race, but the completed response can still contain a stale dispatch status, causing callers to receive inconsistent settlement information. This bounded correctness issue should be fixed before merge; the regression test should also exercise the actual worker_done path. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.ts (1)
320-324: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winExercise the actual
worker_donepath.If this test is intended to cover the race named in the PR objective, the mock should call lifecycle reconciliation instead of updating the task directly. Direct
db.updateTaskStatusskipsworker_donepayload validation, Dispatch identity checks, and message settlement. The existinglifecycle-reconciliation.test.tsuses aworker_donemessage containingtaskIdanddispatchId; reuse that path before throwing the prompt error.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3207852e-78d4-423e-917e-adb80f7a678b
📒 Files selected for processing (2)
src/main/runtime/rpc/methods/orchestration-tasks-dispatch.test.tssrc/main/runtime/rpc/methods/orchestration.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| const settled = db.getDispatchContextById(ctx.id) | ||
| if (settled?.status === 'completed') { | ||
| injected = true | ||
| } else { | ||
| db.failDispatch(ctx.id, err instanceof Error ? err.message : String(err)) | ||
| throw err | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Return the settled Dispatch row.
The code reads settled at Line 1702, but the response still returns ctx at Lines 1714-1716. ctx was created before the race and can still contain status: 'dispatched' while the durable row is completed. Return settled on this branch so the response matches the authoritative state.
Proposed fix
const settled = db.getDispatchContextById(ctx.id)
if (settled?.status === 'completed') {
- injected = true
+ if (params.returnPreamble) {
+ return { dispatch: settled, injected: true, preamble }
+ }
+ return { dispatch: settled, injected: true }
} else {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const settled = db.getDispatchContextById(ctx.id) | |
| if (settled?.status === 'completed') { | |
| injected = true | |
| } else { | |
| db.failDispatch(ctx.id, err instanceof Error ? err.message : String(err)) | |
| throw err | |
| } | |
| const settled = db.getDispatchContextById(ctx.id) | |
| if (settled?.status === 'completed') { | |
| if (params.returnPreamble) { | |
| return { dispatch: settled, injected: true, preamble } | |
| } | |
| return { dispatch: settled, injected: true } | |
| } else { | |
| db.failDispatch(ctx.id, err instanceof Error ? err.message : String(err)) | |
| throw err | |
| } |
Summary
Prevent
orchestration dispatch --injectfrom reportingagent_prompt_stalledafter the dispatched worker has already completed the task throughworker_done.Problem
Prompt submission verification can time out while the worker has already received the lifecycle preamble, executed the task, and durably completed the Dispatch. The injection catch path currently calls
failDispatchand rethrows the stale prompt error without re-reading settlement state. This produces a contradictory result: the CLI reports failure even though the Task and Dispatch are completed. A coordinator may then retry work that already ran.Approach
completed, treat the durable settlement as authoritative and returninjected: true.worker_done/ prompt-verification race.Verification
orchestration-tasks-dispatch.test.ts: 31/31 passedagent_prompt_stalled) and passes with the fixtypecheck:node: passedoxfmt --checkon changed files: passedoxlinton changed files: passedgit diff --check: passedScope
This change is limited to the low-level local
orchestration.dispatch --injectsettlement race. It does not change agent recognition, prompt submission timing,worker-startlaunch behavior, or terminal ownership/release semantics.Related: #15920