Skip to content

fix(goals): split-to-roster counts a turn parked on its piece's wait gate as ended (FIX-2124) - #3714

Merged
jhoffner merged 2 commits into
mainfrom
fix/FIX-2124
Oct 23, 2026
Merged

jhoffner merged 2 commits into
mainfrom
fix/FIX-2124

Conversation

@jhoffner

@jhoffner jhoffner commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

The problem

The split-to-roster goal's leg 1:waiting-while-b-works fails on main. The product is behaving correctly; the check is out of date. The leg promises that worker A doesn't hold its session while delegate B works on A's piece. It counted A's turn as over only once A's request had finished. Since FIX-2082 the agent waits for its piece with getTask, which parks the request on the piece's wait gate. A parked request runs nothing and holds no lease, but it never finishes before B ends, so the goal reported that B ended first. A red goal for correct behaviour hides real regressions and blocks the FIX-2087 closure.

What this does

A's turn now counts as ended in either of two cases. Its request finished (the task then waits on filed), or its request is parked on the wait gate of B's piece (the request is suspended, the piece's wait slot names it, and the task waits on wait). After A's turn ends, the read waits until nothing is running in A's session, and B must still be working at that point. It then checks that A's task is running, has no lease, and is waiting on the right thing. If A's request is still running when B ends, or anything is still running in A's session, the leg fails as before.

A new control, hold-session, demonstrates the red state. It makes A's getTask hold its request open past B's hold, and leg 1 then fails 1:waiting-while-b-works alone.

What's asked of you

Nothing here is yours to decide. The EM already ruled that a request parked on a wait gate counts as A's turn having ended. The PR is the gate.

Parts worth reviewing closely

  • goals/workforce/split-to-roster/run.mts, leg 1's read loop. It tells a finished turn from a parked one. A parked turn has to be parked on B's piece: the piece's live (not lapsed) wait slot must name A's request id. A parked turn also has to read waitingOn: "wait", and a finished turn filed.
  • The quiet-session wait. A first cut read the session right at the park and found the board's own dispatch pass running in A's session (about 140 ms, an internal pass and not A's turn). The read now keeps polling until the session is quiet, and that has to happen before B ends.

Linear: FIX-2124 · epic FIX-2056 · found by the closure FIX-2087 (#3692). Goals-only, no changeset (BP-022: private package). Draft, not for merge by the agent.

How to review this

How to review this. This is a bug fix on the direct route: there is no spec and no spec PR, because the hard part was the diagnosis and it happened in code. This PR is the only gate, so unlike a spec-backed change, the approach is in scope. Nothing here was signed off upstream.

Most valuable here: the diagnosis chain. Does the repro actually reproduce the reported failure, is the named cause the real one, does the fix address that cause rather than the symptom, and does the regression test fail without the fix? Then the second path (the legacy shape, the null boundary, the concurrent case, the cancel path).

In scope to challenge: where the guard was placed, any behaviour change a user could notice, and whether this should have been a spec'd feature instead of a fix.

Engineering calls
  • The parked turn has to be parked on B's piece. Being suspended isn't enough: the piece's wait slot has to name A's request, and the slot can't be lapsed. A park on anything else (an approval, a webhook) doesn't count.
  • Wait for a quiet session instead of excluding the dispatch action by name. This keeps "no request running in A's session" as written and doesn't hard-code which internal actions are harmless. It only needs one moment of quiet while B works. That is the same strength as the old read (A could also finish its turn early on the old path).
  • New control hold-session rather than a one-off local patch, so the red state of this assertion can be re-checked. It only fires on runs where A waits with getTask, which was every run here; a model that ends its turn never reaches the patch.
Everything else

Red, then green

  • Red, main 34cebe6, GOAL_LEGS=1: 1:waiting-while-b-works — … crew.keeper's piece ended before A's turn did. The log shows A's work request action execution suspended while B held its answer.
  • Green, this branch, GOAL_LEGS=1: PASS. During B: {"ended":"parked","status":"in_progress","waitingOn":"wait","running":0}.
  • Full goal, all four legs, with FIX-2097 (fix(store-sqlite): drop a write that arrives after the database closed (FIX-2097) #3707, still open) merged locally for verification only. This PR is from main and doesn't contain FIX-2097. Runs 2 and 3: PASS. Run 1 failed 2:reads-the-failure only, because the model messaged crew.broken (messageWorker) instead of filing a piece. That is model behaviour in a leg this change doesn't touch.
  • Control hold-session: FAIL 1:waiting-while-b-works alone, as intended.

Controls that no longer fail as intended (both already broken on main, not fixed here)

  • first-answer: 1:report-is-output held. When A parks on a getTask wait, its resumed request gives the answer, which the task's own entry records. The patched woken-turn line in task-settled.ts never runs, so the control only goes red on runs where A ends its turn instead of waiting. This dates from FIX-2082, not this change.
  • wake-coordinator: 4:desk-hears-tasks-only held. A's piece errored at the desk's hand-over, the desk acted on no notice at all, and A's task stayed in_progress. Main's version of run.mts gives the same result, so this change didn't cause it.

Both are recorded in goal.md's verdict log as open. They should go in a follow-up issue.

Checks

pnpm typecheck (includes control-shape guard), pnpm lint, pnpm fallow:ci, node scripts/check-retired-terms.mjs, the vocabulary sweep and its --control: all pass. No package code changed, so there are no package tests to run. The task-surface sweep isn't needed because no task tools, endings or docs were touched.

Files

  • goals/workforce/split-to-roster/run.mts: leg 1's ended-turn read, the hold-session control.
  • goals/workforce/split-to-roster/goal.md: leg 1's signal, the controls, verdict log.

Generated by Claude Code


Note

Low Risk
Goals-only changes to assertions and documentation; no production workforce/orchestration code ships in this PR.

Overview
Updates the split-to-roster goal so leg 1:waiting-while-b-works matches current agent behavior: after filing a piece, A may getTask-park on the delegate piece’s wait gate instead of finalizing its request.

run.mts now treats A’s turn as ended when the request is finalized (waitingOn: "filed") or suspended on B’s piece with a live wait slot (waitingOn: "wait"). It then polls until A’s task session has no in-progress requests (so brief board dispatch after a park doesn’t false-fail) while B’s piece is still running, and asserts no lease and zero running requests.

goal.md documents the two end-of-turn paths (FIX-2124), adds the hold-session scratch control (delays markWait so the leg should fail alone), and extends the verdict log with 2026-10-23 runs—including known gaps where first-answer and wake-coordinator no longer isolate on getTask park paths.

Reviewed by Cursor Bugbot for commit e302941. Configure here.

…gate as ended (FIX-2124)

Leg 1's waiting-while-b-works read A's turn as ended only once its request
finalized. Since FIX-2082 the agent waits on its piece with getTask, which
parks the request on the piece's wait gate: it runs nothing and holds no
lease, but never finalizes before B ends, so the leg read B ending first.

A turn now ends when its request finalized (task waitingOn filed) or parked
on the wait gate of B's piece (request suspended, the piece's wait slot
naming it; task waitingOn wait). The read then waits for nothing to run in
A's task session while B still works, since the board's own short pass can
follow a park. A request still in progress until B ends still fails it, which
the new hold-session control shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
…s controls (FIX-2124)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VaN4uTiYqiabCbsFLWM52A
@linear-code

linear-code Bot commented Oct 23, 2026

Copy link
Copy Markdown

FIX-2124

@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated
flow-state-dev-docs Ignored Ignored Oct 23, 2026 12:01pm UTC
flow-state-dev-kitchen-sink Ignored Ignored Oct 23, 2026 12:01pm UTC
flow-state-dev-ui Ignored Ignored Oct 23, 2026 12:01pm UTC

Request Review

@cursor

cursor Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Bugbot couldn't run - usage limit reached

Bugbot 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: c40e1d0d-2e78-4133-af55-01e920a9ae11)

@jhoffner jhoffner left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stand-in review (correctness and restraint). Nothing blocking.

  • The promise is kept, and the check is no weaker. A parked turn counts only when the piece's wait slot names A's request and isn't lapsed. Any other suspended request doesn't count. Two cases still fail: a request still in_progress, and anything still running in A's session when B ends. The expected waitingOn follows how the turn ended (filed or wait).
  • The new hold-session control fails exactly 1:waiting-while-b-works, so the red state can be re-checked.
  • 🟣 Two controls stale on main. first-answer no longer reddens 1:report-is-output, and wake-coordinator no longer reddens 4:desk-hears-tasks-only. Both predate this PR (FIX-2082), and goal.md records them. They're filed as a follow-up on the epic, not here.

Generated by Claude Code

@jhoffner
jhoffner marked this pull request as ready for review October 23, 2026 12:08
@jhoffner
jhoffner merged commit e4bc6c7 into main Oct 23, 2026
21 of 23 checks passed
@jhoffner
jhoffner deleted the fix/FIX-2124 branch October 23, 2026 12:08

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify review (FIX-2124)

Scope: Two files only (goal.md, run.mts) — appropriately narrow for “leg 1 must treat a getTask park as turn-ended.” No production/runtime changes.

Did the approach go too far?

No on the core fix. After FIX-2082, the default model parks on the piece wait gate (suspended, waitingOn: wait) instead of finalizing the work request. Grading only finalizedAtMs was the bug; extending the read to “finalized or parked on this piece’s slot” matches conversation-board-wait / wait-slot contracts. The extra “session quiet” loop after turn-end is not gold-plating — the verdict log’s ~140 ms board dispatch pass after park is a real race if you snapshot too early.

Alternatives considered (and why this PR is reasonable):

Alternative Why not (for this issue)
Finalize the request when parking on getTask Product semantics change; goals should observe store truth
Treat any suspended / waitingOn: wait as ended Too loose — wrong request or lapsed slot
Move logic into @flow-state-dev/workforce or vitest split-harness Wrong layer: this goal needs real hireWorkforce + HTTP + model; harness is for scripted splits

Where complexity crept in (optional follow-ups, not blockers):

  1. Comment weight — Leg 1’s block comment (~lines 315–325) largely duplicates goal.md leg 1. One line pointing at the spec would shrink the diff without losing intent.
  2. Poll loop I/O — Per 25 ms tick you sometimes call store.rows() three times and store.requests(own) twice with items. For a goal script this is fine; if leg 1 ever feels slow, reuse one rows snapshot per iteration and poll requests with withItems: false until the post-quiet() assertion that needs tool output.
  3. Local structure — A tiny turnEnded(turn, piece, runId) → 'finished' \| 'parked' \| undefined (same predicates as today) would shorten the loop; busy vs during.busy is a loose state machine but readable enough.
  4. hold-session patch — KEEPER_HOLD_MS + 2_000 inlined in the patch string is brittle; a named constant beside KEEPER_HOLD_MS would document the “2 s past B’s hold” contract.

Controls

  • hold-session — Good negative control for the new invariant; keep it.
  • first-answer — Honestly documented as not isolating when A answers via resumed parked wait (patch never hits noteTaskAnswer). I’d treat that as a follow-up test-design item (retire, narrow, or add a path-specific control), not a reason to block this fix.
  • wake-coordinator — Verdict log shows failure on main too (desk hand-over); pre-existing, out of scope here.

Reuse / packages

No new cross-package imports; no third-party helper buys much here. If a second workforce goal needs the same “turn ended (finalize or park) + session quiet” poll, then extract to goals/lib — not worth it for one consumer.

Performance

Goal-only polling; no production hot-path concern.


Verdict: Approve. The right layer (goal grading), the right semantics (parked turn counts as ended + session quiescence), and the hold-session control backs the new read. Optional nits above are polish, not a simpler approach.

Open in Web View Automation 

Sent by Cursor Automation: Review For Best Approach

@@ -300,11 +314,28 @@ await runGoal(async (failures) => {
const taskId = await fileForA(ask("release", B));
// While B works: A's task running, waiting on its piece, and nothing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify nit: this block largely restates goal.md leg 1 (finished vs parked, session quiet). Consider one line here (“see goal.md leg 1”) and keep the normative wording in the spec only — easier to maintain when the read evolves again.

const turn = own === undefined || runId === undefined ? undefined : (await store.requests(own)).find((r) => r.id === runId);
if (turn?.finalizedAtMs == null) {
const slot = (piece as { wait?: { requestId?: string; lapsed?: true } }).wait;
const ended =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parked/finished predicates match the right contracts (suspended + wait slot ownership). If this loop grows again, a local turnEnded(turn, piece, runId) helper (same three checks) would be my first readability win — not a different approach.

}
continue;
}
const inSession = (await store.requests(own!)).filter((r) => r.status === "in_progress");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional perf/readability: this iteration can call store.rows() up to three times and store.requests(own) twice. Reusing the rows from line 340 and a single requests list (items only when you need tool_output after quiet()) would be a mechanical shrink — fine to defer for a goal script.

// works, and reads B's ending without parking.
module: "packages/orchestration/src/tasks/helpers/wait-on-task.ts",
from: String.raw`\n const marked = await collection\.markWait!\(taskId, \{`,
to: `\n await new Promise((resolve) => setTimeout(resolve, ${KEEPER_HOLD_MS + 2_000}));\n const marked = await collection.markWait!(taskId, {`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KEEPER_HOLD_MS + 2_000 in the patch template couples the control to leg timing by magic. A named constant (e.g. HOLD_SESSION_EXTRA_MS) next to KEEPER_HOLD_MS would make the “2 s past B’s hold” contract obvious when someone changes the taker hold.

**Controls:** each is a scratch patch to Workforce applied as the process loads it (`goals/lib/module-patch.mts`), printed by the run and refused when it never reached the code.

- `GOAL_CONTROL=first-answer`: the woken turn's answer is never noted (`conversation-board/task-settled.ts`, the woken turn's `noteTaskAnswer`), so the task completes with A's first answer. Leg 1 must fail **`1:report-is-output`**, alone.
- `GOAL_CONTROL=first-answer`: the woken turn's answer is never noted (`conversation-board/task-settled.ts`, the woken turn's `noteTaskAnswer`), so the task completes with A's first answer. Leg 1 must fail **`1:report-is-output`**, alone. Red only on a run where A ends its turn: a turn parked on a `getTask` wait resumes in its own request, whose answer the task's own entry notes, so this patch never touches it (seen 2026-10-23; open).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good honesty that this control doesn’t isolate 1:report-is-output on the parked-wait path. I’m not blocking on it, but a follow-up issue to retire/replace first-answer (or grade only runs that end via finalize + woken turn) would restore a discriminating negative control — otherwise leg 1’s output check is mostly plain-run only for that scenario.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Snob. Outcome 1. The check is already the contract. The extra lines are comments that restate it. Fold 48c89645c onto main. Do not reset onto the POC. Close #3719 unmerged. This head has already landed, so fold onto main.

POC: #3719 (poc/shorter-parked-turn @ 48c89645c). Net −9 (5/14) in goals/workforce/split-to-roster/run.mts. Comment-stripped source is identical to e3029419, so the ended check, the quiet wait, both failure sentences, and the hold-session patch are unchanged.

What to drop:

  • Leg 1's comment restated goal.md (two endings, filed / wait, the end-of-request check, an in_progress request holds the session). Five lines stay: read once the turn has ended (request finalized, or parked on this piece's live wait slot) and the session is quiet. The board's own short pass may follow a park.
  • The busy note restated the failure sentence.
  • The hold-session note restated the control line in goal.md. One line stays: delay markWait past B's hold, so the request stays open while B works.

Left as recorded: the slot must name A's request and not be lapsed, a quiet session rather than skipping dispatch by name, waitingOn follows how the turn ended, hold-session, the two failure sentences, goal.md's signal and verdict log, the open first-answer and wake-coordinator gaps.

Tried and left: one rows() snapshot needs a binding and is longer. Keeping busy on during changes what a timeout prints. Dropping running: 0 drops the grade. A helper around the ended check is longer.

Passed: comment-stripped identity with e3029419. TypeScript parse diagnostics 0. eslint exit 0. Live goal not re-run; no assertion text changed. Red: deleting && slot?.lapsed !== true drops the conjunct the short comment names.

View PR

Open in Web View Automation 

Sent by Cursor Automation: Code Snob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants