Repository navigation
fix(orchestration): a task's ending reaches its filer once, on the defaults too (FIX-2123) - #3733
Conversation
…faults too (FIX-2123)
A notice was admitted by a read, not a claim, so a filer's wait and its
onTaskSettled could both deliver one ending. Now:
- A row records the request that filed it (server-side, from the engine's
request identity, only in the filer's own session). Its notice is turned
away, as `defer` turns one away, while that request still runs, and the
request sends it as it ends (the request-end seam), past any backoff. A
wait in the filing request reads the ending first and drops the notice.
- taskSettledEntry takes a notice in one conditional write before it runs
the block (`takeNotice`, both backings). A wait's drop and a take can't
both go through. A block that throws leaves the notice owed, and the next
copy takes it over once the failed request has ended.
- A wait that finds the notice taken (still owed, or its request still
running) answers `{ ok, taskId, arrivesAsNotice, message }`, naming the
task, instead of the ending.
Tests: the defaults path and Workforce `hold` path, red first, on the
in-memory and SQLite stores, and on both backings for the take; a turn that
never waits still hears its ending once, as it ends; a failed block's notice
is taken over.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 0a2ca801-b265-4f8e-85cd-e6be2e41e2ed) |
Update "Waiting on a task" and "Hearing how a task ended": a wait on an already-ended task takes the ending whatever the entry's options, a wait while the notice is being handled gets arrivesAsNotice, and a notice is held until the request that filed the task has ended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: e140a22d-1d06-42d8-aed3-9dd00806d416) |
…eld (FIX-2123) The send at the filing request's end registered a request-end hook at every filing on a board that delivers. A context built outside a request's run (testBlock's) never runs its hooks, and the engine keeps owed hooks process-wide: every later host shutdown in the process then waited out its 10 s drain budget. On CI's shared module cache that made wait-on-task.test.ts time out test by test. The hook is registered only where a notice can be held for the request: a host that records which requests have ended (`requestHost.waits.ended`). Anywhere else nothing is held, so nothing needs sending at its end. Regression test: a row filed under testBlock, then a host's dispose finishes in under 2 s (it took the 10 s budget before). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 4b456f12-894c-4dd2-a594-5554e65c4f15) |
|
CI's Cause: the send at the filing request's end registered a request-end hook at every filing on a board that delivers. A context built outside a request's run never runs its hooks ( Fix: the hook is registered only on a host that records which requests have ended ( Regression test: Checks:
The docs commit 7e5b3c9 ( Generated by Claude Code |
jhoffner
left a comment
There was a problem hiding this comment.
Stand-in review (Bugbot is out of usage) at 0501d1522. I traced the five areas below in code and ran the new tests plus two mutations in a throwaway worktree.
🔴 A filing request parked on a person or on getTask holds the notices of every other task it filed, with no upper bound
The question: should a notice wait out a park, or only a running turn?
The trace:
task-settled-entry.tsturns a notice away while!(await hasEnded(ctx, filing)).hasEndedreadsrequestHost.waits.ended. Inengine/src/durability/wait-chain.ts,endedis true only forWORK_OVER(completed / incomplete / failed / aborted), or forinterruptedwhen nothing will drive the request again. Asuspendedrequest reads not ended.- So for the whole of a park, each copy the pass sends is deferred (
deferredNoticePatch), and the notice's age is reset each time.
Take a turn that files B and then asks a person for approval. Before this PR, B's notice woke its own turn during the park: the park releases the session's concurrency key, and the resume takes it back (execution-and-errors.md, FIX-2062). Now B's ending is silent until the person answers. If the approval has no expiry, that can be never. The same holds for a turn parked on getTask for A: B's ending waits on A. A person who is waiting to hear B before they approve is stuck. The PR names this under Consequences, but it is a behaviour change users will see, and it wasn't put to a product decision. (I couldn't find a written FIX-2077 rule about notices during a person-park. FIX-2077 is the request-end seam and waitingOn. Today's behaviour is still what users get, and this PR takes it away.)
The reason given ("treating parked as ended would let a resumed turn's wait on B race B's notice again") is now covered by the take this PR adds. If B's notice is admitted during the park and taken, a resumed wait on B finds the take. deliveredByWait leaves the marker, and noticeDelivery makes the wait answer arrivesAsNotice. That is one hearing. Recommendation: hold only while the filing request is actually running. That needs waits to tell suspended apart from running. Today ended folds the two together, so this is an engine-side addition. The other option is to keep the hold and get explicit sign-off that a parked turn silences its other tasks. What being wrong costs: a conversation goes quiet on finished work for as long as a person takes to answer.
🟡 The request-end send is lost across a park, so a parked-then-ended filing request delivers late
createDelivery.whenRequestEnds registers on onRequestEnded, and the hook returns early on status === "suspended". Request-end hooks run on the suspension path (request-end-hooks.ts), so the hook is used up at the park. The resumed run's collection starts with an empty filedHere and never registers again. Held notices then go out at the pass's next resend. After a long park their backoff has grown to the cap (NOTICE_RESEND_CAP_MS = 5 min). The PR says so, but it is cheap to fix: on resume, re-register for the rows whose filer.requestId === ownRequest, or call resendNowPatch on them when the resumed request ends.
🟡 "Only once" while the first taker still runs is not covered by any test
In the worktree I removed this line from task-settled-entry.ts:
if (taker !== undefined && taker !== own && !(await hasEnded(ctx, taker))) return { owed: false };The full orchestration suite (2100/2100) still passed, and so did Workforce's conversation-board-{wait,notices,notice-bounds}. Without that line, a second copy calls takeNotice with replacing: taker and takes a notice from a request that is still delivering it, so the block runs twice. That can happen when a notice turn parks on a person and the pass resends. The failed-block test in notice-defer.test.ts runs on a host where the first taker has already ended, so it covers only the takeover branch. A test where the taker is still running (or parked) and a resend arrives would pin this line.
🟣 Not blocking
- A taken notice whose taker is parked ages out. A copy that finds a running taker returns
{ owed: false }withoutdeferredNoticePatch. If the taker is parked longer thanmaxDebtAgeMs(24 h by default),pass.tssettles the notice undeliverable while it is still being delivered. A rare edge, and better than before this PR, when the block would have run again. - A crashed filing request.
endedreadsinterruptedas ended unless it will be driven again, so the hold lifts. The request-end hook never fires, so the notice goes out at the next resend (≤ 5 min after the sweep marks the request interrupted). Not lost. - BP-031: holds.
filer.requestIdandtake.byboth come fromctx.request.identity.id.buildInitialTasknever readsfilerfrominit. One nit:createTask'sinit.metadatapassesnoticeTaken:*keys through unfiltered, as it already doesnoticeOwed:*. A planted take suppresses the wait's drop, but the takeover path still delivers the notice once, so this is not an auth problem. Consider stripping notice-record prefixes from init metadata.
Verified, no finding
- Take vs drop on both backings.
noticeReadByWaitWriteandnoticeTakeWriteare both decided insidepatchRef/patchOneon the row as stored. A drop needs a sendable marker and no taker; a take needs a sendable marker and a taker of none / self /replacing. Exactly one goes through. "Neither" only happens when the taker's block fails, and the takeover covers that. Two concurrent takeovers: the second one'sreplacingno longer matches, so it is refused. - Failed block's takeover. Re-sent by the pass (
owesUntakenNoticerightly leaves taken markers out of the request-end send), and taken over once. The test passes. - Mutation that bites. In
deliverEndedBeforeWait, replacing theended([delivery.by])check withreturn falsefails Workforce's FIX-2123 test. Orchestration'snotice-claim.test.tsstill passes, so the marker-cleared-before-the-turn path is pinned only in Workforce. notice-claim,notice-deferandnotice-taketests pass (18/18).
Generated by Claude Code
…aker is never replaced (FIX-2123) Review 5630613272 on #3733: - A notice is held only while the request that filed its task is running, not while it is parked on a person or a wait. Core's RequestWaits gains an optional `running(requestIds)`, which the engine implements (in_progress, this session); `ended` folded suspended and running together. The request sends what it held as it parks too: the record still reads in_progress while its hooks run, so the filer's pass is owed shortly instead. - A request that runs again after its park notes the rows it filed when it resolves the board, so it sends what it held as it next parks or ends. Registered once per request and board; never on a ledger that owes no notices (a plan board). - A wait on a task whose notice another request took answers arrivesAsNotice whether that notice is under way or done. - A copy that finds the notice taken by a request that hasn't ended, running or parked, runs nothing and records itself as turned away, so the notice doesn't age out while it is delivered. - A filing's metadata can't carry notice records. Tests: a filer parked on a person hears its task during the park, and its resumed wait answers arrivesAsNotice; a request that runs again after its park sends the held notice as it ends; a second copy beside a running or parked taker runs nothing (red when the live-taker line goes); engine `running` tells running from parked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 47199593-933f-4e70-9817-818770e5ee3c) |
|
Replies to review 5630613272, finding by finding. The fixes are in adbcf0b. 🔴 A parked filing request holds its other tasks' notices. Fixed, per the EM's call: a notice is held only while the filing request is running.
🟡 The request-end send is lost across a park. Fixed by re-registering on resume.
🟡 "Only once" while the first taker still runs.
🟣 A taken notice is marked undeliverable mid-delivery. Fixed. A copy that finds a live taker now records itself as turned away ( 🟣 A crashed filer's notices arrive late. Left as is. The hold lifts once the request reads as interrupted, and the next resend (at most 5 minutes later) delivers it, so nothing is lost. 🟣 Checks:
The Generated by Claude Code |
…etired ask word (FIX-2123) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 5868ae48-96c8-46fb-a7aa-bbdfa0fd8310) |
…AsNotice after the notice starts (FIX-2123) Correct "Hearing how a task ended" and "Waiting on a task": a notice waits only while the filing request is running and goes out during a park; any wait after an onTaskSettled request for the ending has started gets arrivesAsNotice, whether that request is still running or finished. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 86738494-372b-483c-a88e-6d91d4dba26a) |
jhoffner
left a comment
There was a problem hiding this comment.
Stand-in review, round 2 (Bugbot is out of usage), at dc20268c8. I reviewed 0501d1522..dc20268c8, skimmed the whole PR against main, and ran mutations in a throwaway worktree, since removed. On the unmodified head: orchestration 2108/2108, workforce 1566/1566, engine wait-chain.test.ts 15/15.
🔴 The park-time send opens a lost-resume window. The notices === false guard hides it on plan boards only.
The question: should a request do board I/O in its request-end hook while it parks?
The worker didn't confirm why worker-plans-its-steps broke. I tracked it down. The guard is a mask, not a fix.
- What the hook does at a park. Before this round,
whenRequestEndsreturned straight away onsuspended. Now it runs at the park:adoptUnknownRows(a fullcollection.list()), then arefresh(anupdateStateround trip) for every row the request filed, thenowePassAt. - Where that lands in the engine.
runAction.tsruns request-end hooks before the record is writtensuspended, and after the wait gate has been stored. A task-bound wait whose task ends inside that window gets resumed throughpayOwedResumes→resumeWaitGate.resumeWaitGatesees a pending gate on a request that still readsin_progress, so it refuses withalready-resolved("…not parked"). That refusal isn't the retryablebusy.payOwedResumestreatsalready-resolvedas done and clears theresumeOwedmarker, so nothing resumes the turn until the wait's deadline. - Evidence on the plan board. I removed the guard and logged the hook. It never patched a row (
owesUntakenNoticewas false for all three steps). Its only effect was the time it took. With the guard removed and the hook made a no-op, the FIX-2082 D2 tests pass. Add a 100 ms sleep to that no-op hook and they fail the same way the worker saw (s-draftstayspending, no answer turn). A 5 ms sleep passes. - Evidence on a delegation board, where the guard doesn't apply. I put the guard back and added a sleep only on the
parkedbranch of the hook.conversation-board-wait.test.ts› "a task session's turn that waits on a task it filed (FIX-2082) › waits, reads the task as it ended, and answers its own task from it" fails at 30 ms: it times out at 10 s. With no sleep it passes in 476 ms. The suite passes today only because in-memory I/O is fast. On SQLite or Postgres, a list plus one round trip per filed row can take 30 ms or more. - What users see. A turn that files tasks on a conversation board and then waits on one of them can miss that task's ending, if it lands while the turn is parking. The wait then resumes at its deadline (five minutes by default) with the task as it stood, not its ending.
Recommendation: fix the window in the engine and drop the guard. A pending gate whose request still reads in_progress is "not parked yet", so resumeWaitGate should refuse it as busy (retryable), the way it already does for an interrupted request with no gate on its log. The alternative is to re-check task-bound waits after suspended is recorded, as resumeIfChildEnded does for request-bound ones. If neither fits this PR, at least make the park branch do no board I/O: owe a single pass wake. Note that the park send isn't pinned by any test (next finding), so trimming it costs no coverage.
What would change my mind: if already-resolved on a pending gate in an in_progress request is caught somewhere I missed, this drops to 🟡. The 30 ms reproduction above says it isn't caught.
What being wrong costs: waits in production stall for their whole deadline, intermittently and depending on store latency. That is hard to debug from the outside.
🟡 The park-time owePassAt is not pinned by a test
When I replaced if (parked) await delivery.hooks.owePassAt(current, now() + NOTICE_DUE_MS) with a no-op, notice-claim and notice-defer still passed (16/16). That includes "a filing request parked on a person holds nothing…", which presumably gets its notice from the pass's ordinary resend. Fix 2 ("a request that parks sends what it held") is a claim with no red state. Either pin it (for example, assert the notice is heard within roughly NOTICE_DUE_MS + ε of the park, with the resend backoff above that) or drop it as part of resolving the 🔴.
🟡 task-board.md now gets a lapsed wait wrong
The new text says: "If it ends while your request is parked on something else, or your request ends without reading it, you hear about it once, the usual way." The code doesn't do that. After a wait's deadline the row's slot is lapsed. markerFor records an ending onto it as held: true, which isn't sendable. releaseAtRequestEnd keeps the slot across a park ("an ending that lands meanwhile is held for its read after the resume"), and releaseEndedWaits releases it only on ended. So the request's next getTask after the resume returns the ending. That is exactly what the old text said ("even while your request waits on something else, your next getTask on it returns the ending"), and the README still says it. The running/parked rule applies to other tasks' notices, not to a lapsed wait's own ending. Restore the old sentence for the lapsed-wait case.
Otherwise the page matches the new behaviour and has no implementation leakage.
🟣 Not blocking
- A host with
endedbut norunningsilently loses the hold. BothisRunningand thewhenRequestEndsguard key offrunning. A third-partyRequestWaitswritten against round 1 (which hasended) goes back to the pre-PR race. That is safe, because the take still makes wait and notice exclusive. The core/engine changeset could still say that implementers should addrunningto keep notices held. - A park whose record write takes longer than
NOTICE_DUE_MS(2 s). The pass wakes, still readsin_progress, and turns the notice away. It then waits for the resend backoff. That's late, not lost.
Verified, no finding
running()in the engine isin_progressANDrecord.sessionId === inputs.sessionId, andfalsefor no record, an unreadable record, parked, ended, died, re-driven, or another session. The engine test covers each of these. A crashed request readsin_progressuntil the sweep marks it, so the hold lasts until then, asendeddid before.- A host without
running:isRunning→false(nothing held), andwhenRequestEndsdoesn't register, so nothing is owed at dispose. Consistent. - Re-registration on resume: the
sendsAtStopWeakMap is keyed by the request-end seam.createExecutionContextbuilds one registry per run, so a resume gets a fresh seam and registers again. Mutation: with the constructor-timenoteFiledskipped, "a request that runs again after its park sends the notice it held as it ends" fails on both in-memory and SQLite. ✅ - The hold rule: mutation to put back
!hasEnded(filing)in place ofisRunning(filing). "a filing request parked on a person holds nothing…" fails on both backings. ✅ - The live-taker line keeps
hasEnded, so a parked notice turn isn't taken over, and the copy now recordsdeferredNoticePatch(round 1's 🟣 is fixed).deliveredAsNoticedropping theended(taker)check is right, now that the take is the single source. - At request end the record already reads
completedbefore the hooks run, sodeliverAfterisn't turned away by the filing request's own hold. buildInitialTaskstrips notice records viawithoutNoticeMarkers, andnotice-take.test.tscovers it.- BP-007:
RequestWaits.runningis documented on the type, and so areDeliveryHooks.whenRequestEndsandisRunning. Changesets:request-waits-running.md(core + engine, patch) anda-notice-is-taken-once.md(orchestration, patch) are both present.
Generated by Claude Code
…ked request held (FIX-2123) Review 5631310696 on #3733. The request-end hook ran at a park too, doing a list, a refresh per filed row and a pass wake. Engine hooks run before the record is written suspended, so that time widened a window in which a task-bound wait's resume is refused already-resolved and its resumeOwed marker cleared: the turn stalled until its deadline. The notices === false guard only hid it on plan boards. Now the hook does nothing at a park: a parked request holds no notice, so the filer's pass sends what it held at the notice's next send. The guard is gone; worker-plans-its-steps and the FIX-2082 waits pass without it, and still pass with 100 ms added to the hook after the park return. Unit test: whenRequestEnds runs nothing at a park and sends once the request ends (red without the park return); once per request and board; nothing on a host that doesn't record running requests. The core/engine changeset says a host with its own RequestWaits should add `running`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 9450d788-b25f-4989-a506-fa2587902f4a) |
|
Replies to review 5631310696. The fixes are in 0652a15. 🔴 Board I/O at a park. Fixed by doing no I/O at a park, per the EM's call.
🟡 The park-time 🟡 🟣 A host with 🟣 A park whose record write takes longer than Checks:
Generated by Claude Code |
…sed wait's ending goes to the next getTask (FIX-2123) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 652954d5-a8cf-405f-9e01-cbdfc2aa0d11) |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: a994d635-034f-4a60-a7ff-5319c144b0d5) |
There was a problem hiding this comment.
Simplify / architecture read (FIX-2123)
I read the full diff (~1.1k lines) with parallel passes on code quality, performance, and reuse. No blocker from this review; the size is mostly tests and docs, which match the risk.
Did the approach go too far?
The bug is really three coupled races, not one:
- Filing turn still running —
onTaskSettledmust not beat the filer'sgetTask({ wait })to the ending. - Park vs end — holding must follow running, not “request exists,” or parked turns stall notices incorrectly.
- Wait drop vs notice admit — FIX-2112 drop and dispatch need a single winner under concurrent writes.
A narrower fix (Workforce-only defer, or wait-drop tweaks without defaults) would leave default boards and cross-request races. Extending RequestWaits.running + filer.requestId + conditional takeNotice is the smallest platform story that covers “defaults too,” and it reuses the existing seam (onRequestEnded, deferredNoticePatch, noticeReadByWaitWrite / patchOne). I would not chase a third-party package here; the behavior is row metadata + request lifecycle, which is already the framework’s model.
What did add surface area:
- New metadata family (
noticeTaken:*) anddeliveredAsNotice/arrivesAsNoticetool shape. noteFiled+whenRequestEndsflush on resource-backed boards.- ~500 lines of new tests (appropriate for this class of bug).
Cleaner follow-ups (optional, not merge gates)
| Area | Suggestion | Confidence |
|---|---|---|
| Request-end hooks | Extract shared “register on request end, skip on suspended” helper (same shape as wait-on-task / task-request) |
High — duplication only |
noteFiled |
Track filed task ids per request (like lapsedByRequest) instead of listAll() on every request end |
Medium — perf/clarity on large boards |
takeNotice decline |
Consider routing outcome !== "recorded" through notNow() so defer/aging matches other “not admitted” paths |
Medium — behavior under contention |
deliveredAsNotice + lingering noticeTaken |
After ack, clearNotice clears owed marker but not take record; a later wait on the same terminal row may still see arrivesAsNotice. If that’s impossible by contract, a test would pin it; if repeat waits are allowed, consider clearing take on ack or requiring an owed marker in deliveredAsNotice |
Uncertain — needs product call |
| State-backed | No noteFiled flush — fine if documented; only matters for custom hosts with delivery + ownRequest |
Low |
| Zod | Derive arrivesAsNotice tool schema from arrivesAsNoticeAnswer |
Nit |
Performance note
noteFiled runs inside onRequestEnded (after drains, before terminal status): adoptUnknownRows + full-board scan + per-row refresh / deliverAfter. Correct to skip on suspended; still worth watching if boards grow beyond session scale. Not a reason to block this PR.
What’s strong
- Park vs end split in
whenRequestEndsis the right latency/correctness trade. - Conditional take vs wait drop is the right primitive.
- In-memory + SQLite + workforce integration tests give real evidence.
Verdict: Approach is justified for “once, on defaults too.” I’m leaving comment (not a formal approve) so the inline items below are visible; I’d be comfortable approving after the uncertain deliveredAsNotice / repeat-wait question is either tested or explicitly ruled out.
Sent by Cursor Automation: Review For Best Approach
| * and leaves it to be sent again. A wait answers so, not with the ending: the | ||
| * notice is the filer's one hearing of it. | ||
| */ | ||
| export function deliveredAsNotice(row: Task, requestId: string): boolean { |
There was a problem hiding this comment.
Possible repeat-wait edge (uncertain): deliveredAsNotice keys off noticeTaken:* via takerOf, while clearNotice only clears the owed marker. After a successful notice delivery, the take record can remain. If a new request in the filer session waits again on the same terminal row, this may still return true and surface arrivesAsNotice even though the ending was already heard.
If repeat waits on the same ending are out of contract, a short test + one-line invariant in docs would close this. If they’re allowed, consider clearing the take key on ack or requiring an active owed marker here.
There was a problem hiding this comment.
Real, still on main: once the notice turn clears the marker, a later request's getTask({ wait: true }) still gets arrivesAsNotice back, and no result comes with it. Filed as FIX-2181.
Generated by Claude Code
| by: own, | ||
| ...(taker !== undefined && taker !== own ? { replacing: taker } : {}) | ||
| }); | ||
| if (took.outcome !== "recorded") return { owed: false }; |
There was a problem hiding this comment.
Consistency nit: When takeNotice returns something other than recorded, admission returns { owed: false } without deferredNoticePatch. Other “not now” paths use notNow(). Under write contention, this might skip defer/aging behavior the pass expects. Worth aligning if you’ve seen flaky resend timing in tests.
| if (delivery === undefined || own === undefined || row.filer?.requestId !== own) return; | ||
| delivery.hooks.whenRequestEnds?.(async () => { | ||
| await adoptUnknownRows(mirror, options.collection); | ||
| for (const filed of listAll() as Task[]) { |
There was a problem hiding this comment.
Simplify later: This hook scans listAll() on every request end for rows with filer.requestId === own. For session-sized boards that’s fine, but it’s O(board) on the request-end critical path (after drains). A per-request Set<taskId> filled at file time (same idea as lapsedByRequest in wait-on-task) would shrink the hook and avoid re-scanning unrelated rows.
| whenRequestEnds | ||
| }; | ||
|
|
||
| function whenRequestEnds(send: () => Promise<void>): void { |
There was a problem hiding this comment.
Reuse: whenRequestEnds mirrors the onRequestEnded + skip-suspended pattern already in wait-on-task / task-request. Not wrong to duplicate once, but a tiny shared registrar would keep park-timing rationale in one place if more features register end hooks.
There was a problem hiding this comment.
Code Snob. A smaller shape exists, and it is comments only.
The park return, the take, and the hold while the filing request runs are each told again beside the line that does them. The test file header repeats the test names. Say each fact once. The entry header, the take-record section, and the test names already keep them.
POC (draft, does not merge): #3739 (poc/shorter-notice-once @ b74057d6c). Net −80 lines (+38/−118). Comment-stripped source matches 69831f2. notice-take and whenRequestEnds: 14 passed. eslint clean. Dropping the park return failed “runs nothing at a park” (send called on suspended).
Fold b74057d6c onto main. Do not reset onto the POC. This PR has landed (f740b61c). Close #3739 unmerged.
Left as recorded: the take beside the marker, a park holds no notice, arrivesAsNotice omits the task, the request id comes from the engine, optional takeNotice, the README, the docs page, both changesets. Tried and left: one helper for hasEnded and isRunning (the missing-host defaults are opposite).
Files: delivery.ts, task-settled-entry.ts, task-notice.ts, resource-backed.ts, wait-on-task.ts, internal.ts, task.ts, request-host.ts, task-tools-capability.ts, notice-claim.test.ts.
Sent by Cursor Automation: Code Snob


The problem
A session that files a task should hear the task's ending once. When the session waits on the task with
getTask({ id, wait: true })after it has already ended, it can hear the ending twice: once as the wait's answer, and once fromonTaskSettled, which wakes a second turn on the same ending. FIX-2112 closed this only for flows whoseonTaskSettledwaits behind the turn that filed the task, which is how Workforce sets things up. A flow on the defaults (taskSettledEntry({ block })) still heard it twice every time. In Workforce, a second reply that waited on a task while that task's notice turn was already running heard it twice as well.What this does
taskSettledEntry'sdeferholds one back. When the request ends, it sends whatever is still owed right away. A wait inside the filing request therefore always reads the ending before the notice runs, and drops it.onTaskSettledtakes the notice in one conditional write. A wait's drop and a take can't both go through. If the block throws, the notice stays owed, and the next copy takes it over once the failed request has ended.{ ok: true, taskId, arrivesAsNotice: true, message }. The message names the task and says its ending is arriving as a notice, so the model doesn't take it as "no result" and wait again.What's asked of you
Nothing here is yours to decide. One call shapes behaviour you can see: who backs off when a notice and a wait race. The epic's engineering manager made that call against the epic objective (every ending reaches its filer once, on the defaults). It is under Engineering calls below.
Parts worth reviewing closely
packages/orchestration/src/tasks/notice/task-settled-entry.ts: the admit order.defer, then "the filing request still runs", then the take. Taking over a take whose request has ended is how a failed block's notice gets resent.packages/orchestration/src/tasks/notice/task-notice.ts: the take is a record beside the marker (noticeTaken:<attempt>:<ending>), like the resend and deferral records. It stays after the marker clears, so a wait can still see that the request delivering the ending is running. Workforce's handling clears the marker before the turn it wakes, so this matters there.packages/orchestration/src/tasks/collection/resource-backed.ts→filerFor/noteFiled: the filing request is stamped only when the filer is this session. A follow-up filed elsewhere carries no request id, because another session's request is never answered as ended.packages/orchestration/src/tasks/helpers/wait-on-task.ts→deliverEndedBeforeWait: re-reads the committed row after a drop that a take beat.Links
Linear FIX-2123 (bug, epic FIX-2056). Found in review 5627158643 on #3697 (FIX-2112). Builds on FIX-2113's
deferredAt/resendNowPatch. Draft; a human merges.How to review this
Engineering calls
The notice steps aside while the turn that filed the task runs (decided by the epic EM)
The issue asked for a claim alone: admission marks the marker taken, so exactly one of the wait's drop and the admission goes through. Measured on
mainwith FIX-2112's test minusnoticeAfterTurn(3 of 3 runs), the notice is admitted 2–3 ms before the wait reads the row. The fast path sends it the moment the ending is written. So a claim alone lets the admission win, and the filer still hears the ending twice. The options were:The EM picked 2: it is the only option that keeps the epic's promise on the defaults, and it can be undone. Constraints carried out:
ctx.request.identity.id(BP-031).deferredNoticePatch(deferredAt) andresendNowPatch.onRequestEnded), not the backoff. It doesn't fire at a park, because a parked request hasn't ended. A request that parks and later ends gets its held notices from the pass's next resend (at most 5 minutes). The hook isn't registered again after a resume.Consequences worth knowing
deferredAt). Treating "parked" as ended would let a resumed turn's wait on B race B's notice again.requestHost.waits.endedis absent), nothing is held back and a take is always replaceable. That is the old behaviour. Waits can't be made on such a host anyway.takeNoticeandDeliveryHooks.whenRequestEndsare optional, so a hand-written ref or hooks object keeps compiling and behaves as before.Smaller calls
hold/deferset as Workforce does) on the in-memory and SQLite stores, and in Workforce itself (conversation-board-wait.test.ts).patch, for consumers of the published@flow-state-dev/orchestration: the new answer shape, the new optional ref method, and the notice timing.Everything else
Red, then green
Red is the new tests run against
main'spackages/orchestration/src, with only the tests and fixture from this PR applied:notice-claim.test.ts, defaults path, in-memory and SQLite:expected [ { boardId: 'waits', …(4) } ] to deeply equal [].onTaskSettled's block ran beside the wait.notice-claim.test.ts, notice already running, in-memory and SQLite:expected '{"ok":true,…"status":"completed","output":"already done"}' to contain 'arriving as a notice'.conversation-board-wait.test.ts(FIX-2123): the same assertion, through the realgetTask.notice-take.test.ts, state-backed and resource-backed:tasks.takeNotice is not a function. With the method present anddeliveredByWaitignoring the take (a mutation), "a take first leaves the wait's drop nothing to drop" fails on both backings.notice-defer.test.ts, failed block:expected undefined to deeply equal Any<String>(nothing took the notice).main. It guards against this change holding the notice too long. Its red was produced by disabling the request-end send:not within 1500mson both stores.Green: all of the above pass. FIX-2112's test with
noticeAfterTurn: truestays green.Checks
pnpm typecheck(includes the side-chain vocabulary sweep): pass.pnpm lint: pass.pnpm fallow:ci: pass.node scripts/check-retired-terms.mjs: pass.goals/workforce-coordination/runs-on-one-task/sweep.mjsfromfix/FIX-2087, run on this tree): PASS.goals/task-board/waits-on-a-task-it-filedlegs a and c (model-free): PASS. "A piece that ended before its wait was read by it; 0 onTaskSettled requests delivering it."j1was not run. This bug came from review, not the closure.Docs
packages/orchestration/README.md: the "waits behind the turn" condition is gone; the hold-until-the-filing-request-ends rule, the take and thearrivesAsNoticeanswer are added.apps/docs/docs/orchestration/task-board.md: written throughdocs-writerthendocs-editor(separate commit on this branch).Generated by Claude Code
Note
Medium Risk
Changes notice admission,
getTaskwait answers, and request-end delivery in durable orchestration; regressions would double-notify or drop endings, though coverage is broad.Overview
Fixes FIX-2123 so a session hears each task ending once, including default flows where
onTaskSettledno longer has to queue behind the filing turn.Notice timing: Filed tasks record the filing request id (server-side). While that request is
in_progress, its task notices are deferred (likedefer); when it ends, delivery hooks flush held notices immediately viawhenRequestEnds/onRequestEnded(not on park).RequestWaits.runningin core/engine powers that distinction.Single winner between wait and notice:
onTaskSettledtakes a notice in a conditionaltakeNoticewrite before the block runs; a concurrentgetTaskwait either drops the marker or sees a taken notice and returns{ ok: true, taskId, arrivesAsNotice: true, message }instead of the task body. Filing metadata can no longer smuggle notice/take markers.Docs, README, and integration tests (orchestration + Workforce) cover the new races and failure/retry paths.
Reviewed by Cursor Bugbot for commit 69831f2. Configure here.