Skip to content

Commit 49b3642

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(server): fork notice follows a first /compact and native replacement (#1864)
## Problem A conversation fork's notice tells its agent which thread it is. It missed the agent in two cases: - **Compact:** native `/compact` carries no notice - **Then:** the next turn treats it as delivered - **Replacement:** legacy runs suppress it Legacy runs are accepted runs with no recorded native id. ## Change - **New:** `conversationForkNoticeOwedFork` - **Owed:** until a non-compact run carries it - **Legacy runs:** as `nativeThreadHasTurns` - **Hook:** one call in `ProviderTurnStartService` - **Compact command:** still sent unchanged ## Scope and approval Closes #1668 Fix in the fork: human decision. Known limits disclosed in #1667. **Not changed:** a fork's very first `/compact` is refused before start; a fork copies no messages to compact. The reachable case is a first `/compact` on a fresh native thread; the compact test drives it. ## Close conditions - [ ] **Compact:** notice follows a first `/compact` - [ ] **Replacement:** notice after native replacement - [ ] **Tests:** both cases covered ## Verification New `ConversationForkNotice.fork.integration.test.ts`: one test per case, draining the effect worker, no sleeps. - [x] **Before fix:** 2/2 fail, notice missing - [x] **After fix:** `vp test run` → exit 0 (4/4) - [x] `vp run --filter t3 typecheck → exit 0` - [x] `vp run fork:ci → exit 0` - [x] `vp run check:changed → exit 1`: 2/5012 tests, both unrelated - `markdownPipeline` browser test: load flake, passes alone - `GitManager` CLAUDE.md test: local global gitignore; passes with `GIT_CONFIG_GLOBAL=/dev/null` ```text × follows a first /compact on a fresh native thread, leaving the command unchanged × reaches a replacement native thread despite legacy accepted attempts AssertionError: expected 'Context handoff (full_thread_summary)…' to include '[T3 Code conversation fork:' ``` Claude Opus 5.5, Claude Code in T3 Code. ## Fork trailers Squashes: - c4ed8bb fix(server): fork notice follows a first /compact and native replacement (#1864) (#1864) - 2927ac8 fixup! fix(server): fork notice follows a first /compact and native replacement (#1864) (#1864) Fork-Domain: upstream-fixes Fork-Tier: bugfix Fork-Upstreamable: yes Co-authored-by: donjor <[email protected]>
1 parent c20d6ef commit 49b3642

3 files changed

Lines changed: 415 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/ProviderTurnStartService.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import * as RunExecutionService from "./RunExecutionService.ts";
5757
import * as RuntimePolicy from "./RuntimePolicy.ts";
5858
import {
5959
conversationForkContextFork,
60+
conversationForkNoticeOwedFork,
6061
appendConversationForkContextFork,
6162
} from "./conversationFork.fork.ts"; // fork-hook: upstream-fixes/conversation-fork-context-import
6263
import {
@@ -1379,7 +1380,12 @@ export const layer: Layer.Layer<
13791380
);
13801381
const forkContextFork = conversationForkContextFork(
13811382
projection.thread,
1382-
nativeInputRunIds.size + legacyInputRunIds.size === 0,
1383+
conversationForkNoticeOwedFork(projection, {
1384+
sameNativeThread,
1385+
acceptedAttempts,
1386+
nativeInputRunIds,
1387+
legacyInputRunIds,
1388+
}),
13831389
); // fork-hook: upstream-fixes/conversation-fork-context
13841390
const startWithHandoffs = Effect.fn("ProviderTurnStartService.startWithHandoffs")(
13851391
function* (turnInput: Parameters<typeof session.startTurn>[0], compact = false) {

‎apps/server/src/orchestration-v2/conversationFork.fork.ts‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { OrchestrationV2AppThread } from "@t3tools/contracts";
1+
import type {
2+
OrchestrationV2AppThread,
3+
OrchestrationV2ThreadProjection,
4+
RunId,
5+
} from "@t3tools/contracts";
26

37
/** A fork copies conversation and checkout settings, not the source's live controls. */
48
export function freshConversationForkMetadataFork() {
@@ -64,6 +68,41 @@ export function conversationForkContextFork(
6468
].join("\n");
6569
}
6670

71+
/**
72+
* The notice is owed until a non-compact turn on the current native thread carried it: a native
73+
* `/compact` takes its command unchanged, so the notice waits for the next turn.
74+
*/
75+
export function conversationForkNoticeOwedFork(
76+
projection: Pick<OrchestrationV2ThreadProjection, "runs" | "messages">,
77+
input: {
78+
readonly sameNativeThread: boolean;
79+
readonly acceptedAttempts: ReadonlyArray<{ readonly nativeThreadId?: string | undefined }>;
80+
readonly nativeInputRunIds: ReadonlySet<RunId>;
81+
readonly legacyInputRunIds: ReadonlySet<RunId>;
82+
},
83+
) {
84+
// Legacy runs (no recorded native id) count only as ProviderTurnStartService's
85+
// `nativeThreadHasTurns` counts them: on an unreplaced thread with no recorded native ids.
86+
const held = new Set(
87+
input.sameNativeThread &&
88+
!input.acceptedAttempts.some((attempt) => attempt.nativeThreadId !== undefined)
89+
? [...input.nativeInputRunIds, ...input.legacyInputRunIds]
90+
: input.nativeInputRunIds,
91+
);
92+
// Turn-start projections load every `/compact` message, not every message.
93+
const compactMessageIds = new Set(
94+
projection.messages
95+
.filter(
96+
(message) =>
97+
message.attachments.length === 0 && message.text.trim().toLowerCase() === "/compact",
98+
)
99+
.map((message) => message.id),
100+
);
101+
return !projection.runs.some(
102+
(run) => held.has(run.id) && !compactMessageIds.has(run.userMessageId),
103+
);
104+
}
105+
67106
export function appendConversationForkContextFork(
68107
context: string,
69108
notice: string,

0 commit comments

Comments
 (0)