Skip to content

fix(FIX-2161): keep a legacy task's project, refuse a session of another worker - #3829

Merged
jhoffner merged 3 commits into
mainfrom
claude/project-thread-fppi6t
Oct 24, 2026
Merged

jhoffner merged 3 commits into
mainfrom
claude/project-thread-fppi6t

Conversation

@jhoffner

Copy link
Copy Markdown
Collaborator

Requested by Jake · project thread

The problem

Two gaps in FIX-2161 (#3821, merged) were found after it landed.

  1. A task filed before tasks recorded their project loses it. Codex found this on feat(FIX-2157): Claude Code-style lab, threads mode front end, on fixtures #3818 (finding). When such a task gets a follow-up after the conversation's project changes, the follow-up takes the new project. The follow-up reuses the old task's session, and the run is worse than "wrong project": it errors (key-occupied … readonly state field "filingProjectId"). A legacy task still waiting on the board would also be handed the new project.
  2. setWorkProject(worker, project, { sessionId }) accepted a session of another worker. The head of engineering raised this on agent-mailbox Add governance and publishing configuration #46, and the architect agreed it is the spec's meaning. worker only picked the flow, so naming lead with a main session set main's project.

What this does

  • A row with no stamp (filedInProject absent) now resolves to the project it was filed in. That is the conversation's project as it stood then, read without workProjectId (the field didn't exist before the stamp), and failing that, the project the row's input names. A follow-up of such a row stamps and normalizes to that project. Hand-over of a waiting legacy row uses the same pre-workProjectId read (BP-030).
  • The client sends worker with the action. The action refuses with Refused: this session runs "<x>", not "<worker>" before anything is stored. worker is optional in the input, so an older caller keeps working.

What's asked of you

Nothing. This is a bug fix to the approved FIX-2161 spec.

Parts worth reviewing closely

Fixes FIX-2161 (follow-up) · Goal check: packages/workforce/test/work-project.test.ts, 13/13 PASS.

Verification

New legs and their controls:

Leg Control Result
legacy follow-up: an unstamped root naming Apollo, conversation moved to Beta, follow-up must run in Apollo board.ts as on main FAILS: the follow-up errors (key-occupied on filingProjectId), so no run happens. The other 11 pass
other worker: setWorkProject("lead", …, { sessionId: <main's> }) must reject, and main must still have no project server check removed FAILS (the call resolves). The other 12 pass
same client stops sending worker FAILS. The other 12 pass

Suites. The conversation-board, follow-up, split, steer, project-coordinator, workstream, Error Reporter and work-project suites pass: 17 files, 243 tests (FSDEV_DEFAULT_MODEL= empty, because this container sets it in an old format). tsc --noEmit on the package reports no errors. ESLint is clean. The Process guards scripts (retired terms, changeset refs, spec folder, publish set, NUL bytes, model strings, reserved names, isolation) all pass.

Docs. The README and apps/docs/docs/workforce/projects.md gain the refusal and the "run that worker" rule. Changeset: workforce patch.


Generated by Claude Code

…her worker

A row filed before rows carried the project stamp now falls back to the
project its conversation had then, which can't have come from
workProjectId, else the project its input names. A follow-up of such a
task stays in that project after the conversation changes project,
instead of erroring on the root's task session (key-occupied on
filingProjectId); a waiting one is handed it.

setWorkProject now sends its worker, and the action refuses a session
running another worker, storing nothing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qsh48df8qzrorsfaCXn1X7
@linear-code

linear-code Bot commented Oct 24, 2026

Copy link
Copy Markdown

FIX-2161

@vercel

vercel Bot commented Oct 24, 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 24, 2026 2:49am UTC
flow-state-dev-kitchen-sink Ignored Ignored Oct 24, 2026 2:49am UTC
flow-state-dev-ui Ignored Ignored Preview Oct 24, 2026 2:49am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T02:51:21.135917Z 7b52ca5 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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.

Second look + architecture pass on #3829.

Approach: sound and proportionate. Resolving a legacy row's project at read time (BP-030) is the right shape; no migration or rewrite of stored rows is needed. The refusal belongs in the action, not the client.

Worth doing in this PR (the refactor opportunity is right here):

  1. Collapse the two legacy-project readers (legacyProjectOf and handedProjectOf). They disagree on the input-named fallback, and the workProjectId strip is duplicated. See inline.
  2. Add a test for the hand-over (waiting legacy row) half. Reverting handedProjectOf currently fails nothing. See inline.

Optional: state the limit of the optional worker guard (an intent check, not an enforcement boundary), and rewrap the README paragraph. See inline.

No broader refactor is warranted. Nothing else in the diff is an opportunity beyond the helper unification above.


Generated by Claude Code

Comment thread packages/workforce/README.md Resolved

@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-2161)

