fix: keep unknown agent liveness unknown on session restore

Merged
TE
3d ago
+6-13

Main has failed these since the Computer Use merge (#13055), on main run 36106360658 and every full PR run since:

  • SessionPersistenceTests/testRestoredAntigravityAgentAutoResumeUsesConversationCommand, testRestoredAgentAutoResumeClearsSnapshotWhenShellReturnsToPrompt
  • AgentSessionAutoResumeSettingsTests/testDisabledAutoResumeDoesNotInjectStartupInputOnRestore, testUnknownAgentShellStatePreservesLegacyAutoResumeBehavior
  • AgentSessionAutoResumeSwiftTests/splitAfterSecondRestoreOfClobberedRestorableAgentPaneUsesAgentCwd
  • VaultQueuedRestoreIdentityTests/mismatchedExitedLivenessCannotStopRunningRestore

Cause. In Workspace.swift, agentWasRunning is a Bool?, and nil means "unknown": the shell's activity state and the caller's default (agentWasRunning ?? true) decide. The merge replaced (matchingObservation?.processLiveness ?? .unknown).wasRunning(...) with guard let matchingObservation else { return false } and a trailing ?? false. A restored panel with no process observation, or with liveness the evidence cannot decide, became "the agent was not running", so restores stopped resuming agents and snapshots dropped their agent.

Fix. The non-hook liveness block goes back to the single pre-merge expression, (matchingObservation?.processLiveness ?? .unknown).wasRunning(...), so unknown stays nil in every case, including a non-hook resume binding with a matching observation, which wasRunningForSnapshot also turned into false. The guard and binding branch came from the branch's conflict-resolution merge fdbcb3c0dd2, not from a deliberate change, and none of #13055's own tests depend on them. The hook-binding path above is unchanged.

🤖 Generated with Claude Code


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

The Computer Use merge (#13055) treated a restored agent with no process observation, or with liveness the evidence cannot decide, as if it had never been running, so restores stopped resuming agents and dropped agents from snapshots. This restores pre-merge behavior where unknown liveness stays unknown and the shell's activity state and the caller's default (agentWasRunning ?? true) decide.

Bug Fixes

  • Both liveness cases now go through the single pre-merge expression (matchingObservation?.processLiveness ?? .unknown).wasRunning(...); the hook-binding path is unchanged.
  • The fix is reapplied after main's change that computes confirmedRuntimeProcessIdentities following the Codex restore-intent check.
  • Fixes SessionPersistenceTests, AgentSessionAutoResumeSettingsTests, AgentSessionAutoResumeSwiftTests, and VaultQueuedRestoreIdentityTests.

Summary by CodeRabbit

  • Bug Fixes
    • Improved auto-resume decisions for restored terminal panels with an agent. When process status is unavailable or no matching process observation exists, the app no longer automatically treats the agent as stopped. Instead, shell activity and the existing default behavior can help determine whether the agent should resume, while available process status continues to inform the decision.