feat(agents): pi session resume support
Summary
pi is a recognized TuiAgent with first-class status-extension wiring (main + SSH relay), but it was missing from RESUMABLE_TUI_AGENTS — so pi panes could not survive worktree sleep, app quit-restore, or agent hibernation: the pane came back dead and the conversation was lost.
This PR adds pi to the resumable set, following the nine existing agent precedents:
- The generated pi status extension captures the current session via
ctx.sessionManager.getSessionId()/getSessionFile()onsession_startand carriessession_id+session_fileon subsequent hook posts. - The pi hook path ingests them into
AgentStatusEntry.providerSession, gated on a persisted session file — ephemeral--no-sessionruns are deliberately not resumable. RESUMABLE_TUI_AGENTSgains'pi'; resume argv is['pi', '--session', <session-file path>]. The path form is cwd-independent and always non-interactive (a bare id can hit pi's interactive cross-project fork prompt).session_fileis threaded astranscriptPath, mirroring the Claude/Codextranscript_pathconvention.
User-visible: pi workers now hibernate and revive with conversation context intact.
Screenshots
No visual change.
Testing
- [x]
pnpm lint— passed (41 reliability gates, localization parity checks) - [x]
pnpm typecheck— all three tsconfigs, exit 0 - [x]
pnpm test— honest accounting: on our macOS test box the full suite shows load-induced flaky failures in unrelated renderer suites both on this branch and on clean baseef87461bf(different failure sets per run, 15–20s timeouts under load). The one deterministic failure actually caused by this PR —workspace-session-schema.sleeping-agent.test.tsusedagent: 'pi'as its malformed-record sentinel, which this PR made valid — is fixed here by switching the fixture to a genuinely non-resumable sentinel. All PR-touched suites plus that schema suite pass deterministically: 170/170. - [x]
pnpm build— full build passed (renderer, native, macOS computer-use targets) - [x] Added/updated tests: extension session-metadata transport, provider-session extraction edges (ephemeral / missing file / empty id), path-form resume argv, listener
session_starthandling, omp payload identity, hibernation-planner gating.
Additionally verified against the real pi binary (0.80.6) with a mock hook server: real runs emit session_id + session_file matching the on-disk session header; --no-session runs omit session_file; and pi --session <absolute session file> resumes with context intact from a different cwd, non-interactively.
AI Review Report
Multi-agent review pipeline (implementer, independent adversarial reviewer, separate cross-platform/security auditor — different models):
- Adversarial review of the initial commit: 0 P1, 2 P2, 4 P3. The P2s (ephemeral sessions falsely marked resumable; bare-id resume argv reaching pi's interactive cross-cwd fork prompt) are fixed in the follow-up commit by gating on and resuming via the persisted session file.
- Cross-platform pass (macOS / Linux / Windows / WSL): the change adds no new platform-specific code. New payload fields ride the existing endpoint-file parser (POSIX
endpoint.envand Windowsendpoint.cmdvariants) and the existing WSLcurl.exefallback verbatim. Resume argv quoting goes through the sharedquoteStartupArg(posix single-quote escaping, PowerShell quote doubling, cmd caret-escaping); a leading-dash or metacharacter-bearing path cannot escape quoting on posix/powershell. SSH remotes resume on the capture host, so no cross-host path translation occurs. - Noted inherited assumption (pre-existing, not introduced here): SSH
connectionIdimplies a posix shell. Native-Windows pi under thecmdshell is an unexercised combination (likely unreachable if pi is WSL-only on Windows).
Security Audit
session_id / session_file arrive over the existing token-authenticated loopback hook channel from the managed pi process (semi-trusted source). session_id passes normalizeSessionId (length cap, leading-dash rejection, control-char rejection); session_file is control-char-checked and is only ever emitted as the quoted value of --session — no shell-injection vector through the changed paths. No new secrets, no new IPC channels; omp (which shares the extension source generator) is scoped out with a payload-identity test.
Two low-severity hardening notes from our audit, disclosed deliberately rather than patched — happy to add either if you prefer:
session_fileis not additionally checked to be absolute, existing, or confined to pi's session root before use as resume argv; bounded by pi's own session-load behavior and the loopback token gate.- Re-hydration from persisted state re-validates the session id but does not re-run the control-char check on the stored transcript path (the capture path does); backstopped by spawn-time quoting.
Notes
- Scope honesty: verified via unit/integration tests, typecheck, full build, and a real-pi-binary hook harness including cross-cwd resume. A full in-app hibernate→revive e2e was not run here (no dev-build environment on this machine); the wiring follows the existing nine-agent precedents exactly, and we're glad to run any additional verification maintainers want.
- pi restores provider/model/thinking from its session file on resume, so the resume argv intentionally passes no model flags.
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] ▶️ Resume reviews
- [ ] 🔍 Trigger review
📝 Walkthrough
Walkthrough
Pi hook generation now captures session_id and session_file for Pi events while keeping OMP payloads unchanged. Pi session-start handling clears cached turn state. Shared session utilities recognize Pi as resumable, extract transcript paths from session_file, and construct Pi resume arguments when metadata is complete. Metadata-only session updates now flow through server, relay, IPC, persistence, and renderer ownership handling. Tests cover hook context forwarding, payload metadata, event normalization, session extraction, incomplete sessions, hibernation planning, and malformed sleeping-agent records.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 16.22% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title is concise and accurately summarizes the main change: pi session resume support. |
| Description check | ✅ Passed | The description follows the required template and includes summary, screenshots, testing, AI review, security audit, and notes. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.