Skip to content

Commit c3c2f91

Browse files
author
PR Batch Tester
committed
fix(mobile): compact when the original prompt is paged out
1 parent 325930a commit c3c2f91

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

‎apps/mobile/src/state/thread-task-permissions.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ describe("mobile handoff preview and submission", () => {
333333
auth: { status: "authenticated" as const },
334334
availability: "available" as "available" | "unavailable",
335335
models: [{ slug: selection.model }],
336+
slashCommands: [],
336337
};
337338
const projectOverride = { enabled: false };
338339
state.serverConfig = {

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function sendInput(
4040
readonly heldQueue?: boolean;
4141
readonly pendingRequest?: boolean;
4242
readonly onlyCompactMessages?: boolean;
43+
readonly promptOutsideWindow?: boolean;
4344
readonly text?: string;
4445
readonly threadIdle?: boolean;
4546
} = {},
@@ -67,15 +68,19 @@ function sendInput(
6768
contextUsage: null,
6869
updatedAt: DateTime.makeUnsafe(lastTurnAt),
6970
});
70-
const visibleTurnItems = [
71-
{
72-
item: {
73-
type: "user_message",
74-
text: overrides.onlyCompactMessages === true ? "/compact" : "Fix the build",
75-
attachments: [],
76-
},
77-
},
78-
];
71+
const visibleTurnItems =
72+
overrides.promptOutsideWindow === true
73+
? [{ item: { type: "assistant_message", text: "Build fixed" } }]
74+
: [
75+
{
76+
item: {
77+
type: "user_message",
78+
runId: RunId.make("run-1"),
79+
text: overrides.onlyCompactMessages === true ? "/compact" : "Fix the build",
80+
attachments: [],
81+
},
82+
},
83+
];
7984
const projection = {
8085
...v2Projection,
8186
thread: {
@@ -179,6 +184,11 @@ function sendInput(
179184
describe("shouldCompactBeforeSend", () => {
180185
it.each([
181186
{ name: "a stale Claude thread over 200K", expected: true },
187+
{
188+
name: "when the original prompt is outside the loaded window",
189+
promptOutsideWindow: true,
190+
expected: true,
191+
},
182192
{
183193
name: "when the environment compacts before the cache expires",
184194
settings: { idleCompaction: "beforeCacheExpires" },

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,19 @@ export function shouldCompactBeforeSend(input: {
271271
resolvePendingHandoff(projection, input.selection, input.providers) !== null ||
272272
projection.runtimeRequests.some((request) => request.status === "pending") ||
273273
projection.runs.some((run) => run.status === "queued" && run.queueHeld === true) ||
274-
!input.visibleTurnItems.some(
274+
(!input.visibleTurnItems.some(
275275
({ item }) =>
276276
item.type === "user_message" &&
277277
(item.text.trim().toLowerCase() !== "/compact" || item.attachments.length > 0),
278-
) ||
278+
) &&
279+
!projection.runs.some(
280+
(run) =>
281+
run.status !== "rolled_back" &&
282+
run.startedAt !== null &&
283+
!input.visibleTurnItems.some(
284+
({ item }) => item.type === "user_message" && item.runId === run.id,
285+
),
286+
)) ||
279287
hasDismissedResumeCompaction(
280288
projection.runtimeRequests
281289
.filter((request) => request.kind === "user_input" && request.status === "resolved")

0 commit comments

Comments
 (0)