feat(phrocs): make r restart crashed procs too#59209
Merged
Merged
Conversation
Pressing `r` on a crashed proc now starts it back up, in addition to restarting a running one — same user intent of "rerun this thing", just with no live process to stop first. The binding gates on running || StatusCrashed so clean exits and manual stops are left alone. Generated-By: PostHog Code Task-Id: cb29ca97-345f-4b3d-b485-2ca9ef89b576
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
tools/phrocs/internal/tui/restart_failed_test.go:313-338
**Missing `t.Cleanup` leaves subprocess leaked on timeout**
`p.Start` succeeds and a `sleep 30` process is forked, but there's no `t.Cleanup(func() { p.Stop() })` registered before the spin-loop. If `t.Fatal("sleeper never started")` fires, the subprocess is never reaped. Compare with `TestUpdateProcKeys_RestartEnabledWhileRunning` which correctly adds `t.Cleanup` immediately after the successful `Start` call.
### Issue 2 of 2
tools/phrocs/internal/tui/restart_failed_test.go:224-338
**Binding-gating tests should be a single table-driven test**
The five `TestUpdateProcKeys_Restart*` functions all follow the same pattern — set up proc state, call `m.updateProcKeys()`, assert `Restart.Enabled()`. Per the team's simplicity rules ("OnceAndOnlyOnce") and the explicit preference for parameterised tests, these should be collapsed into one table-driven test with a per-case setup func. At minimum `TestUpdateProcKeys_RestartEnabledAfterCrash` and `TestUpdateProcKeys_RestartDisabledAfterCleanExit` are identical modulo the shell command and expected boolean, and can be merged immediately.
Reviews (1): Last reviewed commit: "feat(phrocs): make `r` restart crashed p..." | Re-trigger Greptile |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates phrocs’ TUI so the r hotkey (“restart”) also revives crashed processes (in addition to restarting currently-running ones), aligning the keybinding with the user intent of “rerun this proc”.
Changes:
- Enable the
Restartkeybinding when the active proc isrunning || crashed. - Update the
rkey handler to callStartwhen the active proc is crashed (instead of doing nothing). - Add tests covering
Restartbinding gating across proc states and an end-to-end “pressrto revive crashed proc” scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tools/phrocs/internal/tui/keys.go | Enables Restart for crashed procs and starts a crashed proc on r keypress. |
| tools/phrocs/internal/tui/restart_failed_test.go | Adds tests for restart key gating and verifies r restarts a crashed proc. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Snapshot p.Status() once in updateProcKeys so running/crashed are derived from the same observation, avoiding a redundant trip through the proc mutex (Copilot). - Collapse the five TestUpdateProcKeys_Restart* gating tests into one table-driven test (Greptile). - Extract a waitRunning helper that registers t.Cleanup before the spin loop, so a t.Fatal inside the loop can no longer leak a sleep-30 subprocess (Greptile / Copilot). Generated-By: PostHog Code Task-Id: cb29ca97-345f-4b3d-b485-2ca9ef89b576
gantoine
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In phrocs the
rhotkey only worked on running procs — if a proc had crashed,rdid nothing and you had to reach fors(start) instead. Two different keys for the same user intent ("rerun this thing") is friction, especially because the proc-detail view doesn't make it obvious which key applies to which state.Changes
rnow also starts a proc inStatusCrashed, alongside its existing behavior of restarting a running proc. Clean exits (StatusDone), manual stops (StatusStopped), and never-started procs are still left alone — those are the user's chosen end-states andrshouldn't silently undo them.Restartbinding gating so the hotkey is only enabled when there's actually something to do (running || crashed), keeping help-text discoverability honest.How did you test this code?
I'm an agent. I haven't manually exercised the TUI; Go isn't available in this sandbox. The change is covered by automated tests in
tools/phrocs/internal/tui/restart_failed_test.go:TestUpdateProcKeys_Restart{Disabled,Enabled}*— binding-gating across fresh, running, crashed, clean-exit, and manually-stopped states.TestHandleNormalKey_RestartKeyRevivesCrashedProc— end-to-end check that pressingron a crashed proc actually kicks off a newStart, not just that the binding is enabled.Reviewer should run
go test ./tools/phrocs/internal/tui/...to confirm.Publish to changelog?
no
Docs update
No docs changes — the in-app help still reads
r: restart, which fits both cases.🤖 Agent context
Authored by PostHog Code (Claude Opus 4.7). Approach:
updateProcKeysand the keypress dispatch inhandleNormalKey.Restart(which callsStopthenStart) for code symmetry — rejected in favor of a directStartcall since there's no live process to stop and thedbglog is clearer about what's happening.RestartAllFailedtest structure (runUntilStatus,modelWithProcs) for the new tests rather than introducing a new harness.Created with PostHog Code