Skip to content

fix(doctor): keep migrated agents on their existing workspace - #123808

Merged
Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
scotthuang:agent/preserve-doctor-workspace-migration
Aug 15, 2026
Merged

Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
scotthuang:agent/preserve-doctor-workspace-migration

Conversation

@scotthuang

@scotthuang scotthuang commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users upgrading a legacy multi-agent configuration and running openclaw doctor --fix could have the previous owner agent silently moved from the shared agents.defaults.workspace to a new <workspace>/<agentId> directory after a later Doctor health write.

Why This Change Was Made

Doctor now materializes the legacy owner's workspace in its canonical roster migration candidate before retiring the old default marker. Every later Doctor write therefore persists the same authoritative workspace. This keeps explicit multi-agent ownership intact and does not introduce a global default agent or a resolver fallback.

The repair reuses the existing legacy-role materializer at the Doctor persistence boundary. Production delta: +8 net lines; test delta: +83 lines.

User Impact

Existing multi-agent installations keep the owner's current workspace, memory, and workspace files after an upgrade/Doctor repair instead of appearing to start from an empty agent-specific directory.

Evidence

Exact-head real Doctor upgrade proof

  • Product head: 2777d6425c730cf7bcbe5e6939e4ee8c317554b3.
  • Boundary: real source-checkout CLI built and run from that head against an isolated temporary HOME, state directory, and config. Bundled plugins were disabled; no provider or channel was exercised.
  • --generate-gateway-token supplied a deterministic post-migration health mutation, forcing Doctor's final config writer to run after the initial migration write. The token value was never printed; evidence records only whether it exists.

Representative legacy input (paths redacted):

{
  "agents": {
    "defaults": { "workspace": "<proof-root>/shared-workspace" },
    "entries": {
      "main": { "default": true },
      "cursor": { "workspace": "<proof-root>/shared-workspace" }
    }
  },
  "gateway": { "mode": "local" }
}

MEMORY.md and AGENTS.md canaries existed in the shared workspace before the run.

Command:

HOME=<proof-root>/home \
OPENCLAW_STATE_DIR=<proof-root>/state \
OPENCLAW_CONFIG_PATH=<proof-root>/openclaw.json \
OPENCLAW_DISABLE_UPDATE_CHECK=1 \
OPENCLAW_DISABLE_BUNDLED_PLUGINS=1 \
pnpm openclaw doctor --fix --non-interactive --yes --generate-gateway-token

Selected redacted terminal output (unrelated isolated-environment diagnostics omitted):

[openclaw] Building TypeScript (dist is stale: git_head_changed - git head changed).
OpenClaw 2026.8.1 (2777d64)

Config warnings
- Materialized legacy per-surface agent ownership.
- Removed retired agents.entries.*.default markers.

Doctor changes
- Prepared the canonical agent roster without retired default markers for persistence.
- Stamped the multi-agent roster for explicit per-surface ownership.

Updated config: <proof-root>/openclaw.json
Backup: <proof-root>/openclaw.json.bak

Gateway auth
- Gateway token configured.

Updated config: <proof-root>/openclaw.json
Backup: <proof-root>/openclaw.json.bak

Doctor complete.
exit=0

Sanitized persisted state immediately before the second write (openclaw.json.bak):

{
  "ownership": "explicit",
  "defaults_workspace": "<proof-root>/shared-workspace",
  "main_workspace": "<proof-root>/shared-workspace",
  "cursor_workspace": "<proof-root>/shared-workspace",
  "retired_default_marker_present": false,
  "gateway_auth_mode": null,
  "gateway_token_present": false
}

Sanitized final state after the second write:

{
  "ownership": "explicit",
  "defaults_workspace": "<proof-root>/shared-workspace",
  "main_workspace": "<proof-root>/shared-workspace",
  "cursor_workspace": "<proof-root>/shared-workspace",
  "retired_default_marker_present": false,
  "gateway_auth_mode": "token",
  "gateway_token_present": true
}

Post-run workspace checks:

