Skip to content

fix(server): subagents and forks no longer copy their source's fork, guest-link and history state - #914

Merged
yaacovcorcos merged 4 commits into
mainfrom
fix/derived-thread-scient-fields-20261114
Nov 14, 2026
Merged

yaacovcorcos merged 4 commits into
mainfrom
fix/derived-thread-scient-fields-20261114

Conversation

@yaacovcorcos

@yaacovcorcos yaacovcorcos commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Since beta 0.6.29-beta.20261114.1, delegate_task from any forked conversation fails with "Failed to load orchestration projection for thread thread:delegated-task:…". So do Codex reviews started from a fork.

The cause: makeSubagentChildThread (T3's builder, also used by Claude's and Codex's native subagents) copies the whole parent thread, including Scient's own conversationFork. dispatchMessage then runs the fork-only consumed-transfer read added in #882 against the subagent. At that point the subagent exists only as a pending thread.created event in the same command, so the read fails.

The copy did more than fail delegation. About 20 Scient readers treat conversationFork as "this thread is a fork", including analytics, the read-through-fork history read, attachment budgets and handoff policy. Each of them misjudged every subagent of a fork.

Traced from the installed beta's server trace and reproduced from a forked conversation.

Change

  • scientDerivedThread.ts defines SCIENT_DERIVED_THREAD_RESETS, the facts about a thread's own history that a thread derived from it must not copy:
    • Scient's fork, import and fork-lineage state;
    • the rollback receipt, cleared as a whole (clearing only Scient's rollbackCompletedRequestId would make analytics count an inherited rollbackRequestId as pending);
    • usage-limit recovery and unsettledAt, which Scient's fork paths already reset.
  • The derived-thread-fields seam in makeSubagentChildThread spreads it after the copy.
  • The seam's other line drops delegatedFrom, word for word as T3's open fix(server): subagent threads no longer show the remote parent their parent was delegated from pingdotgg/t3code#30334 does, so it gives way to T3's at the next alignment once #30334 lands. SCIENT_DERIVED_THREAD_RESETS also resets what T3's own fork resets: opens, activeOrderKey, lastSnoozeWakeAt. No T3 PR for those three: they have no effect a T3 user can see, because subagents are never listed.
  • The failing read itself is unchanged. It is correct for real forks, which are always stored. Catching its "not found" error would have hidden the wrong fork state instead of removing it.
  • Second commit, found by Codex review: Scient's own fork builder (ConversationForkService, the web Fork dialog's path) also copied the source thread and kept its guestShare. Guest links resolve by share id (findGuestShareThreadId, LIMIT 1), so an invite to the source could open the fork, including anything written there after forking. The fork now clears guestShare, plus what T3's own fork resets: delegatedFrom, opens, lastSnoozeWakeAt, autoSettleDisabledAt. This only affects users who turned on beta guest sharing.
  • Forks already in users' databases still carry a copied share in their events, so editing projection rows would not last. A thread is always created without a share of its own, so a share already in its thread.created event was copied. The copied-guest-share seams in ProjectionStore.findGuestShareThreadId and GuestShareService.authorize refuse such a share, for invites and for sessions already redeemed. This replaces a timestamp rule from an intermediate commit that Codex showed a backward clock could defeat.
  • Fields kept on purpose: workspace, branch, tags, section (a subagent is filed with its parent and is never listed), linkOrigin and branchPullRequest. workspaceAuthorityRevision is restamped by the store on thread.created.

Verification

  • New scient-fork/DelegatedTaskFromFork.test.ts:
    • starts a delegated task from a parent marked as a ready fork with delegation, rollback, list and fork state set;
    • its field table classifies every OrchestrationV2AppThread field as inherited, reset or set, typed as Record<keyof OrchestrationV2AppThread, …>, so a new field fails typecheck until it is classified.
  • ConversationForkService.test.ts now gives the source a guest share and asserts the fork has none. Its negative control fails on the original builder with the source's share id.
  • scient/guest/ownGuestShare.test.ts: an older fork created with its source's share in its creation event. The invite resolves to the source; once the source closes its link, it resolves to nothing. On main's lookup it fails, resolving to the fork.
  • Negative control: with the original builder, the test fails exactly as production did (ProjectionStoreThreadNotFoundError at the Orchestrator.ts consumed-transfer read).
  • Focused tests on macOS, Node 26.12.1, with the live-profile environment removed:
    • every server test that builds subagents or dispatches delegated_task.request: 34 files, 1,755 tests;
    • Claude/Codex adapter V2 tests: 4 files, 800 tests;
    • provider-core: 26 files, 292 tests.
  • Root pnpm run typecheck (0 errors), vp fmt --check and vp lint on the changed files, knip:check, seam check, git diff --check.
  • Every fork test (65 files: scient-fork/ plus the fork integration suites) passed except 6 cases in testkit/ProviderSwitch.integration.test.ts, which fail the same way locally on the unmodified source (token-usage expectations). That is local only and unrelated; CI ran that file green on the first head.
  • First CI run on 4042e0d: everything green except Test Server 9, which failed in ConversationImportStaging.test.ts (a cancelled-upload quota case). That is a known main problem since effect 4.1.3 and not touched here.
  • Final head bc73743, macOS, Node 26.12.1:
    • root typecheck: 0 errors;
    • repo-wide vp lint --report-unused-disable-directives: 0 errors;
    • vp fmt --check on the changed files, knip:check, seam check, git diff --check;
    • 42 server test files (1,874 tests): the subagent and delegated-task set, ProjectionStore, guest-share and fork-service tests.
  • Codex reviewed every commit in four rounds, with no open findings. The guest-link problem and the timestamp weakness both came from those reviews.
  • Not run locally: the full server suite, build and desktop smoke. Hosted CI runs the full suites.

Documentation impact

Updated:

  • UPSTREAM.md: new "Subagent thread fields" and "Copied guest links" sections.
  • docs/internals/upstream-alignment-protocol.md: when upstream narrows a shared read or copies a record carrying Scient fields.

Platforms

Server orchestration logic with no platform branches, so it behaves the same on macOS, Windows and Linux. Tests ran locally on macOS only; hosted CI covers Linux. Not tested on a real Windows or Linux machine; nothing here depends on the OS.

Model: Claude Opus 5.5 in Claude Code inside Scient.

🤖 Generated with Claude Code

… as that fork

delegate_task from any forked conversation failed with "Failed to load
orchestration projection". makeSubagentChildThread copies the parent thread,
so the subagent inherited Scient's conversationFork. dispatchMessage then ran
the fork-only consumed-transfer read (added in #882) against the subagent,
which exists only as a pending event in that command, and the read failed.
The same copy made fork, import, rollback, usage-limit and analytics readers
treat every subagent of a fork as a fork. Claude's and Codex's native
subagents share the builder.

A derived thread now starts without the origin's own history: Scient's fork,
import and fork-lineage state, the rollback receipt as a whole, usage-limit
recovery and unsettledAt. It also resets what T3's own fork already resets
(delegatedFrom, opens, activeOrderKey, lastSnoozeWakeAt), offered to T3
separately. A field table in the regression test classifies every thread
field, so an upstream merge that adds one fails typecheck until it is decided.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M labels Nov 14, 2026
yaacovcorcos and others added 2 commits November 14, 2026 14:24
… link

ConversationForkService built the fork from a copy of the source thread and
kept its guestShare. Guest links are looked up by share id (LIMIT 1), so an
invite to the source could open the fork, including what was written there
after the fork. The fork also kept the source's remote delegation, opens,
last snooze wake and auto-settle opt-out, which T3's own fork resets.

Found by Codex review of #914.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Forks made before the previous commit still carry their source's guestShare
in their events, so the invite lookup (LIMIT 1) could resolve to the fork,
and after the source closed its link the fork was the only match. A share
made for a thread is always created after the thread, so the lookup and
guest authorization now accept a share only on a thread created before it.

Also keeps only T3's open #30334 line (drop delegatedFrom) inside T3's
subagent builder; the opens, list-position and snooze-wake resets move into
SCIENT_DERIVED_THREAD_RESETS, since T3 shows no visible effect from them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added size:L and removed size:M labels Nov 14, 2026
…ent, not timestamps

The previous commit judged ownership by comparing the share's and thread's
creation times. Codex showed a clock moving backwards defeats that both ways.
A thread is always created without a share of its own, so a share already in
its thread.created event was copied. The lookup and authorization now ask
exactly that (one indexed read; thread.created events are never pruned).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yaacovcorcos yaacovcorcos changed the title fix(server): a subagent of a forked conversation is no longer treated as that fork fix(server): subagents and forks no longer copy their source's fork, guest-link and history state Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.5 KiB 5.5 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 4.2 KiB 4.2 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.3 KiB 1.3 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 22.3 KiB 22.3 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.5 KiB 5.5 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 4.2 KiB 4.2 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.3 KiB 1.3 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 22.7 KiB 22.7 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 12.0 KiB 12.0 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 45.1 KiB 45.1 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 45.1 KiB 45.1 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 12.2 KiB 12.2 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.1 KiB 384.1 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 45.6 KiB 45.6 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 45.6 KiB 45.6 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: 7378666 · PR result: bc73743 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Bounded compact HTTP snapshot with live cursor.

  • Codex decoded thread snapshot: 88.2 KiB
  • Claude decoded thread snapshot: 88.4 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@yaacovcorcos
yaacovcorcos added this pull request to the merge queue Nov 14, 2026
Merged via the queue into main with commit 4a01db6 Nov 14, 2026
111 of 130 checks passed
@yaacovcorcos
yaacovcorcos deleted the fix/derived-thread-scient-fields-20261114 branch November 14, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant