Skip to content

Commit cb24bb1

Browse files
praffiiiclaude
andcommitted
fix(mobile): sends compact only after the notice announces it
The notice checks eligibility on a minute clock while the send checks the exact time, so for up to a minute after a thread went stale a send could compact with no notice and no way to keep the history. A send now compacts only when the notice was showing and the send-time check still agrees, which matches web, where the send reads the same value as the chip. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a6375ec commit cb24bb1

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,29 @@ describe("mobile task permissions", () => {
316316
visibleTurnItems: [],
317317
updatedAt: DateTime.makeUnsafe(0),
318318
} as unknown as OrchestrationV2ThreadProjection;
319-
state.compactModel = "gpt-5.5";
320-
const stale = useThreadComposerState(NO_SIDE_CHATS);
321-
expect(stale.compactBeforeSend).toBeNull();
322-
// A model picked after the last render still decides the send.
323-
state.draft = {
324-
...state.draft,
325-
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.5" },
326-
};
327-
await stale.onSendMessage();
319+
const due: ModelSelection = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.5" };
320+
state.compactModel = due.model;
321+
const unannounced = useThreadComposerState(NO_SIDE_CHATS);
322+
expect(unannounced.compactBeforeSend).toBeNull();
323+
// Due at send time but not at the last render, as when the minute clock trails the deadline.
324+
state.draft = { ...state.draft, modelSelection: due };
325+
await unannounced.onSendMessage();
328326
expect(state.enqueue).toHaveBeenLastCalledWith(
329-
expect.objectContaining({ compactBeforeSend: true }),
327+
expect.not.objectContaining({ compactBeforeSend: true }),
330328
);
331329
const composer = useThreadComposerState(NO_SIDE_CHATS);
332330
expect(composer.compactBeforeSend?.tokens).toBe(248_000);
331+
await composer.onSendMessage();
332+
expect(state.enqueue).toHaveBeenLastCalledWith(
333+
expect.objectContaining({ compactBeforeSend: true }),
334+
);
335+
// A model picked after the last render still decides the send.
336+
state.draft = { ...state.draft, modelSelection: undefined };
337+
await composer.onSendMessage();
338+
expect(state.enqueue).toHaveBeenLastCalledWith(
339+
expect.not.objectContaining({ compactBeforeSend: true }),
340+
);
341+
state.draft = { ...state.draft, modelSelection: due };
333342
composer.compactBeforeSend?.keepFullHistory();
334343
const kept = useThreadComposerState(NO_SIDE_CHATS);
335344
expect(kept.compactBeforeSend).toBeNull();

‎apps/mobile/src/state/use-thread-composer-state.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,10 @@ export function useThreadComposerState(input: {
761761
// A redirect belongs to the approval it answers; the armed session waits for the next message.
762762
const freshContext = beforeDispatch === undefined && isFreshSessionPending(threadKey);
763763
const metadata = makeQueuedMessageMetadata();
764-
// A fresh session drops the context a compaction would summarize.
764+
// A fresh session drops the context a compaction would summarize. Only a send the notice
765+
// announced compacts, since the notice's minute clock can trail the exact deadline.
765766
const compactBeforeSend =
767+
compactTokens !== null &&
766768
!freshContext &&
767769
followUpDispatchMode === null &&
768770
appAtomRegistry.get(fullHistoryThreadKeysAtom)[threadKey] !== true &&

0 commit comments

Comments
 (0)