MEMORY.md sha256=4954482e0ad1c68678b417cc88777f840e569d275dd4f33162babb8f1a2bc250
AGENTS.md sha256=852b4ec232664cff55016cf68a263933d87c59eb88ec81283e5120b62388b620
unexpected_nested_workspace_exists=false

This proves the real two-write lifecycle at the exact PR head: the later health mutation was persisted, while both agent workspaces and the existing workspace canaries remained in place.

Automated and static verification

  • node scripts/run-vitest.mjs src/commands/doctor-config-flow.workspace-persistence.test.ts src/config/legacy.roster.test.ts src/commands/doctor/shared/default-agent-role-materialization.write.test.ts — 43 tests passed.
  • pnpm tsgo:core — passed.
  • pnpm tsgo:core:test — passed.
  • Targeted Oxfmt and Oxlint — passed.
  • Autoreview and TruffleHog — clean; no actionable findings.

Proof status: real behavior passed at the exact PR head. Merge-CI status is tracked independently. Full changed-gate delegation could not start because the local Crabbox binary failed its own version/help sanity check; the required local fallback then stopped on an existing main ratchet mismatch (OPENCLAW_* count 504 vs budget 502). This patch adds no environment variables.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@scotthuang
scotthuang marked this pull request as ready for review August 14, 2026 20:02
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S labels Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 8:03 PM ET / August 15, 2026, 00:03 UTC.

ClawSweeper review

What this changes

Doctor now pins a legacy multi-agent owner’s inherited workspace into its canonical migration candidate so later Doctor writes retain that existing workspace.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. This focused PR remains necessary: current main still builds Doctor’s persisted migration candidate without materializing the legacy owner workspace, while the later health write persists that stale candidate. No blocking patch findings. Likely related people: steipete (high) and Vincent Koc (medium).

Priority: P1
Reviewed head: 2777d6425c730cf7bcbe5e6939e4ee8c317554b3

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with strong exact-head two-write behavior proof and no blocking findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The exact-head CLI transcript demonstrates a real isolated Doctor upgrade with a forced second write and confirms the persisted workspace and canaries remain intact.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The exact-head CLI transcript demonstrates a real isolated Doctor upgrade with a forced second write and confirms the persisted workspace and canaries remain intact.
Evidence reviewed 7 items Current-main gap: Current main calls the roster migration without requesting workspace materialization, so Doctor's in-memory candidate can omit the legacy owner's explicit workspace.
Patch repairs the owning candidate: The PR requests the existing workspace-materialization behavior at Doctor's persistence boundary, before removal of the legacy owner marker.
Existing materializer contract: The shared materializer already pins an owner entry to the inherited defaults workspace, or the canonical default workspace when absent; the PR only propagates its existing option.
Findings None None.
Security None None.

How this fits together

Doctor converts legacy agent configuration into the current explicit roster before its health checks may write configuration again. The resulting roster determines which workspace each upgraded agent continues to use for memory and workspace files.

flowchart LR
  A[Legacy multi-agent config] --> B[Doctor migration candidate]
  B --> C[Initial config write]
  C --> D[Health repair]
  D --> E[Final config write]
  E --> F[Existing agent workspace]
Loading

Before merge

  • Resolve merge risk (P1) - This compatibility migration persists an explicit workspace for an upgraded legacy owner; an incorrect owner mapping would redirect workspace-backed state. The supplied two-write proof covers the intended path, and the +8 production lines are the smallest propagation of an existing materializer option rather than a duplicate later-write repair.
  • Complete next step (P2) - This PR already contains the bounded repair and sufficient real behavior proof; no separate automated repair job is needed.
Agent review details

Security

None.

PR surface

Source +8, Tests +83. Total +91 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 10 2 +8
Tests 1 83 0 +83
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 93 2 +91

Review metrics

Metric Value Why it matters
Production versus test delta production +10/-2 (net +8); tests +83/-0 The production change is limited to threading an existing migration option into Doctor, with a boundary-level two-write regression test.
Persisted migration behavior 1 legacy workspace materialization path changed; 0 new config keys, flags, or defaults The change affects upgrade persistence of an existing workspace field without expanding the user configuration surface.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-config-flow.ts, migration/backfill/repair: src/commands/doctor-config-flow.workspace-persistence.test.ts, unknown-data-model-change: src/commands/doctor-config-flow.workspace-persistence.test.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Merge the canonical-candidate repair (recommended)
    Accept the tested compatibility write because it reuses the existing workspace materializer and proves the initial and later Doctor writes retain the same workspace.

