Repository navigation
fix(workforce): a best-fit follow-up keeps its conversation's context (FIX-1828) - #2955
Conversation
… (FIX-1828)
Best fit chose a delegate from the post's words alone, and the delegate
that took a post saw only that post. A follow-up like "It sees it. It
fails right after the password." went to whichever delegate's
description mentioned passwords, and "Where can I buy it?" got "Buy
what?".
Each post now opens with its conversation's recent lines, read once
from the coordinator conversation's own items: the person's posts, the
coordinator's replies and the delegates' answers that landed, the last
10 and at most 4,000 characters, newest kept first. Best fit's
evaluation reads { recent, post }, and every delivery, by any policy,
carries the lines to the delegate. delegatedPostCapability shows them
to the delegate's model for that turn only; the built-in agent turn has
it, and an app's own delegate flow adds it to its generator's uses.
To tell a person's post from the coordinator's own notice in
items.all(), a SessionItem for a message now carries its role.
Adds a goal, coordinators/routes-a-follow-up-by-its-conversation, with
a no-recent control.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
…nd log its verdicts (FIX-1828) The container's FSDEV_DEFAULT_MODEL / FSDEV_INTENT_* overrides swapped the delegates' answer model under the app's resolver, so the run now strips them first, and installs a silent runtime logger so the attempts and the verdict are what it prints. The verdict log records the green runs and the no-recent control failing at followup:delegate alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
|
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: ef21a837-a823-4a53-b520-00afced1734d) |
…line names (FIX-1828) Docs-editor fold on the coordinator page and the workforce README: - A follow-up "can go back to" its delegate under best fit; the other policies don't route by the lines. - The README drops shapes no public API shows, keeping the one an evaluation model passed as routeModel is handed. - A filled-in context section, with who each line names. - The history window is counted in completed turns, as the other pages and the engine count it. - A message item's role: the framework writes user and assistant only. - The coordinator's "Nobody took this post" message carries no agentName. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
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: 0370b5a1-dbaf-499d-806b-bf786e8a4c89) |
… desk writes (FIX-1828) The example put a coordinator hand-off line in a best-fit desk's conversation, but a best-fit hand-off writes only a routing record, which is never a line. The example keeps the person's line and the delegate's, and a note says when a coordinator line does appear: a reply from its own turn, or "Nobody took this post". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
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: 8c6ddecc-d6d3-4f29-a518-35f7b9aa3cd3) |
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: 50a062aa-5a8b-425c-833b-21125e1eb4b2) |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Code Snob — already tight. No POC.
Head 3398e44a9803f86a69ab9903ea18df52b3a845c8. I read packages/workforce/src/coordinator/coordinator-lines.ts, delegated-post.ts, coordinator-flow.ts, packages/workforce/src/agent-worker-flow.ts, packages/core/src/types/scope.ts, packages/engine/src/context/history.ts, and packages/workforce/test/coordinator-followup-context.test.ts.
A rewrite would not shrink the contract:
recentLinesis the pure bound the unit tests call.readRecentLinesis the one session query. Folding them makes those tests stubitems.all(), which is more code.- A
usesentry can only add generator context through a preset. One preset, on by default, is the smallest capability. Puttingrecenton the turn input, the way the mailbox already does, would change the door's{ message }input this PR kept so a strict custom door still accepts a delivery. - Best fit copies
{ recent, post }onto the case because that is the evaluation state a scripted route reads. Reading it back off request state insidestate()saves a field and ties. SessionItem.roleis one optional field and one spread. The other ways to name the speaker are already recorded on this PR.
The new desk in the follow-up test is not a second coordinator-harness.ts. Those doors are handlers, so they never see a context section.
Sent by Cursor Automation: Code Snob
There was a problem hiding this comment.
Simplify review (FIX-1828)
Verdict: The core approach looks right for the problem. Recent lines have to exist in two places at once — best-fit’s evaluation and the delegate’s one turn — while delegates run in their own sessions, so read once when the post opens and carry a bounded snapshot on PostState → delivery → delegated post is simpler than re-reading the coordinator session at dispatch time or teaching delegates to pull from the filing session. SessionItem.role on core/engine is the minimal platform fix for attribution; splitting that into a follow-up PR would not shrink this change much.
Where the diff is heavier than it needs to be (follow-ups, not blockers):
- Duplicate transcript formatting —
delegatedPostLinesmirrorsrecentLinesContextinagent-worker-flow.ts(heading +- writer: textbullets). One small shared formatter (mailbox + coordinator headings as parameters) would cut drift risk. - Second mini harness —
coordinator-followup-context.test.tsreimplements much ofcoordinator-harness.ts(openDesk, scripted route, HTTP boot). Extending the existing harness forstate.recentand[follow-up]routing would shrink ~200 lines and keep coordinator tests on one pattern. recentoptional vs always-present —PostStatenormalizes torecent: [](BP-030), but delegated post / delivery state still uses “omit when empty” in several places. Picking always an array on the wire (or oneincludeRecent(recent)helper used everywhere) would remove repeatedundefined || length === 0branches.readRecentLines→items.all— Correct for “what the person sees,” but it scans the full history window before keeping 10 lines. Fine at default limits; if post-open latency ever matters, a newest-first walk (or a tail-biased items API) would be a localized optimization, not a redesign.
Alternative considered: Load recent lines inside delegatedPostEntry from filingSessionId instead of threading through schemas. That avoids four schema touchpoints but adds cross-session I/O, auth, and “lines before this post” timing on every delegate turn — more moving parts than copying ≤4k chars once.
Skipped (needs product call): Unifying RECENT_LINES (10) with mailbox’s 20; auto-injecting context without delegatedPostCapability (capability opt-in matches mailbox and custom flows).
No major concerns — approving with the nits above as optional tighten-ups before or after merge.
Sent by Cursor Automation: Review For Best Approach
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3398e44a98
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ude a just-landed answer, and never mistake a delegate for the coordinator (FIX-1828) Three review findings, each with a test that failed on the previous head: - The lines reached a delegate's model through a generator context slot, which renders into the system message, so an earlier post written like an instruction got system authority over the delegate's instructions. delegatedPostHistory replaces delegatedPostCapability: a generator history that puts the lines in as one user-role message just before the post, for that call only and never stored. - A request reads only finished requests' items, and an answer is in the conversation a moment before the request that landed it finishes. The claim that lands an answer now keeps it in session state (landedAnswers, server-owned, the last 10), and a reader adds each one whose request its items don't hold yet. - A delegate whose id starts with coordinator-judgment was read as the coordinator. Lines now match the judgment turn's exact generator names, which the agent turn returns. linesField is the one rule for a post's recent: present only when there are any. Docs, README and the changeset follow the delivery change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
PASS on attempt 1, and the no-recent control failing at followup:delegate alone, with the lines delivered as a user-role message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
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: 1dabc449-6378-4363-af06-3563ade807aa) |
# Conflicts: # packages/workforce/src/agent-worker-flow.ts
… for a closed round's pass-on (FIX-1840) Every delegate's answer, every routing and every pass-on writes the one coordinator conversation's state, and the flow ran on the engine's default CAS budget of 3 retries. Under contention a pass-on's delivery write could lose four times in a row; its request then failed after its round had already closed, and the round's answers never went back out. The coordinator flow's session now sets cas.maxRetries to 8. The new test makes the write that opens a pass-on delivery lose to another writer four times in a row: at the default budget the delegate never gets the other's answer; at 8 it does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
… serves reports blocked (FIX-1828) Each model the run calls must have a key that serves it here. Only the gateway serves the route model, so an OpenAI-only box reports blocked, naming the model and the keys that would serve it, as the other coordinator goals do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
|
About the red It isn't this PR's. Under CPU load,
What's done. The fix is FIX-1840 (#2983): the coordinator's session allows 8 retries. It is ported into this branch as
Generated by Claude Code |
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: 4300849d-6d8f-4e71-bfc9-32daf3495072) |
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: 2a90ea0e-2e89-407b-bd8a-56de569f3e8b) |