Verdict: The behavioral fixes look right and the test matrix matches the spec (legacy follow-up, waiting, other worker). I’m approving; the notes below are about a smaller surface area for the worker guard and one place for the “ignore workProjectId” legacy rule—not blockers.

What’s working

  • Stripping workProjectId before resolving an unstamped row is the minimal BP-030 fix for “conversation as it stood at filing,” without a migration.
  • The legacy follow-up test (unstamp + setWorkProject + follow-up) is the right regression for pre-stamp rows.
  • Worker mismatch refusal closes the real footgun (lead / main sharing a coordinator flow + sessionId).

Where complexity crept in

1. Worker binding via optional action input

setWorkProjectInputSchema grows an optional worker, and the block only refuses when input.worker !== undefined. The workforce client always passes worker, so the client API is fixed, but the declared action still accepts { project } alone—same cross-session mistake remains for anything that invokes the action directly without worker (tools, custom hosts, Error Reporter act, etc.).

Cleaner alternative (I’d lean this way): keep the action input as { project } only and enforce binding in createWorkforceClient.setWorkProject: after resolving sessionId, read the session’s WORKER_ID_STATE_KEY (trusted server state) and refuse if it !== the worker argument before runIn. No public schema change, no optional field, no README line about worker? on the action.

If you prefer defense-in-depth in the block, make worker required in the schema (and update every action entry point), not optional—optional reads as “sometimes we check.”

2. Two legacy paths that almost share logic

legacyProjectOf (strip → filingProjectAddressOf → input.project) and unstamped handedProjectOf (strip → filingProjectOf only) duplicate the omit pattern and differ on address vs string ref and on whether row input counts.

Cleaner alternative: one helper in filing-session.ts, e.g. conversationProjectBeforeWorkProject(state, row?), used by both filedProjectFor and handedProjectOf. For hand-over, I’d consider legacyProjectOf + projectRef so unstamped waiting rows filed with only input.project behave like follow-ups (I’m not sure production has that shape—worth a one-line invariant or a test if you keep the split).

3. Nits

  • unstamp could use FILED_PROJECT from board-entries like conversation-board-filing.test.ts.
  • Doc on the schema says the session “must” run the worker while the field is optional—small mismatch.

Skipped (larger than this PR)

  • Backfilling filedInProject on read to drop the permanent !isStamped branch.
  • Deduplicating ledger reads in handedProjectOf / sessionSettingOf (perf reviewer: fine to ship).

Performance

No concerns for hot paths; duplicate ledger fetch on hand-over is optional future dedupe.

Nice tight changeset overall—main follow-up I’d consider for a follow-up PR is client-side worker binding instead of optional action worker.

Open in Web View Automation 

Sent by Cursor Automation: Review For Best Approach

@jhoffner

Copy link
Copy Markdown
Collaborator Author

Engineering review: FIX-2161 follow-up (worker mismatch + legacy-row project) at 42067d7

Verdict: good to merge once the remaining CI jobs finish. No blockers.

What I checked:

  • (a) The worker check is on the server. The refusal is in the action (work-project.ts:86-90), next to the no-worker check and before the LINKED checks and any write. The client only passes worker along (client.ts:356). An old client that doesn't send worker is accepted and skips the check, but that is safe. The check only stops a session from being set under the wrong worker's name. Membership, ownership and the LINKED refusals still run, and the project is set on the worker the session actually runs, which is what happened before this PR.
  • Nothing is stored on refusal. The refusal throws before patchState. The test checks that a later filing on main still gets no-project.
  • Each fix has a test that fails without it. I re-ran each control locally:
    • board.ts as it is on main: only legacy follow-up fails.
    • Server check removed: only other worker fails.
    • Client not sending worker: only other worker fails.
    • Only the handedProjectOf hunk reverted: legacy follow-up fails, so the hand-over change is covered too.
  • (b) is a tolerant read, not a migration. Nothing rewrites stored rows. An unstamped root resolves through legacyProjectOf: the conversation's own project fields without workProjectId, then the project named in the row's input. The follow-up's new row is stamped with that project. I found no scope widening:
  • Local runs: work-project 13/13. Full workforce suite: 131 files / 1592 tests passing. The retired-terms check passes.

