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