Skip to content

fix: resume built-in Pi sessions#1197

Open
vilmos-brainco wants to merge 1 commit into
asheshgoplani:mainfrom
vilmos-brainco:pi-builtin-resume
Open

fix: resume built-in Pi sessions#1197
vilmos-brainco wants to merge 1 commit into
asheshgoplani:mainfrom
vilmos-brainco:pi-builtin-resume

Conversation

@vilmos-brainco
Copy link
Copy Markdown

@vilmos-brainco vilmos-brainco commented May 26, 2026

Summary

  • launch built-in Pi sessions with an Agent Deck instance-scoped Pi session directory
  • add --continue --session-dir ~/.pi/agent-deck/<instance-id> so Pi restarts resume the same Agent Deck session without cwd-level collisions
  • allow Pi sessions to restart and cover command generation with unit tests

Verification

  • go test ./internal/session -run 'TestBuildPiCommand|TestCanRestartPi' -count=1
  • make build VERSION=1.9.36-pi-resume-pr
  • end-to-end smoke test with a fake pi binary through a real tmux session, verifying AGENTDECK_INSTANCE_ID and --continue --session-dir ~/.pi/agent-deck/<instance-id>

Summary by CodeRabbit

  • New Features

    • Added support for Pi tool sessions with per-instance session directories and improved restart handling.
    • Sessions using the Pi tool can be restarted when in waiting status.
  • Tests

    • Added tests covering Pi session command construction, quoting of instance identifiers, and restart behavior.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b1642c15-4ebb-4d5f-bd59-15a63388ffeb

📥 Commits

Reviewing files that changed from the base of the PR and between 6e720ed and 9fa34a9.

📒 Files selected for processing (2)
  • internal/session/command_override_test.go
  • internal/session/instance.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/session/command_override_test.go
  • internal/session/instance.go

📝 Walkthrough

Walkthrough

Adds a buildPiCommand helper that creates a per-instance ${HOME}/.pi/agent-deck/ session directory, exports AGENTDECK_INSTANCE_ID, and launches pi with --continue --session-dir. Start, StartWithMessage, and Restart fallback route pi tool invocations through the builder; CanRestart now returns true for waiting pi instances. Tests assert command construction, quoting, passthrough for non-pi tools, and restart eligibility.

Changes

Pi Tool Session Lifecycle Integration

Layer / File(s) Summary
Pi command builder implementation
internal/session/instance.go
Adds (*Instance).buildPiCommand that constructs a shell invocation which defines session_dir=${HOME}/.pi/agent-deck/<instance-id>, runs mkdir -p "$session_dir", sets AGENTDECK_INSTANCE_ID=<instance-id>, and calls pi --continue --session-dir "$session_dir".
Session lifecycle dispatch for Pi
internal/session/instance.go
Start, StartWithMessage, and Restart fallback paths route i.Tool == "pi" to i.buildPiCommand(i.Command); CanRestart() is extended to return true for pi instances in StatusWaiting.
Pi command and restart behavior tests
internal/session/command_override_test.go
Adds tests verifying instance-scoped session directory usage, shell-escaping of instance-id path components, passthrough behavior for non-pi tools, and that CanRestart() returns true for waiting pi instances.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 70.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test_coverage_per_surface ⚠️ Warning Pi resume feature only has backend unit tests; lacks tests validating restart through TUI, Web, CLI, and remote surfaces where users actually trigger restart. Add integration tests covering Pi session restart across all applicable surfaces: TUI (hotkey), Web (restart button), CLI (agent-deck restart), and remote invocation.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: resume built-in Pi sessions' follows Conventional Commits format with a 'fix:' prefix and clearly describes the main change of enabling Pi session resumption.
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.
Remote_parity ✅ Passed PR modifies only internal/session/ files, not internal/ui/ or cmd/agent-deck/. The remote_parity check only applies to TUI changes, which don't apply here.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@asheshgoplani
Copy link
Copy Markdown
Owner

Thanks @vilmos-brainco — clean addition. Instance-scoped Pi session dirs (--continue --session-dir ~/.pi/agent-deck/<instance-id>) is the right way to let Pi restarts resume without cwd-level collisions, and you covered command generation + restart with unit tests. Verified locally: internal/session Pi tests pass, golangci clean. First-time contributor, so CI needs a maintainer approve-workflows click before auto-run, then it can merge.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/session/command_override_test.go (1)

194-196: ⚡ Quick win

Tighten quote assertion to validate the exact quoted path.

This assertion can pass even if the command quotes the wrong directory. Assert the full expected --session-dir '<full-path>' (and ideally mkdir -p '<full-path>') to make the regression test strict.

Proposed test hardening
-	if !strings.Contains(got, "--session-dir '") {
-		t.Errorf("buildPiCommand() should shell-quote session dir with spaces, got %q", got)
-	}
+	wantSessionDir := tmpDir + "/.pi/agent-deck/test-instance-id"
+	if !strings.Contains(got, "--session-dir '"+wantSessionDir+"'") {
+		t.Errorf("buildPiCommand() should include quoted session dir %q, got %q", wantSessionDir, got)
+	}
+	if !strings.Contains(got, "mkdir -p '"+wantSessionDir+"'") {
+		t.Errorf("buildPiCommand() should include quoted mkdir path %q, got %q", wantSessionDir, got)
+	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/session/command_override_test.go` around lines 194 - 196, Tighten
the test by asserting the exact quoted path instead of a substring: build the
expected strings using the test's sessionDir variable and require that got
contains "--session-dir '<sessionDir>'" (including single quotes) and also
contains "mkdir -p '<sessionDir>'" to ensure the command quotes the correct
directory and creates it; update the assertions in the buildPiCommand() test to
check these full expected substrings rather than just "--session-dir '".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/session/instance.go`:
- Around line 1340-1354: The code currently resolves the host's user home with
os.UserHomeDir and bakes an absolute path into the command; change
buildPiCommand (the code that constructs sessionDir/quotedSessionDir and returns
the mkdir+command string) to use the target-side $HOME literal instead of
resolving the host home: build sessionDir from the literal "$HOME" (e.g.
filepath.Join("$HOME", ".pi", "agent-deck", i.ID)) and then shell-quote that
string and i.ID as before so the generated command uses $HOME on the
remote/target runtime and preserves Local/Remote parity.

---

Nitpick comments:
In `@internal/session/command_override_test.go`:
- Around line 194-196: Tighten the test by asserting the exact quoted path
instead of a substring: build the expected strings using the test's sessionDir
variable and require that got contains "--session-dir '<sessionDir>'" (including
single quotes) and also contains "mkdir -p '<sessionDir>'" to ensure the command
quotes the correct directory and creates it; update the assertions in the
buildPiCommand() test to check these full expected substrings rather than just
"--session-dir '".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 15b181f5-b29c-4adf-9b59-57d955ce358d

📥 Commits

Reviewing files that changed from the base of the PR and between d534fe7 and 6e720ed.

📒 Files selected for processing (2)
  • internal/session/command_override_test.go
  • internal/session/instance.go

Comment thread internal/session/instance.go Outdated
@vilmos-brainco vilmos-brainco changed the title Resume built-in Pi sessions fix: resume built-in Pi sessions May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants