Skip to content

Commit 9c503bb

Browse files
committed
fix: skip timeout compaction when run was aborted by user
When the user presses the stop button in the Control UI, the model request times out. Previously, if context token usage exceeded 65%, the timeout compaction mechanism would fire even though the run was intentionally aborted — causing unnecessary compaction at an inappropriate time. Add !aborted check to the timeout compaction condition so that user-initiated stops skip compaction entirely.
1 parent 0793775 commit 9c503bb

2 files changed

Lines changed: 6 additions & 17 deletions

File tree

src/agents/pi-embedded-runner/run.timeout-triggered-compaction.test.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ describe("timeout-triggered compaction", () => {
365365
expect(result.payloads?.[0]?.text).toContain("timed out");
366366
});
367367

368-
it("still attempts compaction for timed-out attempts that set aborted", async () => {
368+
it("skips timeout compaction when run was aborted by user", async () => {
369369
mockedRunEmbeddedAttempt.mockResolvedValueOnce(
370370
makeAttemptResult({
371371
timedOut: true,
@@ -375,20 +375,13 @@ describe("timeout-triggered compaction", () => {
375375
} as never,
376376
}),
377377
);
378-
mockedCompactDirect.mockResolvedValueOnce(
379-
makeCompactionSuccess({
380-
summary: "timeout recovery compaction",
381-
tokensBefore: 180000,
382-
tokensAfter: 90000,
383-
}),
384-
);
385-
mockedRunEmbeddedAttempt.mockResolvedValueOnce(makeAttemptResult({ promptError: null }));
386378

387379
const result = await runEmbeddedPiAgent(overflowBaseRunParams);
388380

389-
expect(mockedCompactDirect).toHaveBeenCalledTimes(1);
390-
expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
391-
expect(result.meta.error).toBeUndefined();
381+
// Timeout compaction should NOT fire for intentionally aborted runs
382+
expect(mockedCompactDirect).not.toHaveBeenCalled();
383+
expect(result.payloads?.[0]?.isError).toBe(true);
384+
expect(result.payloads?.[0]?.text).toContain("timed out");
392385
});
393386

394387
it("does not attempt compaction when timedOutDuringCompaction is true", async () => {
@@ -531,7 +524,6 @@ describe("timeout-triggered compaction", () => {
531524
.mockResolvedValueOnce(
532525
makeAttemptResult({
533526
timedOut: true,
534-
aborted: true,
535527
lastAssistant: {
536528
usage: { input: 150000 },
537529
} as never,
@@ -541,7 +533,6 @@ describe("timeout-triggered compaction", () => {
541533
.mockResolvedValueOnce(
542534
makeAttemptResult({
543535
timedOut: true,
544-
aborted: true,
545536
lastAssistant: {
546537
usage: { input: 150000 },
547538
} as never,
@@ -582,7 +573,6 @@ describe("timeout-triggered compaction", () => {
582573
.mockResolvedValueOnce(
583574
makeAttemptResult({
584575
timedOut: true,
585-
aborted: true,
586576
lastAssistant: {
587577
usage: { input: 150000 },
588578
} as never,
@@ -592,7 +582,6 @@ describe("timeout-triggered compaction", () => {
592582
.mockResolvedValueOnce(
593583
makeAttemptResult({
594584
timedOut: true,
595-
aborted: true,
596585
lastAssistant: {
597586
usage: { input: 150000 },
598587
} as never,

src/agents/pi-embedded-runner/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ export async function runEmbeddedPiAgent(
15571557
// ── Timeout-triggered compaction ──────────────────────────────────
15581558
// When the LLM times out with high context usage, compact before
15591559
// retrying to break the death spiral of repeated timeouts.
1560-
if (timedOut && !timedOutDuringCompaction && !timedOutDuringToolExecution) {
1560+
if (timedOut && !aborted && !timedOutDuringCompaction && !timedOutDuringToolExecution) {
15611561
// Only consider prompt-side tokens here. API totals include output
15621562
// tokens, which can make a long generation look like high context
15631563
// pressure even when the prompt itself was small.

0 commit comments

Comments
 (0)