The problem
On a coordinator with
routing: best-fit, a follow-up lost the conversation it belonged to. Best fit picked the delegate from the post's own words, and the delegate that took it saw only that post.What this does
Every post now travels with its conversation's recent lines: the person's posts, the coordinator's own replies, and the delegates' answers that landed, oldest first, each under who wrote it.
{ recent, post }and asked to send a post that follows up on a delegate's answer to that delegate. The laptop follow-up now reaches the IT specialist.…; older ones are left out. That is roughly 1,000 extra tokens per evaluation and per delegate turn, at most.Judgment routing is unchanged: its turn already reads the conversation. Round robin and everyone route as before; their deliveries carry the lines because the delegate needs them.
What's asked of you
Nothing here is yours to decide: you already decided that follow-ups keep the conversation's context, and this implements that. One thing to know: under
routing: everyone, each delegate's turn now carries up to 4,000 characters of lines. That is the cost of the decision, and it is bounded.This unblocks FIX-1792 P1 (#2938), which restores its retired
followupandcontextlegs (a-routed-post-gets-one-answer) once this merges. Best fit's evaluation state is{ recent, post }, with each line as{ from, text }. That is the shape the mailbox's evaluation had, so those legs' scripted route reads it unchanged.Parts worth reviewing closely
SessionItemgainsrole(packages/core/src/types/scope.ts,packages/engine/src/context/history.ts). This is a small additive change in two framework packages. Without it,items.all()can't tell the person's post from the coordinator's own "Nobody took this post" message: neither carries anagentName, andhistory()has the role but drops who wrote each line, which is what best fit needs. The reasoning is in "Engineering calls".coordinator-lines.ts: which messages count as lines, who wrote each one, and the two bounds.delegatedPostHistory(delegated-post.ts): a new export. The entry notes the post's lines in request state.delegatedPostHistoryis a generatorhistorythat inserts them as one user-role message between the earlier turns and this request's own items, so just before the post. It is resolved per call and never stored. The built-in agent's generator uses it in place ofhistory: true, and on any other turn it is that history unchanged. A custom delegate flow sets it as its own generator'shistory. The door's{ message }input is unchanged, so no existing door breaks.landedAnswers(session state, server-owned): the claim that lands an answer keeps it (the last 10, each cut to 4,000 characters) in the same atomic write that releases the hold. A reader adds each kept answer whose request isn't among its loaded items yet. This closes the window between an answer appearing and its request finishing.postOf's dual-read: a request whose post state was written before this change, and resumed since, reads as having no lines (BP-030). It is not under test, because building a cross-version resume needs a durable host. Cleanup: remove it once no such request can resume.Spec: none (bug route)·Linear: FIX-1828·Epic: FIX-1786· Merges independently; #2938 follows it.How to review this
Engineering calls
postStateOfreads the lines into the post's request state. Best fit's case and everydeliveryOf, under every policy including the judgment turn'shandOff, take them from there. No second read can disagree with the first.role: useris the person (the session's user id). An assistant message under a delegate'sagentNameis that delegate. An assistant message undercoordinator-judgment*, or with noagentName(the "Nobody took this post" message), is the coordinator's worker id. Only messages visible in the conversation and its history count, so the skill classifier's hidden output never becomes a line.roleonSessionItem. The fix belongs where the information is lost.outputItemToSessionItemdropped the message's role, soall()/selectForContext(), documented for building custom prompt context, could not say who spoke. The change is additive and optional, and appears only on message items. I considered three alternatives and rejected each. Giving the coordinator's notice anagentNamechanges what clients render under every policy. Inferring the person's post from item order relies on engine internals. Zippinghistory()withall()is fragile under concurrent requests.RECENT_LINES,RECENT_CHARS), as the brief asked and as the mailbox's 20 was. Cutting the crossing line, rather than dropping it, keeps the newest answer, which is the one a follow-up most often continues. If a caller needs different bounds, they could become defaulted options ondefineCoordinatorFlow; that wasn't added here.contextleg, which checks that the delegate's stored conversation holds no other post's line. They never go into a context slot either: those render into the system message, which would give an earlier post system authority. A generatorhistoryentry is the framework's per-call, never-stored message, so the lines go there, with theuserrole, just before the post. Note for FIX-1792 P1: coordinators without boards (kitchen-sink's help desk, the pentest lab, the desk fixtures) #2938: its scripted answer should look for the item in that user-role message, not in the system text. This also leaves the door's input contract alone, so a custom door with a strict input schema still works.agentNameis one of the judgment turn's generator names, whichagentWorkerTurnnow returns (answerNames), or absent. A delegate namedcoordinator-judgment-…keeps its own id.roleand from the coordinator's ownagentName, which it stamps from the delivery record. The lines reach a delegate only on the internalonDelegatedPostentry. A caller can't hand lines in throughrun: its input is{ message }, and the agent's action schema strips anything else.@flow-state-dev/workforce(the behaviour anddelegatedPostHistory), and a patch for@flow-state-dev/core+@flow-state-dev/engine(SessionItem.role).rolelists only the two roles the framework writes. The docs site builds with no broken links or anchors.coordinators.mdsaid every reply the coordinator writes itself carries anagentNamestarting withcoordinator-judgment. Its "Nobody took this post" message carries none, and the page now says so.Everything else: verification and file-by-file
Red, then green (scripted models,
packages/workforce/test/coordinator-followup-context.test.ts)On
mainatddaec6167, the three conversation tests fail. The unit tests for the new module were left out of that run, since the module doesn't exist there.accounts(wantdevices, which answered the opener);Buy what?(wantBuy the item-… at the shop.);recent(want[]).On this branch all 12 pass. They cover: the follow-up goes to
devicesby evaluation, which was handed[{from: alice, …}, {from: devices, …}], anddevices' turn was shown both lines; under round robin,accounts(never sent the item post) answers from the lines, and its own stored conversation keeps no message carrying them; an app's own delegate flow withdelegatedPostHistorysees them; the first post has no lines and no section; who wrote each line; the 10-line cap; the 4,000-character cap with the crossing line cut.Three tests from the review round each failed on
3398e44a9and pass on3f9fd8ace:3398e44a9the system text contained it. Now it is only in the one user-role lines message.3398e44a9the follow-up went toaccounts. Now it goes todevices, with the answer among the evaluation's lines. Mutating the reader to ignore kept answers turns it red again.coordinator-judgment-specialist. On3398e44a9its answer was labelleddeskand the follow-up went toaccounts. Now it keeps its id and gets the follow-up back.Mutations, each reverted:
roledropped inoutputItemToSessionItem: both conversation tests fail.Buy what?) while routing still passes.Buy what?.Real models:
goals/coordinators/routes-a-follow-up-by-its-conversation. This is a new goal with two held-out threads, each a follow-up whose words alone point at another specialist.by: evaluated, one answer each.GOAL_CONTROL=no-recent(the evaluation handed{ post }alone) fails atfollowup:delegateon both threads and nothing else. "It sees it. It fails right after the password." went to accounts.Suites
pnpm --filter @flow-state-dev/workforce test: 99 files, 1348 tests pass, on the head merged withmain.@flow-state-dev/enginevitest: 271 files, 3635 pass (6 skipped), including two newoutputItemToSessionItemcases.pnpm exec turbo run typecheck --concurrency=2: 74/74. The root guards (package boundaries, updater purity, side-chain vocabulary, goals control shape) pass.tsc -p goals --noEmit: clean.node scripts/validate-changeset-refs.mjs: every new changeset names its issue.Files
packages/workforce/src/coordinator/coordinator-lines.ts(new): the line shape,readRecentLines,recentLines, the bounds.coordinator-flow.ts: lines read inpostStateOf, carried in the post state, best fit's case, the evaluation's state and question, and every delivery; thepostOfdual-read.delegated-post.ts:recenton the post, noted in request state;delegatedPostHistory.coordinator-keys.ts,coordinator-delegates.ts:landedAnswers, server-owned.agent-worker-flow.ts: the agent turn's generatorhistoryisdelegatedPostHistory, and the turn returns itsanswerNames.coordinator/index.ts: exportsdelegatedPostHistory.packages/core/src/types/scope.ts,packages/engine/src/context/history.ts(+ spec):SessionItem.role.apps/docs/docs/workforce/coordinators.md(follow-ups and recent lines; custom flows),apps/docs/docs/streaming/items.md,docs/architecture/generator-identity.md,packages/workforce/README.md.goals/coordinators/routes-a-follow-up-by-its-conversation/(new); two.changesetfragments.🤖 Generated with Claude Code
https://claude.ai/code/session_01XMg2dz8sMEdyzCQTRsaMTV
Generated by Claude Code
Note
Medium Risk
Changes coordinator routing, delegate prompt assembly, and public SessionItem shape; behavior is bounded but affects every delegated post and best-fit evaluation.
Overview
Fixes FIX-1828: best-fit coordinators no longer route follow-ups from the post text alone, and delegates no longer answer with only that post.
Conversation recent lines are read once when a post opens (last 10 messages, up to 4,000 characters, this conversation only). Best fit’s evaluator now gets
{ recent, post }and is prompted to send follow-ups back to the delegate that last answered. Every delivery carries the same lines, regardless of routing policy.Delegates see those lines for one turn as a single user-role message inserted via new generator
historyhelperdelegatedPostHistory(built-inagentuses it instead ofhistory: true). Lines are not stored in the delegate session and are not injected as system text.SessionItemnow includes optionalroleon message items fromall(),client(), andselectForContext(), so line assembly can distinguish the caller from coordinator vs delegate replies (outputItemToSessionItemin engine).landedAnswerssession state records answers at claim time so a follow-up routed while the landing request is still in flight still includes that answer inrecent.Docs, changesets, integration tests (
coordinator-followup-context.test.ts), and a real-model goal exercise the behavior; ano-recentcontrol confirms routing fails without lines while delegates still get context on delivery.Reviewed by Cursor Bugbot for commit 21b737a. Configure here.
Generated by Claude Code