Notes (none blocking):

  1. work-project.ts:88: because worker is optional, a caller that leaves it out never hits the mismatch check. Making it required at the next breaking release would remove the gap.
  2. board.ts:399-405: the legacy test only covers the branch that reads the project from the row's input. The branch that uses the conversation's project as it stood at filing (a conversation with projectId / filingProjectId) has no test. A small extra test would cover it.

CI at 42067d7:

  • Passed: Process guards (retired terms), Test 1–3/3, Typecheck, Fallow, changesets, Analyze (python), Vercel, Best Approach.
  • Pending: Analyze (JS/TS), Kitchen-sink E2E, Packed release, Docs build, Storybook, Code Snob.

— FSD Head of Engineering

@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 — already tight. No POC.

I read packages/workforce/src/conversation-board/board.ts (filedProjectFor, legacyProjectOf, handedProjectOf), filing-session.ts (filingProjectOf, filingProjectAddressOf), held-task.ts (isStamped, filedProjectOf, filingProjectStampOf), projects/work-project.ts, workers/client.ts, projects/run-project.ts (namedProjectOf), and test/work-project.test.ts.

The two workProjectId omits stay one line each. Filing needs an address (filingProjectAddressOf, workstream first, then the project the row names). Hand-over needs the string filingProjectOf already writes on the session, and stops there: a waiting row with no conversation project is handed nothing, and the run still reads input.project. A helper around the omit is longer than those two lines. Sending hand-over through legacyProjectOf would write that named project onto filingProjectId.

legacyProjectOf stays a function. Inlining it into the early return in filedProjectFor drops the name and not a step. That return is what keeps an unstamped root off the session's current project. namedProjectOf is the run's three-way read (none, named, malformed). This path only wants an address or nothing.

The worker refusal stays the three lines beside the no-worker check. lead and main share a flow, so the action sees worker, and the client passes it. unstamp is the one store write the legacy test needs; inlining it moves those lines into the test.

The doc on legacyProjectOf is why the key comes out: workProjectId is a later set, and the input fallback is what the run read. Folding the schema comment back to one line is the only shorter wording, and the check stays the same length. The README sentence, the docs table row, and the changeset are the caller-visible line each.

Open in Web View Automation 

Sent by Cursor Automation: Code Snob

The two legacy readers share stateBeforeWorkProject. Hand-over keeps
handing only the conversation's pre-workProjectId project, not the one a
row's input names: a legacy root's task session already exists with that
value in its readonly filingProjectId, and the doc comment now says so.
Adds the waiting-row leg, moves the unstamp fixture to the projects
harness, notes that the worker check is the caller's intent and not a
boundary, and rewraps the README paragraph.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qsh48df8qzrorsfaCXn1X7
…the conversation's project

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qsh48df8qzrorsfaCXn1X7

Copy link
Copy Markdown
Collaborator Author

@codex review

7b52ca5 adds one test leg for the head of engineering's second note. It covers legacyProjectOf's branch that reads the conversation's project: a project coordinator's legacy row whose input names another project, followed up. The control is to prefer the row's input over the conversation's project. With that control the new leg fails (the follow-up is refused) and the other 14 legs pass.

Please look closely at unstamp's new input argument in test/projects-harness.ts. It rewrites the row's input to mimic a row filed before the board wrote the conversation's project over a named one. Check that this matches a shape a real stored row could have.


Generated by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 7b52ca58a8

ℹ️ 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".

@jhoffner
jhoffner merged commit 2ce8d58 into main Oct 24, 2026
18 checks passed
@jhoffner
jhoffner deleted the claude/project-thread-fppi6t branch October 24, 2026 13:02
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