fix(desktop): auto-restart setup-mode agents when an edit satisfies readiness

A harness spawned with BUZZ_ACP_SETUP_PAYLOAD runs as a nudge-only setup
listener and never re-evaluates its config — readiness is only computed at
spawn. Fixing the missing model/provider in Edit Agent therefore changed
nothing: the stale setup-mode process stayed connected to the relay and kept
replying "needs configuration" to every mention, with no hint that a restart
was required.

Stamp was-spawned-in-setup-mode on the in-memory ManagedAgentProcess at spawn
time (runtime-only, never persisted), and in update_managed_agent stop +
respawn the process when the edit makes the record pass readiness — inside
the same store-lock section the save already holds, reusing
stop_managed_agent_process / start_managed_agent_process. The respawn is
best-effort: a failure is surfaced via record.last_error and never fails the
save itself. Healthy (non-setup-mode) processes keep the existing
"takes effect on next spawn" contract and the needs_restart badge.

The readiness gate lives in setup_mode_now_ready, which mirrors the
spawn-time computation (effective harness resolution + effective env), with
unit tests covering fixed config, still-missing model, still-missing
credential, and the non-setup-mode no-op.

Co-authored-by: Bradley Axen <baxen@squareup.com>
Signed-off-by: Bradley Axen <baxen@squareup.com>
This commit is contained in:
npub1ty04d6th3jzvggd25za6xmqrh99g42kvkvqsmf7ydv793fgyxa3s3t2lw7
2026-07-07 20:22:03 -07:00
parent 36fd41c5ce
commit b76292d457
6 changed files with 170 additions and 7 deletions

View File

@@ -233,7 +233,11 @@ const overrides = new Map([
// (if let Some(provider_update) = input.provider { record.provider = provider_update; }).
// +8: harness_override thread-through in update_managed_agent so a deliberate
// Custom pin routes to update_time_agent_command_override (comment + call).
["src-tauri/src/commands/agent_models.rs", 1079],
// +54: setup-mode auto-restart in update_managed_agent (stop + respawn a
// live setup-listener process when the edit satisfies readiness) + the
// expanded doc contract. Load-bearing fix for the "needs configuration"
// forever-loop; queued to split with the discovery modules above.
["src-tauri/src/commands/agent_models.rs", 1133],
// draft-persistence predicate: submit-time `loadDraft` check + inline comment
// + deps-array entry in submitMessage closes the never-persisted-boundary
// defect (Thufir Pass-3 finding). Load-bearing correctness fix; queued to