Skip to content

fix(cli): attach a reclaim command to each residual resource in mutation recovery - #15949

Closed
yzxcj797 wants to merge 3 commits into
stablyai:mainfrom
yzxcj797:fix/residual-resource-recovery-commands-15944
Closed

yzxcj797 wants to merge 3 commits into
stablyai:mainfrom
yzxcj797:fix/residual-resource-recovery-commands-15944

Conversation

@yzxcj797

Copy link
Copy Markdown
Contributor

What

orchestrationMutationRecoveryError now appends a reclaim command for each residual resource after the --retry-request advice:

  • kind: "terminal" → If terminal <handle> is still residual after the outcome is settled: orca terminal close --terminal <handle> --json.
  • kind: "worktree" → If worktree <id> is still residual after the outcome is settled: orca worktree rm --worktree id:<id> --force --json (verify nothing valuable was written first).

Resources without an id, or of kinds there is no safe blanket advice for, are skipped rather than guessed at.

Why (issue #15944)

The unknown-outcome receipt names what a failed mutation left behind but attaches no action to it: the mutation itself gets the --retry-request recovery command while the residue gets a bare JSON.stringify, and the orchestration guide's instruction ends at "inspect its stage, effects, and residualResources". The commands that would clear the residue exist in the CLI (terminal close since well before v1.4.186; worktree rm) but a coordinator reading the receipt would never learn them — the guide's only mention of terminal close is the prohibition against substituting it for worker-release.

The commands are deliberately placed after the retry advice and phrased conditionally ("if still residual after the outcome is settled"): a replayed mutation may adopt the same resources, so the residue should only be reclaimed once --retry-request (or a deliberate fresh attempt) has settled the outcome. That also keeps the receipt consistent with the guide's release discipline.

Testing

  • New src/cli/orchestration-mutation-recovery.test.ts: terminal + worktree residue map to their exact reclaim lines; id-less / unknown-kind / non-array inputs yield no lines.
  • The existing end-to-end recovery test (orchestration-gate-cli.test.ts) now also asserts the reclaim commands appear in the printed error message, after the --retry-request line.
  • Diff-verified: with only orchestration-mutation-recovery.ts stashed, the extended e2e assertions fail (no reclaim commands in the message); with it applied, both files pass and pnpm run typecheck is clean.

Fixes #15944

…ion recovery

The unknown-outcome receipt named what a failed mutation left behind
with no action for it — the mutation got --retry-request advice, the
residue got nothing, and the orchestration guide ends at "inspect
residualResources". Terminal and worktree residue now carry their
reclaim command, positioned after the retry advice since a retried
mutation may adopt the same resources.

Fixes stablyai#15944
@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The mutation recovery error now appends shell-quoted reclaim commands for residual terminal and worktree resources. The helper ignores non-array residue, unsupported resource kinds, and entries without valid identifiers. Tests cover command generation, filtering, shell quoting, empty inputs, and platform-specific command formatting.

Merge Risk: ⚪ Minimal · up to 01b93

The change adds conditional reclaim guidance for residual resources, with no actionable merge-blocking risk remaining after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. 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 clearly describes the main change: adding reclaim commands for residual resources during mutation recovery.
Description check ✅ Passed The description explains the change, rationale, linked issue, and testing, but omits several template sections that are not critical to review.
Linked Issues check ✅ Passed The PR satisfies issue #15944 by adding conditional reclaim guidance for residual terminals and preserving the existing retry and release discipline.
Out of Scope Changes check ✅ Passed The implementation, quoting logic, and tests remain focused on actionable recovery guidance for residual resources.

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
src/cli/orchestration-mutation-recovery.ts (1)

26-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten the explanatory comments.

Keep only concise, non-obvious context.

  • src/cli/orchestration-mutation-recovery.ts#L26-L34: reduce the nine-line rationale to one brief comment.
  • src/cli/orchestration-mutation-recovery.test.ts#L5-L6: remove or reduce the issue-history comment.
  • src/cli/handlers/orchestration-gate-cli.test.ts#L231-L232: remove or reduce the ordering explanation.

As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5353549d-4cee-4be7-b87b-fbb45abcbb75

📥 Commits

Reviewing files that changed from the base of the PR and between 5651662 and 75c6ff5.

📒 Files selected for processing (3)
  • src/cli/handlers/orchestration-gate-cli.test.ts
  • src/cli/orchestration-mutation-recovery.test.ts
  • src/cli/orchestration-mutation-recovery.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Coderabbit review on stablyai#15949: raw interpolation into a copy-paste command
splits on spaces (worktree ids embed paths) and executes injected shell
syntax. Ids now go through quoteShellToken, which handles both posix
single-quoting and the win32 cmd.exe double-quote form.
@yzxcj797

Copy link
Copy Markdown
Contributor Author

Good catch — pushed: both ids (and the id: worktree selector) now go through the shared quoteShellToken, which single-quotes posix-side (with the '' escape) and double-quotes for cmd.exe on win32. New unit cases pin spaces, ;, and an embedded quote against both platform branches, and the e2e assertions accept the platform-appropriate quoting.

The previous push landed with mangled quote escapes in the test file;
rebuild via quoteShellToken so expectations stay platform-exact.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 36139163-9ae4-4858-868f-b573f0445c44

📥 Commits

Reviewing files that changed from the base of the PR and between 75c6ff5 and cf9a3db.

📒 Files selected for processing (3)
  • src/cli/handlers/orchestration-gate-cli.test.ts
  • src/cli/orchestration-mutation-recovery.test.ts
  • src/cli/orchestration-mutation-recovery.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/cli/orchestration-mutation-recovery.test.ts (2)

27-35: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for blank identifiers.

The test covers a missing id, but not an empty id. Add a case such as { kind: 'terminal', id: '' } and verify that it produces no recovery command. If runtime inputs can contain non-string identifiers, cover those values too.


38-56: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover Windows double-quote escaping and both platform branches.

The input term_ev'il tests the POSIX apostrophe escape. It does not test the Windows escape for an embedded ". The conditional also runs only one branch on each host. Add a double-quote input and either run the test on both POSIX and Windows or make the platform injectable for deterministic unit coverage.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7d763597-79b3-44a3-a53a-5db1631ecaf8

📥 Commits

Reviewing files that changed from the base of the PR and between cf9a3db and 01b9332.

📒 Files selected for processing (1)
  • src/cli/orchestration-mutation-recovery.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@nwparker

nwparker commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Closing this PR because the linked issue (#15944) has already been resolved and closed on main (via #16904). Thank you for the contribution!

@nwparker nwparker closed this Dec 1, 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.

[Other]: Include Dispatch-aware reclaim guidance in failed worker-start receipts

2 participants