GeezerVison is showing github.com — fix(server): /compact no longer runs on a session that lacks the thre… · Ryoku-dev/hyakki@ff1ee24
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/ProviderTurnStartService.ts +50Lines changed: 50 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -580,6 +580,10 @@ export const layer: Layer.Layer< | 580 | 580 | readonly itemProviderThreadId: OrchestrationV2ProviderThread["id"] | null; | 581 | 581 | readonly item: | 582 | 582 | | Pick<Extract<OrchestrationV2TurnItem, { type: "error" }>, "type" | "title" | "failure"> | | 583 | + | Pick< | | 584 | + Extract<OrchestrationV2TurnItem, { type: "compaction" }>, | | 585 | + "type" | "title" | "driver" | "summary" | | 586 | + > | 583 | 587 | | Pick< | 584 | 588 | Extract<OrchestrationV2TurnItem, { type: "command_execution" }>, | 585 | 589 | "type" | "title" | "input" | "output" | "exitCode" | @@ -1185,6 +1189,52 @@ export const layer: Layer.Layer< | 1185 | 1189 | } | 1186 | 1190 | const session = sessionResult.success; | 1187 | 1191 | if (!(yield* isCurrentAttemptInStatus("starting"))) return; | | 1192 | + // A compaction carries no inline history, so with a full summary still pending the native | | 1193 | + // session holds none of the conversation: compacting it would summarize nothing. | | 1194 | + if ( | | 1195 | + session.injectHistory === undefined && | | 1196 | + providerMessage.attachments.length === 0 && | | 1197 | + providerMessage.text.trim().toLowerCase() === "/compact" && | | 1198 | + handoffs.some( | | 1199 | + (handoff) => | | 1200 | + handoff.strategy === "full_thread_summary" && | | 1201 | + (providerThread.nativeThreadRef === null || | | 1202 | + handoff.delivery?.nativeThreadId !== providerThread.nativeThreadRef.nativeId || | | 1203 | + handoff.delivery.status === "pending"), | | 1204 | + ) | | 1205 | + ) { | | 1206 | + const now = yield* DateTime.now; | | 1207 | + yield* settleRunBeforeStart({ | | 1208 | + run, | | 1209 | + rootNode, | | 1210 | + attempt, | | 1211 | + turnItems: projection.turnItems, | | 1212 | + signal: "empty-compaction", | | 1213 | + status: "failed", | | 1214 | + now, | | 1215 | + startedAt: now, | | 1216 | + providerInstanceId: run.providerInstanceId, | | 1217 | + itemProviderThreadId: providerThread.id, | | 1218 | + item: { | | 1219 | + type: "compaction", | | 1220 | + title: "Nothing to compact yet", | | 1221 | + driver: session.driver, | | 1222 | + summary: | | 1223 | + "This thread's earlier conversation reaches the agent with your next message. Send a message before compacting.", | | 1224 | + }, | | 1225 | + providerThreadUpdate: { | | 1226 | + ...providerThread, | | 1227 | + status: | | 1228 | + providerThread.status === "error" | | 1229 | + ? "error" | | 1230 | + : providerThread.nativeThreadRef === null | | 1231 | + ? "not_loaded" | | 1232 | + : "idle", | | 1233 | + updatedAt: now, | | 1234 | + }, | | 1235 | + }); | | 1236 | + return; | | 1237 | + } | 1188 | 1238 | const cutTurn = unsettledStoppedProviderTurn( | 1189 | 1239 | { runs: projection.runs, providerTurns }, | 1190 | 1240 | run, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts +129-1Lines changed: 129 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1033,7 +1033,11 @@ describe("orchestration v2 provider switching", () => { | 1033 | 1033 | } | 1034 | 1034 | return; | 1035 | 1035 | } | 1036 | | - assert.equal(projection.runs.at(-1)?.status, "completed"); | | 1036 | + // A session that cannot take injected history has nothing native to compact yet. | | 1037 | + assert.equal( | | 1038 | + projection.runs.at(-1)?.status, | | 1039 | + scenario === "compact-legacy" ? "failed" : "completed", | | 1040 | + ); | 1037 | 1041 | if (exhaustedTarget) { | 1038 | 1042 | assert.equal(yield* Ref.get(generation), 2); | 1039 | 1043 | const turns = (yield* Ref.get(capturedTurns)).filter( | @@ -6679,6 +6683,130 @@ describe("orchestration v2 provider switching", () => { | 6679 | 6683 | }), | 6680 | 6684 | ); | 6681 | 6685 |
| | 6686 | + // regression: #44279 a portable fork's first /compact reached a fresh native session without the fork's history. | | 6687 | + it.live( | | 6688 | + "compacts a portable fork's first turn only after its session has the inherited history", | | 6689 | + () => | | 6690 | + Effect.gen(function* () { | | 6691 | + const cwd = yield* checkpointWorkspace("fork-first-compact"); | | 6692 | + const capturedTurns = yield* Ref.make<ReadonlyArray<CapturedTurn>>([]); | | 6693 | + const layerRegistry = ProviderAdapterRegistry.layerFromAdapters([ | | 6694 | + makeTestAdapter({ | | 6695 | + instanceId: CODEX_MODEL_SELECTION.instanceId, | | 6696 | + driver: CODEX_DRIVER, | | 6697 | + capabilities: CodexProviderCapabilitiesV2, | | 6698 | + modelSelection: CODEX_MODEL_SELECTION, | | 6699 | + responseByRunOrdinal: { 1: "The release marker is violet." }, | | 6700 | + capturedTurns, | | 6701 | + }), | | 6702 | + // No injectHistory, like Antigravity: the history can only reach the session in a prompt. | | 6703 | + makeTestAdapter({ | | 6704 | + instanceId: CLAUDE_MODEL_SELECTION.instanceId, | | 6705 | + driver: CLAUDE_DRIVER, | | 6706 | + capabilities: ClaudeProviderCapabilitiesV2, | | 6707 | + modelSelection: CLAUDE_MODEL_SELECTION, | | 6708 | + responseByRunOrdinal: {}, | | 6709 | + capturedTurns, | | 6710 | + }), | | 6711 | + ]); | | 6712 | + const sourceThreadId = ThreadId.make("thread:fork-first-compact:source"); | | 6713 | + const forkThreadId = ThreadId.make("thread:fork-first-compact:fork"); | | 6714 | + yield* Effect.gen(function* () { | | 6715 | + const orchestrator = yield* Orchestrator.OrchestratorV2; | | 6716 | + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; | | 6717 | + const send = ( | | 6718 | + threadId: ThreadId, | | 6719 | + name: string, | | 6720 | + text: string, | | 6721 | + modelSelection: ModelSelection, | | 6722 | + ) => | | 6723 | + orchestrator.dispatch({ | | 6724 | + type: "message.dispatch", | | 6725 | + createdBy: "user", | | 6726 | + creationSource: "web", | | 6727 | + commandId: CommandId.make(`command:fork-first-compact:${name}`), | | 6728 | + threadId, | | 6729 | + messageId: MessageId.make(`message:fork-first-compact:${name}`), | | 6730 | + text, | | 6731 | + attachments: [], | | 6732 | + modelSelection, | | 6733 | + dispatchMode: { type: "start_immediately" }, | | 6734 | + }); | | 6735 | + const settle = (threadId: ThreadId) => | | 6736 | + worker.drain().pipe( | | 6737 | + Effect.andThen(waitForIdle(threadId)), | | 6738 | + Effect.tap(() => worker.drain()), | | 6739 | + ); | | 6740 | + yield* orchestrator.dispatch({ | | 6741 | + type: "thread.create", | | 6742 | + createdBy: "user", | | 6743 | + creationSource: "web", | | 6744 | + commandId: CommandId.make("command:fork-first-compact:create"), | | 6745 | + threadId: sourceThreadId, | | 6746 | + projectId, | | 6747 | + title: "Fork first compact", | | 6748 | + modelSelection: CODEX_MODEL_SELECTION, | | 6749 | + runtimeMode: "full-access", | | 6750 | + interactionMode: "default", | | 6751 | + branch: null, | | 6752 | + worktreePath: null, | | 6753 | + }); | | 6754 | + yield* send(sourceThreadId, "source", "Prompt source", CODEX_MODEL_SELECTION); | | 6755 | + const source = yield* settle(sourceThreadId); | | 6756 | + yield* orchestrator.dispatch({ | | 6757 | + type: "thread.fork", | | 6758 | + createdBy: "user", | | 6759 | + creationSource: "web", | | 6760 | + commandId: CommandId.make("command:fork-first-compact:fork"), | | 6761 | + sourceThreadId, | | 6762 | + targetThreadId: forkThreadId, | | 6763 | + sourcePoint: { type: "run", runId: source.runs[0]!.id }, | | 6764 | + title: "Fork", | | 6765 | + }); | | 6766 | + yield* send(forkThreadId, "compact", "/compact", CLAUDE_MODEL_SELECTION); | | 6767 | + const compacted = yield* settle(forkThreadId); | | 6768 | + const forkTurns = () => | | 6769 | + Ref.get(capturedTurns).pipe( | | 6770 | + Effect.map((turns) => turns.filter((turn) => turn.threadId === forkThreadId)), | | 6771 | + ); | | 6772 | + // Compacting the fork's empty native session would summarize nothing. | | 6773 | + assert.isEmpty(yield* forkTurns()); | | 6774 | + assert.equal(compacted.runs.at(-1)?.status, "failed"); | | 6775 | + // Shown as a failed compaction, like a provider's own, not as a thread error. | | 6776 | + assert.isTrue( | | 6777 | + compacted.turnItems.some( | | 6778 | + (item) => item.type === "compaction" && item.status === "failed", | | 6779 | + ), | | 6780 | + ); | | 6781 | + assert.isFalse(compacted.turnItems.some((item) => item.type === "error")); | | 6782 | + | | 6783 | + yield* send(forkThreadId, "next", "Continue", CLAUDE_MODEL_SELECTION); | | 6784 | + yield* settle(forkThreadId); | | 6785 | + const [next] = yield* forkTurns(); | | 6786 | + assert.include(next!.text, "Prompt source"); | | 6787 | + assert.include(next!.text, "release marker is violet"); | | 6788 | + }).pipe( | | 6789 | + Effect.provide( | | 6790 | + ProviderReplayHarness.layerWithRegistry( | | 6791 | + { | | 6792 | + name: "fork-first-compact", | | 6793 | + runtimePolicyOverride: { | | 6794 | + cwd, | | 6795 | + approvalPolicy: "never", | | 6796 | + sandboxPolicy: { | | 6797 | + type: "readOnly", | | 6798 | + access: { type: "fullAccess" }, | | 6799 | + networkAccess: false, | | 6800 | + }, | | 6801 | + }, | | 6802 | + }, | | 6803 | + layerRegistry, | | 6804 | + ), | | 6805 | + ), | | 6806 | + ); | | 6807 | + }), | | 6808 | + ); | | 6809 | + | 6682 | 6810 | it.effect.each([ | 6683 | 6811 | "same-provider-retry", | 6684 | 6812 | "cancelled-dropped", | |
|