Repository navigation
FIX-1701: one shared item-scope reader for the three harness emitters; Claude Code nests under its container - #2569
Conversation
…X-1701 S0) Pins which of taskId and ownedBy each emitted item version carries, by key presence and value, across the identity matrix (none, task only, owner only, task and owner, empty-string task), on every item kind and close path of the Claude Code, Codex and Cursor emitters. Test-only, green on unmodified source, including Claude Code's current missing top-level and sub-agent-box owner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
…iner (FIX-1701 S1) Claude Code stamped no ownedBy on its top-level items or its sub-agent container items, so a run inside a container showed its steps outside it, breaking the documented Container Ownership contract that Codex and Cursor keep. Every top-level item and sub-agent box now carries the runtime owner; items inside a sub-agent keep the sub-agent's owner (subAgentOwner ?? runtimeOwner, decided at the call site). Presence is `!== undefined`. Flips only the characterization's Claude Code top-level and sub-agent-box owner rows, and adds the owned-container test that drives claudeCodeAgent through a real sequencer declaring a container (red on main, green now). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
…cope (FIX-1701 S2)
itemScope(ctx) returns { taskId?, ownedBy? } off the runtime identity, each
key present only when the identity defines it (!== undefined). Marked
@internal and exported through @flow-state-dev/core/types beside asRuntime;
not re-exported from the package root.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
…701 S3) Removes the private deriveScope reader and its EmitScope type; every former use spreads itemScope(ctx). Stamped output unchanged (V0 untouched). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
…1701 S4) Removes the private deriveScope reader and its EmitScope type; every former use spreads itemScope(ctx). Stamped output unchanged (V0 untouched). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
…(FIX-1701 S5) The shared item stamp reads the task id, and the owner precedence reads the runtime owner, through itemScope(ctx) instead of casting the identity inline. Pure refactor against S1's behaviour (V0 and V5 untouched). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
…ting (FIX-1701 S6) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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: serverGenReqId_718118dd-9f36-4b5c-b6bb-94128c70eed2) |
|
Second look + architecture pass (read-only; for the implementing agent to triage) Overall: the direction is sound and the scope is disciplined. One shared reader replacing two byte-identical private copies ( 1. Likely release/runtime hazard: Claude Code now needs a core that has 2. Claude Code's 3. Behavior change worth one explicit test: item closes vs. the open's owner. 4. Nested sub-agents: the box still takes the runtime owner, not the enclosing sub-agent. 5. Test duplication across packages (optional). 6. Minor: Not raising: the Generated by Claude Code |
There was a problem hiding this comment.
Simplify review (FIX-1701)
Verdict: The production shape is the right local minimum for this problem. I’m approving; the notes below are simplification opportunities and follow-ups, not blockers.
Did the approach go too far?
Runtime code: no. Collapsing Codex/Cursor’s identical deriveScope into one itemScope in core/types, and having Claude compose nesting via resolveOwnedBy → subAgentOwner ?? itemScope(ctx).ownedBy, matches what the spec calls out as the smallest extract that still fixes container ownership. The alternatives that would look “simpler” in line count (engine stamping scope on every emit, a shared harness-emit package, or a full runtime-identity reader including provenance) are correctly deferred in DECISIONS.md and would widen blast radius or blur ownership rules.
Where the PR feels heavier than the runtime delta:
- Triplicated “scope characterization” suites in Codex, Cursor, and Claude
emit.spec.ts(~same identity matrix,actualScope/expectedScope, and per-version loop). The spec intentionally wants per-package characterization (good), but the scaffolding does not need to be copy-pasted three times. A shared helper in@flow-state-dev/testing(identities table +assertScopeOnItemVersions, optionalrecordingHarnessCtx) would shrink ~200 lines and keep the three packages’ event scripts distinct. - Retained spec + figures + POC add a large diff surface. That’s repo process, not accidental complexity—but if the goal is “smallest PR,” splitting spec merge from implementation is sometimes cleaner. Here the characterization-before-change story is tied to the spec, so bundling is defensible.
- Claude
itemFieldsstill partially re-implementsitemScope(task id omission rules) whileownedBygoes throughresolveOwnedBy. Not wrong (sub-agent owner must win), butconst { taskId } = itemScope(ctx)(or a tinyitemTaskScopein core) would make “one reader” literally one place for omission semantics. deriveProvenance+ unsafe_blockIdentitycasts remain triplicated across harness emitters (pre-existing). The POC guardstaskId/ownedByreads; provenance is the obvious next extract if you want “no unclassified identity reads.”
Performance
No concerns for merge. Claude may call itemScope more than once per item-open path (micro-allocations). Optional follow-up: cache itemScope(ctx) once per emit function; not worth blocking.
Third-party / structure
No obvious off-the-shelf package for “spread optional keys from block identity.” Core helper is appropriate. Cross-import smell is low: harnesses only depend on core/types, not each other.
Skipped recommendations (larger than this PR)
- Unifying
generator.tsscope stamping withitemScope(different undefined-vs-omit behavior risk). - New internal package for shared
buildHarnessItemBase/deriveProvenance. - CI wiring for
AFTER=1 node specs/issues/FIX-1701/poc/scope-readers/check.mjs(nice guard; not required for approval).
Changeset nit (uncertain)
Changeset targets @flow-state-dev/claude-code only. If release notes policy treats any new core export as consumer-visible—even @internal—consider a patch fragment for @flow-state-dev/core as well. If @internal means “omit from changesets,” a one-line PR note is enough.
Sent by Cursor Automation: Review For Best Approach
There was a problem hiding this comment.
Code Snob. A smaller shape exists, and it keeps the same contract.
itemFields stamps the task id, then every Claude Code emit site stamps ownedBy again (...(ownedBy !== undefined ? { ownedBy } : {}), fourteen times, plus four separate itemScope(ctx).ownedBy reads for the sub-agent box, its close, the error item, and finalize). That is the copy the shared reader was supposed to end. Codex and Cursor already spread the scope once inside buildBase.
Put the runtime owner on itemFields / buildBase with the task id. Pass an owner only when it replaces that one: a sub-agent id, or the owner the open stored so the close keeps it. Sub-agent boxes, errors, and their closes then need no extra line.
Sketch, already green: #2570 (−17 lines, packages/claude-code/src/sdk/emit.ts only). pnpm --filter @flow-state-dev/claude-code test — 271 passed, including the scope characterization and the owned-container check. Sub-agent owner still wins inside a sub-agent; everything else still carries the runtime owner; an absent owner is still omitted.
Fold that subtraction into this PR. After this PR lands, close the POC unmerged. It does not merge.
I left the per-package characterization copies alone. The spec asks each package to pin its own emitter, and a shared test helper would add surface rather than remove it.
Sent by Cursor Automation: Code Snob
…temFields (FIX-1701 review) The runtime owner now rides on itemFields/buildBase with the task id, spread as itemScope returns it, so the omission rule lives in core alone. An owner is passed only when it replaces the runtime one: a sub-agent's id, or the owner an open stored so its close keeps it. Drops the per-site ownedBy spreads and the four separate itemScope(ctx).ownedBy reads. No emitted value changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
… trim V0 owner helpers (FIX-1701 review) V5 compared ownership against rows rebuilt from the actual items, so a wrong but self-consistent mapping could pass. It now lists the expected rows from the scripted run. V0's two identical owner helpers are inlined and its sub-agent owner is derived from the fake context's instance id. Asserted values are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
|
from: fsd-claude Re Code Snob's review (5378607923): the subtraction is folded in on this branch at 77d391a (commit 6770497), applied by hand. #2570 is not merged or cherry-picked; it stays open as the POC. Claude Code's One deviation from the sketch: it spreads Generated by Claude Code |
…roved FIX-1907's epic spec merged to main (#3162); its six children are filed. Epics table, Now line and the PLAN lane link to specs/epics/FIX-1907/. Flags FIX-1701's stale Linear status (PR #2569 merged). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017pp7wCd87NW4BH7XVuF9Gv


from: fsd-claude
session: refactor-desk-0930
kind: reply
A Claude Code run placed inside a container shows its steps outside that container. Codex and Cursor runs show theirs inside it, and the docs say all three should. The cause is that each of the three coding harnesses reads its task scope in its own way. That drift is also how Claude Code once shipped without the task id, which left a task's own screen empty (FIX-1692).
What this does. It adds one shared reader for "which task and which container is this step in". All three harnesses now call it instead of keeping their own copy. Claude Code also starts stamping the container on its top-level steps and on its sub-agent boxes. Steps inside a sub-agent still show inside that sub-agent. Codex and Cursor output does not change at all.
What's asked of you: nothing new. This implements the approved direction in specs/issues/FIX-1701 (D1 = A, D2 internal).
Parts worth reviewing closely
packages/claude-code/src/sdk/emit.ts→resolveOwnedBy: the owner precedencesubAgentOwner ?? itemScope(ctx).ownedBy. A message, reasoning or tool item whoseparentCallIdnames a sub-agent that is not open now falls back to the runtime owner. Onmainit got no owner at all. I read that as "not inside any known container, so it belongs to the enclosing one".itemFields/buildBase: since the review round, the runtime owner rides here with the task id, spread asitemScopereturns it. An owner is passed only when it replaces the runtime one: a sub-agent's id, or the owner an open stored so that its close keeps it. Every site, including closes, the orphan tool result, the error item and finalize, emits the same owner value as before; only the key's position in the object moves.packages/core/src/types/block.ts→itemScope: marked@internaland exported only through@flow-state-dev/core/types, besideasRuntime. It is not exported from the package root (D2).Spec:
specs/issues/FIX-1701/(merged in #2549) · Linear: FIX-1701 · no epic · this PR merges.How to review this: altitude, what's in scope, what's deliberately unsettled
Engineering calls: decisions made while building, one line each
createTestContext. It asserts key presence on the rawitem.added/item.doneobjects, so no harness normalisation can hide a key set toundefined. If this is wrong, a difference that only shows up through the real response store goes unpinned; V5 covers that path for Claude Code.topLevelOwnerandcontainerOwner), and S2 to S5 touch no test assertion. Check withgit diff 3841e8d2e..1f113a6dc -- '*.spec.ts'after S1. If this is wrong, a stamp moved during the extract. The review round's test commit (77d391a2c) changes test structure only: V5's expected rows are spelled out from the script, and V0's two identical owner helpers are inlined. No asserted value changes.itemFields. This follows Cursor's review and the POC: stamp Claude Code's item owner once in itemFields #2570 sketch, applied by hand; POC: stamp Claude Code's item owner once in itemFields #2570 is not merged. It differs from the sketch in one place:itemFieldsspreadsitemScope(ctx)whole instead of re-spelling thetaskIdcheck, so the omission rule lives in core alone. If this is wrong, a close could lose the owner its open stored; V0's close-path rows pin that.patchon@flow-state-dev/claude-codeonly. Core gets none, because the reader is internal (D2), and Codex and Cursor get none because their output is unchanged (BP-022).apps/docs/docs/tools/claude-code-sdk.mdsay nothing about steps sitting outside an enclosing container. No doc edits.Everything else: commits, the goal check red then green, controls, checks
Commits, in PLAN order
3841e8d2ee0ffc6051e2f5ad8dbitemScopein core, plus V1da546259eitemScope(ctx)(privatederiveScopeandEmitScoperemoved)4882292211f113a6dcitemScope77b08f75f6770497b9itemFields(Cursor review, #2570 shape)77d391a2cV0, what it pins. It covers each identity (none · task only · owner only · task and owner · empty-string task) and every item version, on open and on close. For Claude Code that means streamed message and reasoning closed by the next item, by a turn-boundary flush, by a tool call, by a sub-agent opening, and at stream end. It also covers whole message and reasoning, a tool opened and settled, an orphan failed result, a tool left open, a sub-agent closed, closed failed, and left open, an error, and inside a sub-agent its streamed and whole text, a tool, an orphan result, and a tool left open. Codex and Cursor cover message, reasoning, a tool opened and settled, an orphan failed result, an error, and a tool finalized at stream end. It is asserted on the scope key list.
V5, the goal check, red on
main.claudeCodeAgentruns as a step of a realsequencer({ container })throughtestBlock. It now compares against anexpectedOwnershiplist written out from the script. This is the current V5 run againstorigin/main'spackages/claude-code/src/sdk/emit.ts, with the file restored afterwards:On the current head it passes, along with the rest of the claude-code suite (271).
Control (a): the reader drops
taskId. Re-run on77d391a2c. I removed thetaskIdline fromitemScope, ranvitest -t "scope characterization"in each package, then restored the line.Control (b): Claude Code's stamp drops the runtime owner. Re-run on
77d391a2c. With the owner now stamped once, I strippedownedByfrom theitemScope(ctx)spread initemFieldsand maderesolveOwnedByreturnsubAgentOwneronly, then restored both.The tree was clean after both controls (
git diffshowed only the committed changes).V3: the spec's checker.
On fresh
main, before S0, the plain check passed with the same six readers classified, so nothing new needed classifying. The head run classifies the same six readers as77b08f75fdid.Checks run locally before push (head
77d391a2c)pnpm typecheck: 74/74 tasks passed; package-boundary, updater-purity, side-chain-vocabulary and control-shape guards OK.knipon the four workspaces (at77b08f75f): nothing in the touched files. The listed findings, such asInferResourcesFromSchemas, are already onmain.validate-changeset-refs,validate-spec-folder,validate-publish-set,validate-no-nul-bytes,validate-model-strings,validate-reserved-names(at77b08f75f): OK.pnpm changeset status --since=origin/main: patch for@flow-state-dev/claude-codeonly.Not here, per the spec's fences: the FIX-1668 task-run link, the provenance extract, FIX-1649, and core's own emit sites.
🤖 Generated with Claude Code
https://claude.ai/code/session_019ZDCzhKV2YFRy4LucoHjCx
Generated by Claude Code
Note
Medium Risk
Changes how streamed items are attributed (
ownedBy) in Claude Code UI nesting; Codex/Cursor behavior is refactored to a shared reader but intended to be unchanged.Overview
Introduces a shared
itemScopehelper in core so Claude Code, Codex, and Cursor harness emitters readtaskIdandownedByfrom block identity the same way (replacing per-packagederiveScope/ inline casts).The behavioral fix is in Claude Code emission:
resolveOwnedBynow falls back to the runtime container owner when there is no open sub-agent (subAgentOwner ?? itemScope(ctx).ownedBy), and sub-agent container, error, and finalize paths stamp that outerownedBy. Top-level steps and sub-agent boxes therefore nest inside an enclosing container like Codex/Cursor already did; work inside a sub-agent still nests under the sub-agent box.Adds broad scope characterization tests plus an integration test for a Claude run inside a
sequencer({ container }). Ships a patch changeset for@flow-state-dev/claude-codeonly (FIX-1701).Reviewed by Cursor Bugbot for commit 77b08f7. Configure here.