#5467: Fix: make embedded compaction wait abortable
docs
agents
## Problem
When an embedded Pi run is aborted (timeout or an explicit stop), we still await `waitForCompactionRetry()`. If the underlying session never emits the expected compaction/lifecycle events, this await can hang indefinitely.
In long-running gateways, that means the teardown path may never run, potentially leaving the session transcript write lock behind and blocking the per-session command lane (e.g. a Discord channel session stops replying).
## Change
Wrap the compaction wait with the same abort controller used for the run, so abort/timeout interrupts the wait and teardown proceeds (unsubscribe, clear active run, release session file lock).
## Testing
- pnpm vitest run --config vitest.unit.config.ts src/agents/pi-embedded-runner/run/attempt.test.ts
- pnpm build
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR makes the post-run compaction wait abortable in the embedded Pi runner. Specifically, the existing `waitForCompactionRetry()` await is now wrapped in the same `runAbortController`-based `abortable(...)` helper used for prompt execution, so an explicit abort/timeout interrupts the compaction wait and allows the teardown path to continue (unsubscribe, clear active run, release session write lock).
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- The change is a single-line behavioral fix that uses an existing, local abort wrapper (`abortable`) already exercised by the prompt code path; it reduces hang risk in teardown and doesn’t alter core session logic beyond making the compaction wait interruptible.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#17445: fix(pi-embedded): add aggregate timeout to compaction retry + harde...
by joeykrug · 2026-02-15
85.5%
#6268: fix: add timeout to compaction retry to prevent session lockout
by batumilove · 2026-02-01
83.4%
#6143: fix(agents): handle AbortError from activeSession.abort() on timeout
by Glucksberg · 2026-02-01
80.6%
#5593: fix(pi-embedded-runner): force-clear stuck embedded runs after timeout
by grassX1998 · 2026-01-31
78.5%
#21115: fix(agent): immediately abort active run on stop/abort message during…
by anillBhoi · 2026-02-19
78.4%
#4042: agents: add proactive compaction before request
by freedomzt · 2026-01-29
77.4%
#17721: fix: abort child run on subagent timeout + retry with backoff + sta...
by IrriVisionTechnologies · 2026-02-16
77.2%
#16915: fix: await compaction hooks with timeout to prevent cross-session d...
by maximalmargin · 2026-02-15
75.9%
#11999: fix: add session-growth guard to prevent unbounded session store gr...
by reverendrewind · 2026-02-08
75.7%
#9620: fix: increase auto-compaction reserve buffer to 40k tokens
by Arlo83963 · 2026-02-05
75.6%