Skip to content

Commit 325930a

Browse files
author
PR Batch Tester
committed
fix(mobile): keep fork compaction on its source instance
1 parent 6a8c20c commit 325930a

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎packages/client-runtime/src/state/contextWindow.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function sendInput(
3434
readonly source?: ProviderInstanceId;
3535
readonly selected?: ProviderInstanceId;
3636
readonly onlyEarlierConversationUsage?: boolean;
37+
readonly unstartedFork?: boolean;
3738
readonly slashCommands?: ReadonlyArray<string>;
3839
readonly dismissed?: boolean;
3940
readonly heldQueue?: boolean;
@@ -136,6 +137,29 @@ function sendInput(
136137
],
137138
visibleTurnItems,
138139
} as unknown as ThreadStructure;
140+
if (overrides.unstartedFork === true) {
141+
Object.assign(projection, {
142+
thread: {
143+
...projection.thread,
144+
activeProviderThreadId: null,
145+
forkedFrom: { type: "run", threadId: "source-thread", runId: "source-run" },
146+
},
147+
runs: [],
148+
providerThreads: [],
149+
providerTurns: [],
150+
contextTransfers: [
151+
{
152+
type: "fork",
153+
targetThreadId: projection.thread.id,
154+
sourceThreadId: "source-thread",
155+
sourcePoint: { runId: "source-run" },
156+
sourceProviderInstanceId: source,
157+
status: "pending",
158+
sourceTokenUsage: { usedTokens: 293_611, updatedAt: lastTurnAt },
159+
},
160+
],
161+
});
162+
}
139163
const selected = overrides.selected ?? claude;
140164
return {
141165
projection,
@@ -204,6 +228,13 @@ describe("shouldCompactBeforeSend", () => {
204228
onlyEarlierConversationUsage: true,
205229
expected: false,
206230
},
231+
{ name: "an unstarted fork resuming its source instance", unstartedFork: true, expected: true },
232+
{
233+
name: "an unstarted fork selecting another Claude home",
234+
unstartedFork: true,
235+
selected: claudeOtherHome,
236+
expected: false,
237+
},
207238
{ name: "for a provider without /compact", slashCommands: [], expected: false },
208239
{
209240
name: "after Claude's resume dialog was answered Don't ask again",

‎packages/client-runtime/src/state/contextWindow.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export function shouldCompactBeforeSend(input: {
290290
);
291291
const liveUsage = latestProviderTurnTokenUsage(
292292
projection.providerTurns.filter((turn) => turn.providerThreadId === activeProviderThreadId),
293-
projection,
293+
input.selection.instanceId === projection.thread.modelSelection.instanceId ? projection : null,
294294
providerThread,
295295
);
296296
const contextWindow = deriveLatestContextWindowSnapshot(

0 commit comments

Comments
 (0)