Skip to content

Commit da07ba8

Browse files
fix(composer): queued edits keep legacy recall and the original effort prefix
Mobile typing clears the draft's recall provenance, so saving a queued edit took the generated effort prefix as authored text. The save now takes records from the draft and provenance from the original message. A queued message sent without provenance whose text the legacy recall would change is legacy; saving it, unchanged or edited, no longer marks its whole decorated text as authored, so recall keeps the fallback. AI-assisted; verified with the tests and tools listed above.
1 parent fc98ce0 commit da07ba8

5 files changed

Lines changed: 44 additions & 11 deletions

File tree

‎apps/mobile/src/state/queued-run-edit.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ describe("resolveQueuedEditPayload", () => {
134134
expect(payload.context).toEqual(recalled);
135135
});
136136

137+
it("keeps the effort prefix generated after typing cleared the draft's provenance", () => {
138+
const originalText = "Ultrathink:\noriginal";
139+
const revised = "Ultrathink:\noriginal revised";
140+
const payload = resolveQueuedEditPayload({
141+
edit: {
142+
...edit([]),
143+
originalText,
144+
context: { version: 1, records: [], composerRecall: [12, originalText.length] },
145+
},
146+
text: revised,
147+
draftText: revised,
148+
draftContext: undefined,
149+
draftAttachments: [],
150+
uploaded: [],
151+
});
152+
153+
expect(recallComposerText(payload.text, payload.context)).toBe("original revised");
154+
});
155+
137156
it.each(["", "Ultrathink:"])(
138157
"omits the generated bootstrap when an attachment remains after editing to %j",
139158
(draftText) => {

‎apps/mobile/src/state/queued-run-edit.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,17 @@ export function resolveQueuedEditPayload(input: {
175175
input.draftAttachments,
176176
input.uploaded,
177177
);
178+
// Typing clears the draft's provenance; the edit's original provenance locates the effort prefix.
179+
const originalRecall = input.edit.context?.composerRecall;
178180
const recall = (context: OrchestrationMessageContext | undefined) =>
179-
composerRecallContext(text, input.draftText, context, input.edit.originalText) ?? {
181+
composerRecallContext(
182+
text,
183+
input.draftText,
184+
originalRecall === undefined
185+
? context
186+
: { ...(context ?? { version: 1, records: [] }), composerRecall: originalRecall },
187+
input.edit.originalText,
188+
) ?? {
180189
version: 1,
181190
records: [],
182191
};

‎apps/web/src/components/chat/useQueuedRunEdit.browser.test.tsx‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,19 +329,12 @@ describe("useQueuedRunEdit", () => {
329329
() => {},
330330
);
331331

332-
const keptReference = formatInlineContextReference(threadContextReference(kept));
333-
const sentText = `${keptReference} and`;
332+
const sentText = `${formatInlineContextReference(threadContextReference(kept))} and`;
334333
expect(mocks.editQueuedRun).toHaveBeenCalledWith(
335334
expect.objectContaining({
336335
input: expect.objectContaining({
337336
text: sentText,
338-
edit: expect.objectContaining({
339-
context: {
340-
version: 1,
341-
records: [kept],
342-
composerRecall: [keptReference.length + 1, sentText.length],
343-
},
344-
}),
337+
edit: expect.objectContaining({ context: { version: 1, records: [kept] } }),
345338
}),
346339
}),
347340
);

‎packages/shared/src/composerContextReferences.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,10 @@ describe("composer recall provenance", () => {
626626
composerRecallContext(revised, revised, previous, "Ultrathink:\nold"),
627627
),
628628
).toBe("old revised");
629+
// A message sent without provenance stays on the legacy fallback, saved unchanged or edited.
630+
const legacy = "Ultrathink:\nold";
631+
expect(composerRecallContext(legacy, legacy, undefined, legacy)).toBeUndefined();
632+
expect(composerRecallContext(revised, revised, undefined, legacy)).toBeUndefined();
629633
});
630634

631635
it("retains original whitespace when an unchanged queued draft is saved again", () => {

‎packages/shared/src/composerContextReferences.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,15 @@ export function composerRecallContext(
525525
// Recompute rather than carrying provenance from a message being edited.
526526
const { composerRecall: _previousRecall, ...base } = context ?? { version: 1, records: [] };
527527
// Absent provenance falls back to the legacy heuristic, so record it whenever that would differ.
528-
if (text === sentText && stripLegacyPromptDecoration(sentText) === sentText.trim()) {
528+
// A message sent without provenance where the heuristic applies is legacy: an edit keeps it so.
529+
const legacyEdit =
530+
previousSentText !== undefined &&
531+
context?.composerRecall === undefined &&
532+
stripLegacyPromptDecoration(previousSentText) !== previousSentText.trim();
533+
if (
534+
legacyEdit ||
535+
(text === sentText && stripLegacyPromptDecoration(sentText) === sentText.trim())
536+
) {
529537
return base.records.length > 0 || base.guest ? base : undefined;
530538
}
531539
const start = text.length > 0 ? sentText.indexOf(text) : -1;

0 commit comments

Comments
 (0)