feat: auto-retry failed agent sessions

Merged
AU
4mo ago
+3243-47

Summary

  • add an opt-in terminal.autoRetryAgentSessions setting, default off, across Settings, cmux.json, schema/docs, settings search, and the command palette
  • classify managed agent command termination conservatively and resume the same Claude/Codex-compatible binding only for nonzero, non-signal exits
  • coordinate three cancellable retries with 1/2/4-second backoff per workspace, preserving bindings only across hook-proven session teardown and cancelling on idle, manual clears, replacement sessions, or pane close
  • surface retry and exhaustion state in sidebar metadata, localized logs, and an exhaustion notification
  • route Ghostty COMMAND_FINISHED exit codes and managed hook teardown provenance through existing lifecycle and resume infrastructure

Safety

Retry requires an enabled setting, an active managed lifecycle, a valid agent-hook resume binding, and a known nonzero non-signal exit. Unknown exits, normal completion, Ctrl-C/signal-like exits, inactive sessions, missing bindings, ordinary binding clears, and pane teardown all fail closed.

Testing

  • arch -arm64 swift test (CmuxWorkspaces): 173 tests passed
  • arch -arm64 swift test (CmuxControlSocket): 317 tests passed
  • arch -arm64 swift test (CmuxSettingsUI): 128 tests passed
  • ./scripts/check-pbxproj.sh
  • ./scripts/lint-pbxproj-test-wiring.sh
  • python3 scripts/check-workspace-package-groups.py --check
  • python3 scripts/check-package-resolved-policy.py
  • ./tests/test_ci_swift_warning_budget.sh
  • parsed all 33 changed Swift files with swiftc -frontend -parse
  • parsed and audited Localizable.xcstrings plus English/Japanese web catalogs
  • git diff --check

The requested scripts/swift_file_length_budget.py and .github/swift-file-length-budget.tsv are absent from this checkout and current origin/main. I manually compared all touched large Swift files against origin/main; every new Swift file remains below 500 lines, and .github/swift-warning-budget.tsv is untouched.

Per task constraints, I did not run xcodebuild, XCUITests, a reload, or launch the app.

Issue: https://github.com/manaflow-ai/cmux/issues/9014

Closes #9014


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Adds opt‑in auto‑retry for failed managed agent sessions with bounded backoff and launch‑ack safeguards. Retries are tied to the exact shell command generation, survive managed idle teardown and pane transfers, and stop on user input or ambiguous ownership.

  • New Features

    • New setting: terminal.autoRetryAgentSessions (default off) in Settings, cmux.schema.json, settings search, and a Command Palette toggle.
    • Retry policy: up to 3 attempts with 1/2/4s backoff; waits for launch acknowledgment and stops with a log if the resume command can’t be sent; reuses the same managed resume binding; preserves attempts across idle teardown and pane transfers; cancels on manual clears, replacement sessions, pane close, or explicit terminal input; shows pending/exhausted state in the sidebar, localized logs, and a notification.
  • Bug Fixes

    • Bind retries to the authoritative ended shell command generation with event‑driven ordering; fail closed on ambiguous ownership; keep retry state until exit classification through managed teardown.
    • Validate and forward agent_session_ended as a boolean in resume‑clear APIs; reject malformed values with localized errors; include provenance from the CLI and Ghostty COMMAND_FINISHED; don’t mark bindings as ended without a checkpoint; make design‑mode screenshot quarantine recovery deterministic.

Summary by CodeRabbit

  • New Features
    • Added optional automatic retry for failed managed agent sessions using bounded exponential backoff.
    • Added “Retry Failed Agent Sessions” terminal setting with settings UI, search entry, and command-palette toggle.
  • Bug Fixes
    • Improved surface.resume.clear handling to correctly propagate and validate agent_session_ended, including clearing to false when omitted.
    • Malformed agent_session_ended values are now rejected with an invalid_params error and localized messaging.
  • Documentation
    • Added schema and localized UI/help text for terminal.autoRetryAgentSessions.
  • Tests
    • Expanded coverage for retry policy/coordination and resume-clear provenance validation.