@devries-cameron20 / t3code Mirror · read-only / commits / 35a172883c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 09:45 UTC

fix(pi): report failed manual compaction as a failed turn (#37526)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 16, 2026 at 08:25 UTC 35a172883ce8c524dee7a359098dbae1a46833df
4 files changed +42 -18
apps/server/src/orchestration-v2/testkit/fixtures/pi_compaction/output.ts
+1 -1
@@ -48,7 +48,7 @@ export function assertPiCompactionOutput(
48 result,
49 transcript,
50 runCount: 6,
51 - runStatuses: ["completed", "completed", "completed", "completed", "completed", "completed"],
51 + runStatuses: ["completed", "failed", "completed", "completed", "completed", "completed"],
52 });
53 const projection = projectionFor(result, transcript.scenario);
54 assertSemanticProjectionIntegrity(projection);
apps/server/src/orchestration-v2/testkit/fixtures/pi_compaction/pi_transcript.ndjson
-2
@@ -51,9 +51,7 @@
51 {"type":"emit_inbound","label":"compaction_end","frame":{"type":"compaction_end","reason":"manual","aborted":false,"willRetry":false,"errorMessage":"Compaction failed: Nothing to compact (session too small)"}}
52 {"type":"emit_inbound","label":"response:compact","frame":{"type":"response","command":"compact","success":false,"error":"Nothing to compact (session too small)"}}
53 {"type":"expect_outbound","label":"get_state","frame":{"type":"get_state","id":"t3-9"}}
54 -{"type":"expect_outbound","label":"get_state","frame":{"type":"get_state","id":"t3-10"}}
54 {"type":"emit_inbound","label":"response:get_state","frame":{"id":"t3-9","type":"response","command":"get_state","success":true,"data":{"model":{"type":"chat","id":"deepseek/deepseek-v4-flash","name":"DeepSeek: DeepSeek V4 Flash 0423","api":"openai-completions","baseUrl":"https://openrouter.ai/api/v1","provider":"openrouter","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":null,"medium":null,"high":"high","xhigh":"xhigh","max":null},"input":["text"],"cost":{"input":0.04186,"output":0.08372,"cacheRead":0.008372,"cacheWrite":0},"contextWindow":1048576,"maxTokens":131072,"compat":{"supportsDeveloperRole":false,"thinkingFormat":"openrouter","supportsStrictMode":true,"sendSessionAffinityHeaders":true,"requiresReasoningContentOnAssistantMessages":true}},"thinkingLevel":"high","isStreaming":false,"isCompacting":false,"steeringMode":"one-at-a-time","followUpMode":"one-at-a-time","sessionFile":"/pi-sessions/session-1.jsonl","sessionId":"00000000-0000-4000-8000-000000000002","sessionName":"Replay fixture: pi_compaction","autoCompactionEnabled":true,"messageCount":3,"pendingMessageCount":0}}}
56 -{"type":"emit_inbound","label":"response:get_state","frame":{"id":"t3-10","type":"response","command":"get_state","success":true,"data":{"model":{"type":"chat","id":"deepseek/deepseek-v4-flash","name":"DeepSeek: DeepSeek V4 Flash 0423","api":"openai-completions","baseUrl":"https://openrouter.ai/api/v1","provider":"openrouter","reasoning":true,"thinkingLevelMap":{"off":"none","minimal":null,"low":null,"medium":null,"high":"high","xhigh":"xhigh","max":null},"input":["text"],"cost":{"input":0.04186,"output":0.08372,"cacheRead":0.008372,"cacheWrite":0},"contextWindow":1048576,"maxTokens":131072,"compat":{"supportsDeveloperRole":false,"thinkingFormat":"openrouter","supportsStrictMode":true,"sendSessionAffinityHeaders":true,"requiresReasoningContentOnAssistantMessages":true}},"thinkingLevel":"high","isStreaming":false,"isCompacting":false,"steeringMode":"one-at-a-time","followUpMode":"one-at-a-time","sessionFile":"/pi-sessions/session-1.jsonl","sessionId":"00000000-0000-4000-8000-000000000002","sessionName":"Replay fixture: pi_compaction","autoCompactionEnabled":true,"messageCount":3,"pendingMessageCount":0}}}
55 {"type":"expect_outbound","label":"get_entries","frame":{"type":"get_entries","since":"9923aaa9","id":"t3-11"}}
56 {"type":"emit_inbound","label":"response:get_entries","frame":{"id":"t3-11","type":"response","command":"get_entries","success":true,"data":{"entries":[],"leafId":"9923aaa9"}}}
57 {"type":"expect_outbound","label":"get_session_stats","frame":{"type":"get_session_stats","id":"t3-12"}}
packages/provider-pi/src/server/adapter.test.ts
+36 -11
@@ -4479,7 +4479,27 @@ describe("PiAdapterV2", () => {
4479 }).pipe(Effect.scoped, Effect.provide(layerTest)),
4480 );
4481
4482 - it.effect("fails a compact that never started", () =>
4482 + // A failed compact can respond before starting or after compaction_start/end.
4483 + it.effect.each([
4484 + {
4485 + name: "fails a compact Pi rejects before starting",
4486 + compactionEnd: null,
4487 + error: "Nothing to compact (session too small)",
4488 + status: "failed",
4489 + },
4490 + {
4491 + name: "fails a compact after compaction starts",
4492 + compactionEnd: { aborted: false, errorMessage: "Compaction failed: model request failed" },
4493 + error: "model request failed",
4494 + status: "failed",
4495 + },
4496 + {
4497 + name: "completes a compact an extension cancelled",
4498 + compactionEnd: { aborted: true },
4499 + error: "Compaction cancelled",
4500 + status: "completed",
4501 + },
4502 + ])("$name", ({ compactionEnd, error, status }) =>
4503 Effect.gen(function* () {
4504 const fake = yield* makeFakePi;
4505 const { runtime, takeEvent } = yield* openRuntime(fake);
@@ -4490,17 +4510,22 @@ describe("PiAdapterV2", () => {
4510 });
4511 yield* startTurn(runtime, providerThread, "default", [], "/compact");
4512 yield* fake.takeRequest("compact");
4493 - yield* fake.emit({
4494 - type: "response",
4495 - command: "compact",
4496 - success: false,
4497 - error: "Nothing to compact (session too small)",
4498 - });
4513 + if (compactionEnd !== null) {
4514 + yield* fake.emit({ type: "compaction_start", reason: "manual" });
4515 + yield* fake.emit({
4516 + type: "compaction_end",
4517 + reason: "manual",
4518 + result: null,
4519 + ...compactionEnd,
4520 + });
4521 + }
4522 + yield* fake.emit({ type: "response", command: "compact", success: false, error });
4523 const terminal = yield* takeEvent((event) => event.type === "turn.terminal");
4500 - assert.isTrue(
4501 - terminal.type === "turn.terminal" &&
4502 - terminal.status === "failed" &&
4503 - terminal.failure.message === "Nothing to compact (session too small)",
4524 + assert.deepEqual(
4525 + terminal.type === "turn.terminal"
4526 + ? { status: terminal.status, failure: terminal.failure?.message }
4527 + : null,
4528 + { status, failure: status === "failed" ? error : undefined },
4529 );
4530 }).pipe(Effect.scoped, Effect.provide(layerTest)),
4531 );
packages/provider-pi/src/server/adapter.ts
+5 -4
@@ -378,7 +378,8 @@ interface ActivePiTurn {
378 settleProbeGeneration: number;
379 /** An extension may start compaction immediately after Pi emits agent_settled. */
380 settleWhenIdle: boolean;
381 - sawCompaction: boolean;
381 + /** Pi fails a cancelled compact's response too; that is a stop, not a turn failure. */
382 + compactionCancelled: boolean;
383 manualCompactInFlight: boolean;
384 activeCompaction: PiCompactionState | null;
385 activeProviderRetry: PiProviderRetryState | null;
@@ -2314,7 +2315,6 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
2315 case "compaction_start": {
2316 if (turn === null) return;
2317 turn.settleProbeGeneration += 1;
2317 - turn.sawCompaction = true;
2318 if (turn.activeCompaction !== null) {
2319 yield* emitCompaction(turn, turn.activeCompaction, "cancelled");
2320 }
@@ -2335,6 +2335,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
2335 startedAt: observedAt,
2336 };
2337 turn.activeCompaction = null;
2338 + turn.compactionCancelled = event["aborted"] === true;
2339 const result = event["result"];
2340 if (result === null || result === undefined) {
2341 if (event["aborted"] === true) {
@@ -2514,7 +2515,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
2515 }
2516 return;
2517 }
2517 - if (!compactTurn.sawCompaction) {
2518 + if (!compactTurn.compactionCancelled) {
2519 compactTurn.failure = makeProviderFailure({
2520 message: recordString(event, "error") ?? "Pi compact failed.",
2521 class: "provider_error",
@@ -3333,7 +3334,7 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* (
3334 lastLiveUsedTokens: null,
3335 settleProbeGeneration: 0,
3336 settleWhenIdle: false,
3336 - sawCompaction: false,
3337 + compactionCancelled: false,
3338 manualCompactInFlight: compactCommand !== null,
3339 activeCompaction: null,
3340 activeProviderRetry: null,