Skip to content

fix(runtime-host): surface refused Host handoff attempts instead of looping - #5758

Merged
jackwener merged 1 commit into
apache:mainfrom
Astro-Han:fix/runtime-host-handoff-refusal-recovery
Sep 27, 2026
Merged

jackwener merged 1 commit into
apache:mainfrom
Astro-Han:fix/runtime-host-handoff-refusal-recovery

Conversation

@Astro-Han

Copy link
Copy Markdown
Contributor

Summary

When Desktop upgrades while a supervised Runtime Host from an older release is running, the handoff dialog can stay open indefinitely (#5476). The part of the report that still holds on main is the dialog getting stuck. The idea that staging never ends does not: the update process already stops after 10 minutes.

  • The automatic safe replacement runs maka runtime-host service update from the new package. That CLI cannot speak the old Host's retirement protocol: connectExistingRuntimeHost returns incompatible. Without interruption consent, retireRuntimeHostLifecycleOwner therefore returns active_tasks for a supervised Host, even when its handshake reports 0 connections and 0 operations. The CLI then rolls back the staged package, so the launchd/systemd unit keeps pointing at the old version. This matches the "plist never rewritten, KeepAlive keeps the old daemon" observation in the issue comments.
  • runHostHandoff counted that refusal as busy only for explicit-selection replacements. For the supervised path it showed retry_required ("the service changed; a safe retry won't interrupt work") plus "Maka keeps checking". Retry runs the same refused attempt (download, stage, rollback), so the loop never ends. The only action that works, Stop and continue, looked secondary. This is exactly the screen in the report: retry_required with 0 connections, 0 operations and 0 background activities.

Changes:

  • projectBlocker now shows any refused safe attempt as busy, whatever the replacement kind. An idle busy view uses the existing "The old service refused safe retirement… close other clients and try again, or explicitly interrupt work and continue" copy. No new strings.
  • The Desktop local adapter no longer treats a target_mismatch refusal from service update / restart as replaced / unavailable. Pre-mutation refusals such as "This update would downgrade the shared Runtime Host. Update the Client instead." used to lose their diagnostic and land in the same loop. They now become repair_required with the CLI's message. Recovery is keyed to the observed blocker identity. A Host that really changed has a new registration, so it is still observed again and handled automatically.

Refs #5476

Out of scope

  • The automatic safe attempt against an incompatible supervised Host always ends in refusal, so it still costs one download and stage before the dialog asks for consent. Skipping it would copy the CLI's retirement policy into Desktop. Retiring automatically when the snapshot is idle would change the explicit-consent rule. Both are product decisions and not part of this PR.
  • Cancel during a pre-retirement staging phase still only sends the cooperative EOF, and the CLI honors it only during retirement. The attempt therefore stays bounded by the existing 10-minute operator timeout, not by the click.
  • The WSL handoff also maps target_mismatch to changed. That path requires explicit selection with a manual recheck and has its own test, so it is left alone.
  • The nightly isVersionNewer comparison mentioned in the issue thread is a separate app-update issue.

Verification

  • RED on main: the extended host-handoff test got retry_required instead of busy, and both extended runtime-host-local-remote-access cases resolved instead of rejecting.
  • Checked the CLI claim with a temporary test (not committed): retireRuntimeHostLifecycleOwner with an idle incompatible supervised Host, refuse_active_work → { kind: 'active_tasks' } and the supervisor is not retired.
  • @maka/runtime-host dist/**/*.test.js: 2144 passed, 2 failed. The 2 failures are sandbox Bash tests in execution-model-composition, and they fail the same way on the root main checkout.
  • @maka/desktop dist/main/**/*.test.js: all pass.
  • maka-agent handoff tests (runtime-host-handoff-surface, local-handoff, managed-source-handoff): all pass.
  • npm run lint and npm run format:check are clean.
  • Not run: E2E, a real release→release upgrade against an installed launchd service.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Devin handled the diagnosis, the code and test changes, and this description.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

…ooping

When Desktop upgrades while a supervised Runtime Host from an older
release is running, the handoff starts an automatic safe replacement.
The managed update CLI cannot speak the old Host's retirement protocol,
so without interruption consent it reports active_tasks even though the
Host's handshake shows zero connections and operations. It rolls back
the staged package and leaves the launchd/systemd unit on the old
version.

The handoff projected that refusal for non-explicit replacements as
retry_required ("the service changed; retrying is safe"). Retrying runs
the same refused attempt again, so the dialog stayed open indefinitely
and the one action that works, Stop and continue, looked secondary.
A refusal is now projected as busy for every replacement kind, and an
idle busy view uses the existing "refused safe retirement" copy.

The local adapter also reported a target_mismatch refusal from the
update, repair, or restart command as a successful replacement or an
unavailable result. Pre-mutation refusals such as a downgrade then lost
their diagnostic and re-entered the same loop. They now fail like any
other refusal. Recovery is keyed to the observed blocker identity, so
a Host that really changed is still observed again and handled
automatically.

Refs apache#5476

Generated-by: Devin
@github-actions github-actions Bot added the effort/S Under 100 readable lines label Sep 27, 2026
@Astro-Han
Astro-Han marked this pull request as ready for review September 27, 2026 12:15

@jackwener jackwener left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving at dbb602d63d30c62c72fa90ca3e19cc3d9f519be9. No P0–P2 findings, and CI test is green.

  • Loop fix: projectBlocker now maps any refused safe attempt (activeWorkRefused) to busy, whatever the replacement kind, before the explicit-selection and idle-activity branches. An idle supervised Host that refuses retirement therefore offers cancel / retry / interrupt with the existing "refused safe retirement" copy (formatHostHandoff treats idle activity plus busy as the manual-busy case) instead of the retry_required screen that re-ran the same refused staging. The renamed test pins the reason, the actions and the copy.
  • Desktop adapter: target_mismatch from service update / restart no longer collapses to replaced / unavailable. Pre-mutation refusals such as the downgrade guard keep their CLI diagnostic and surface as a repair failure, and the new assertions cover both the repair and the conflict-replacement paths.
  • canInterrupt: false: this only occurs without a registration. There, busy with cancel / retry is accurate, and the copy points the user to closing other clients.
  • P3, accepted trade-off: a genuine concurrent replacement between observation and service update used to be absorbed as replaced. It now surfaces as an error once, and the next attempt re-observes the new registration. That fits the PR's "recovery is keyed to the observed blocker identity" reasoning; I'm noting it only so the behavior change is visible.
  • Not verified: a real old-release supervised Host upgrade on macOS or Linux.

Automated review by an AI agent, approving at a maintainer's request. This is not an independent human review.

@jackwener
jackwener merged commit fdaa858 into apache:main Sep 27, 2026
3 checks passed
@Astro-Han
Astro-Han deleted the fix/runtime-host-handoff-refusal-recovery branch September 27, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/S Under 100 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants