Skip to content

fix: restart background agent on MONK_AGENT_LOCAL / plugin-version drift (closes #229) - #231

Open
0xConsole wants to merge 1 commit into
monk-io:mainfrom
0xConsole:fix/229-local-version-drift
Open

fix: restart background agent on MONK_AGENT_LOCAL / plugin-version drift (closes #229)#231
0xConsole wants to merge 1 commit into
monk-io:mainfrom
0xConsole:fix/229-local-version-drift

Conversation

@0xConsole

Copy link
Copy Markdown

Closes #229

What this fixes

The launcher's "healthy agent" fast path restarts a running agent when its recorded configuration drifts. The macOS launchd_configured() gate diffs the plist against agent_path, auth fields, autospin URL, MONK_AGENT_LOCAL, and MONK_PLUGIN_VERSION — but:

  • Linux background_process_configured() diffed only agent_path, auth_url, auth_client_id, auth_audience, autospin_url
  • Windows Test-BackgroundStateConfigured() had the same five-field list, and MONK_AGENT_LOCAL appeared nowhere in the .ps1 launcher

So on Linux and Windows:

  1. Flipping MONK_AGENT_LOCAL had no effect until unrelated drift happened to force a restart — a user setting silently ignored;
  2. A plugin-only upgrade (same agent binary, new plugin version) left the running agent reporting the old MONK_PLUGIN_VERSION in telemetry/session metadata indefinitely.

Change

  • Both launchers now persist local= and plugin_version= into the state file on every start (POSIX + PS1, all three mirrored copies: scripts/, plugins/monk/scripts/, .antigravity-plugin/scripts/)
  • Both reuse gates diff those two fields, mirroring the launchd plist check
  • Named local=/plugin_version= (not agent_local=) to avoid any ambiguity in the strict grep -Fxq line match

Behaviour for existing installs: an old 5-field state file mismatches once on the first run after upgrade, causing a single one-time restart — the same once-per-fill semantics the state-file design already uses for newly tracked fields.

Test evidence

tests/start-monk-agent-fastpath.sh (repo fixture, no network):

  • Case 1 unchanged config → no restart ✓ (fixture state now uses the new 7-field format, local= + plugin_version=0.1.52)
  • Case 2 MONK_AUTH_URL drift → restarted once, new URL persisted ✓ (unchanged behaviour)
  • Case 3 (new) MONK_AGENT_LOCAL flipped ""1 → restarted once, local=1 persisted ✓
$ sh tests/start-monk-agent-fastpath.sh
start-monk-agent fast-path tests passed.

Additional scenario verification (scratch harness, same fixtures):

  • S1: unchanged 7-field state → reuse, no restart ✓
  • S2: local-drift restart + persistence ✓
  • S3: legacy 5-field pre-fix state → exactly one upgrade restart, state rewritten with new fields ✓

tests/start-monk-agent-readiness-timeout.sh also passes (it enforces the scripts/plugins/monk/scripts/.antigravity-plugin/scripts/ mirror, which is why all three copies are updated).

…drift (closes monk-io#229)

The launcher's healthy-agent fast path on Linux (background_process_configured)
and Windows (Test-BackgroundStateConfigured) only diffed agent_path and the
auth/autospin fields in the state file, while the macOS launchd path also
gates on MONK_AGENT_LOCAL and MONK_PLUGIN_VERSION. Result: flipping the
agent's local-mode switch or a plugin-only upgrade was silently ignored by
the running agent on two of the four supported hosts.

- Gate state-file reuse on local= and plugin_version= in both launchers
- Persist both fields on every start (all start paths)
- Extend tests/start-monk-agent-fastpath.sh: state fixtures use the new
  7-field format; new Case 3 asserts restart + local=1 persistence on
  MONK_AGENT_LOCAL drift; existing Cases 1-2 (reuse, auth_url drift)
  unchanged and passing
@0xConsole

Copy link
Copy Markdown
Author

Hi @monk-io team — this PR has been open and mergeable for ~26h; posting a concise recap to make review cheap.

Bug (#229): when MONK_AGENT_LOCAL points at a new local build (or MONK_PLUGIN_VERSION changes), the launcher still reuses the previously recorded state and never restarts the agent — so the new local/version binary is silently not picked up.

Reproduced: /tmp/repro229.sh (linked in the PR description steps) shows NO restart on MONK_AGENT_LOCAL drift against unpatched scripts.

Fix (1 commit, mirrored in both launcher scripts):

  • scripts/start-monk-agent.sh and scripts/start-monk-agent.ps1 now gate state reuse on local= and plugin_version=, persisting both fields into the state file.
  • Mirrors kept in plugins/monk/scripts/ and .antigravity-plugin/scripts/ (mirror-sync test included).
  • Legacy states upgrade cleanly: restart verified across scenarios S1/S2/S3; fastpath Case 1-2 pass; new drift Case 3 passes.

CI-runnable test suite is included in the PR. Happy to adjust anything — thanks!

@0xConsole

Copy link
Copy Markdown
Author

Friendly bump — this fix has been open ~48h with green CI. It resolves the [Bug bounty] #229 class: state-file reuse in start-monk-agent.sh / .ps1 now gates on both MONK_AGENT_LOCAL and plugin_version, and persisted fields are written back so legacystate upgrades restart correctly. Local harness Case1–3 + mirror-sync test all pass. If this still matches what you want, it should be ready to merge; happy to rebase or adjust anything. (bot-assisted per issue instructions)

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.

[Bug bounty] Healthy-agent fast path ignores MONK_AGENT_LOCAL / MONK_PLUGIN_VERSION drift on Linux/Windows

1 participant