Technical review

Best possible solution:

Keep Doctor’s canonical migration candidate complete before the retired marker is removed, leaving runtime normalization read-only and the generic writer free of Doctor-specific state repair.

Do we have a high-confidence way to reproduce the issue?

Yes. A legacy two-agent config with one retired default marker and a shared defaults workspace, followed by Doctor’s initial write and a health-triggered later write, is a high-confidence source path; the PR also supplies an exact-head CLI transcript of that sequence.

Is this the best way to solve the issue?

Yes. Materializing the workspace in Doctor’s canonical candidate is the narrow owner-boundary repair; relying on the generic writer alone cannot update Doctor’s retained candidate for the later write.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d9137961120f.

Labels

Label justifications:

  • P1: A legacy multi-agent upgrade can otherwise silently move an existing agent to a different workspace after Doctor writes configuration.
  • merge-risk: 🚨 compatibility: The PR changes how Doctor persists legacy multi-agent workspace ownership during upgrade.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The exact-head CLI transcript demonstrates a real isolated Doctor upgrade with a forced second write and confirms the persisted workspace and canaries remain intact.
  • proof: sufficient: Contributor real behavior proof is sufficient. The exact-head CLI transcript demonstrates a real isolated Doctor upgrade with a forced second write and confirms the persisted workspace and canaries remain intact.

Evidence

What I checked:

  • Current-main gap: Current main calls the roster migration without requesting workspace materialization, so Doctor's in-memory candidate can omit the legacy owner's explicit workspace. (src/commands/doctor-config-flow.ts:241, d9137961120f)
  • Patch repairs the owning candidate: The PR requests the existing workspace-materialization behavior at Doctor's persistence boundary, before removal of the legacy owner marker. (src/commands/doctor-config-flow.ts:243, 2777d6425c73)
  • Existing materializer contract: The shared materializer already pins an owner entry to the inherited defaults workspace, or the canonical default workspace when absent; the PR only propagates its existing option. (src/config/legacy.default-agent-roles.ts:70, d9137961120f)
  • Two-write failure mechanism: The generic writer materializes a legacy owner only while the source marker remains available, whereas Doctor retains its own cfg and only advances cfgForPersistence after a successful write; a later health mutation can therefore write the stale candidate. (src/config/io.write.ts:137, d9137961120f)
  • Boundary regression coverage: The added test performs Doctor migration, the initial writer, and a later health-triggered write, then asserts explicit ownership and preservation of the main workspace. (src/commands/doctor-config-flow.workspace-persistence.test.ts:65, 2777d6425c73)
  • Feature-history provenance: The explicit multi-agent ownership architecture, including retained-owner workspace handling, appears to originate in the ownership refactor; subsequent Doctor/config work remains concentrated in this area. (src/config/legacy.default-agent-roles.ts:57, 1ca60fbc3a3f)

Likely related people:

  • steipete: Authored the central explicit multi-agent ownership refactor and multiple subsequent Doctor/config persistence changes in the affected history. (role: explicit-ownership architecture author; confidence: high; commits: 1ca60fbc3a3f, af687f920f61; files: src/config/legacy.default-agent-roles.ts, src/commands/doctor-config-flow.ts, src/config/io.write.ts)
  • Vincent Koc: Recent history shows work on Doctor configuration behavior adjacent to the affected persistence flow. (role: recent Doctor/config contributor; confidence: medium; commits: 80da61668eb6; files: src/commands/doctor-config-flow.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-14T20:51:05.781Z sha 2777d64 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-14T22:32:04.340Z sha 2777d64 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T22:37:11.601Z sha 2777d64 :: needs maintainer review before merge. :: none

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 14, 2026
@Patrick-Erichsen
Patrick-Erichsen merged commit dd67c3b into openclaw:main Aug 15, 2026
209 of 217 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants