Skip to content

Commit ae0599b

Browse files
committed
fix(sidechat): address context and control review findings
1 parent c97c8a1 commit ae0599b

11 files changed

Lines changed: 268 additions & 164 deletions

‎apps/server/src/orchestration-v2/ContextHandoffService.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ it.layer(layerTest)("ContextHandoffService legacy import", (it) => {
149149
assert.include(handoff.summaryText, "SIDE_LOCAL_QUESTION");
150150
assert.include(handoff.history!.coverage, snapshotHistory.coverage);
151151
assert.deepEqual(snapshotHistory.messages, initial.history!.messages);
152+
const delta = yield* service.prepareProviderHandoff({
153+
...handoff,
154+
transferId: handoff.transferId,
155+
strategy: "delta_since_target_last_seen",
156+
initialHistory: snapshotHistory,
157+
fromProviderInstanceId: ProviderInstanceId.make("claudeAgent"),
158+
toProviderInstanceId: ProviderInstanceId.make("codex"),
159+
items: [
160+
importedItem({ role: "user", id: "new-question", text: "NEW_SIDE_QUESTION", ordinal: 2 }),
161+
],
162+
createdAt: DateTime.makeUnsafe("2026-01-04T00:00:00.000Z"),
163+
});
164+
assert.include(delta.summaryText, "NEW_SIDE_QUESTION");
165+
assert.notInclude(delta.summaryText, "FROZEN_MAIN_PARTIAL");
166+
assert.notInclude(delta.history!.coverage, snapshotHistory.coverage);
152167
}),
153168
);
154169

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,14 @@ const makeContextHandoffService = Effect.fn("orchestrationV2.ContextHandoffServi
453453
),
454454
);
455455
const runStatuses = new Map(input.runs?.map((run) => [run.id, run.status]));
456-
const coverage = input.initialHistory
457-
? `${input.initialHistory.coverage}\n${handoffCoverage(input)}`
456+
const initialHistory =
457+
input.strategy === "full_thread_summary" ? input.initialHistory : undefined;
458+
const coverage = initialHistory
459+
? `${initialHistory.coverage}\n${handoffCoverage(input)}`
458460
: handoffCoverage(input);
459461
const selected = selectHistory({
460462
messages: [
461-
...(input.initialHistory?.messages ?? []),
463+
...(initialHistory?.messages ?? []),
462464
...input.items.flatMap((item) => {
463465
const message = historicalMessage(item);
464466
return message === null
@@ -472,7 +474,7 @@ const makeContextHandoffService = Effect.fn("orchestrationV2.ContextHandoffServi
472474
}),
473475
],
474476
coverage,
475-
omittedItems: input.initialHistory?.omittedItems ?? 0,
477+
omittedItems: initialHistory?.omittedItems ?? 0,
476478
budget: tokenCap,
477479
});
478480
return {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10765,7 +10765,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1076510765
break;
1076610766
case "thread.side-chat.keep": {
1076710767
const projection = yield* getProjectionWithPendingEvents(command.threadId, events);
10768-
if (!projection.thread.sideChatOf) break;
10768+
if (projection.thread.deletedAt !== null) {
10769+
return yield* new OrchestratorDispatchError({
10770+
commandId: command.commandId,
10771+
commandType: command.type,
10772+
cause: `Thread ${command.threadId} is deleted.`,
10773+
});
10774+
}
1076910775
const now = yield* DateTime.now;
1077010776
yield* emit(
1077110777
events,
@@ -10775,7 +10781,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1077510781
threadId: command.threadId,
1077610782
providerInstanceId: projection.thread.providerInstanceId,
1077710783
occurredAt: now,
10778-
payload: { ...projection.thread, sideChatOf: null, updatedAt: now },
10784+
payload: projection.thread.sideChatOf
10785+
? { ...projection.thread, sideChatOf: null, updatedAt: now }
10786+
: projection.thread,
1077910787
});
1078010788
break;
1078110789
}

‎apps/server/src/orchestration-v2/SideChat.execution.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,32 @@ it.effect.each(cases)(
237237
assert.isNull(kept.thread.sideChatOf);
238238
assert.deepEqual(kept.contextHandoffs, b.contextHandoffs);
239239
assert.lengthOf(kept.runs, 1);
240+
yield* orchestrator.dispatch({
241+
type: "thread.side-chat.keep",
242+
commandId: CommandId.make("keep-second-again"),
243+
threadId: second,
244+
});
245+
const keptAgain = yield* orchestrator.getThreadProjection(second);
246+
assert.deepEqual(keptAgain.thread, kept.thread);
247+
assert.deepEqual(keptAgain.runs, kept.runs);
248+
240249
yield* orchestrator.dispatch({
241250
type: "thread.delete",
242251
commandId: CommandId.make("close-first"),
243252
threadId: first,
244253
});
245254
assert.isNotNull((yield* orchestrator.getThreadProjection(first)).thread.deletedAt);
255+
const deleted = yield* orchestrator.getThreadProjection(first);
256+
const keepDeleted = yield* orchestrator
257+
.dispatch({
258+
type: "thread.side-chat.keep",
259+
commandId: CommandId.make("keep-deleted"),
260+
threadId: first,
261+
})
262+
.pipe(Effect.flip);
263+
assert.equal(keepDeleted._tag, "OrchestratorDispatchError");
264+
assert.deepEqual((yield* orchestrator.getThreadProjection(first)).thread, deleted.thread);
265+
246266
assert.isNull((yield* orchestrator.getThreadProjection(source)).thread.deletedAt);
247267
}).pipe(Effect.provide(layer)),
248268
);

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,22 +3995,24 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
39953995
return;
39963996
}
39973997
const prompt = promptRef.current;
3998+
const records = buildMessageContext({
3999+
terminalContexts: composerTerminalContexts,
4000+
reviewComments: composerReviewComments,
4001+
previewAnnotations: composerPreviewAnnotations,
4002+
})?.records;
39984003
if (
39994004
applyPromptReplacement(0, prompt.length, "", {
40004005
expectedText: prompt,
40014006
focusEditorAfterReplace: false,
40024007
})
4003-
)
4004-
onSideChat(
4005-
parseSideChatPrompt(
4006-
prompt,
4007-
buildMessageContext({
4008-
terminalContexts: composerTerminalContexts,
4009-
reviewComments: composerReviewComments,
4010-
previewAnnotations: composerPreviewAnnotations,
4011-
})?.records,
4012-
) ?? side,
4013-
);
4008+
) {
4009+
clearComposerDraftTerminalContexts(composerDraftTarget);
4010+
for (const comment of composerReviewComments)
4011+
removeComposerDraftReviewComment(composerDraftTarget, comment.id);
4012+
for (const annotation of composerPreviewAnnotations)
4013+
removeComposerDraftPreviewAnnotation(composerDraftTarget, annotation.id);
4014+
onSideChat(parseSideChatPrompt(prompt, records) ?? side);
4015+
}
40144016
return;
40154017
}
40164018
// A send while a pasted image is still compressing would strand that image:

‎apps/web/src/components/chat/ChatHeader.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export const ChatHeader = memo(function ChatHeader({
272272
ref={breadcrumbContainerRef}
273273
className={cn(
274274
"flex min-w-0 flex-1 items-center gap-2 sm:gap-3",
275-
rightPanelOpen ? "pr-0" : "pr-24",
275+
rightPanelOpen ? "pr-10" : "pr-24",
276276
)}
277277
onContextMenu={handleHeaderContextMenu}
278278
>

0 commit comments

Comments
 (0)