openclaw - ✅(Solved) Fix [Bug]: gateway init keeps writing into agents/main/ even when default agent is not main [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#80313Fetched 2026-05-11 03:16:22
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
2
Author
Timeline (top)
closed ×1commented ×1cross-referenced ×1

Gateway init actively rebuilds agents/main/ on every boot, even when the directory has been archived and agents.list has a different non-main default. Net effect: agents/main/ becomes a permanent ghost write target. Once #74438 lands and exempts it from orphan reporting, it'll be ghost-written and silently exempted forever.

Root Cause

Gateway init actively rebuilds agents/main/ on every boot, even when the directory has been archived and agents.list has a different non-main default. Net effect: agents/main/ becomes a permanent ghost write target. Once #74438 lands and exempts it from orphan reporting, it'll be ghost-written and silently exempted forever.

Fix Action

Fixed

PR fix notes

PR #74438: fix(doctor): don't flag the live compatibility agent dir as orphan

Description (problem / solution / changelog)

Description

Closes #74313

Summary

openclaw doctor could report the live legacy compatibility agent dir as an orphan when the configured default agent was not main. This PR exempts only the realpath-matching live compatibility store while preserving warnings for genuine orphan agent dirs.

Root Cause

listOrphanAgentDirs built its configured id set from resolveDefaultAgentId(cfg) plus agents.list[].id. When agents.list used a non-main default and ~/.openclaw/agents/main/agent still existed as the legacy compatibility store, main was treated like stale state because the orphan scan never compared it with resolveOpenClawAgentDir().

What Changed

  • Add a strict realpath comparison helper for agent-dir equality.
  • Skip the on-disk nested agent/ dir whose realpath matches resolveOpenClawAgentDir().
  • Add regression coverage for the non-main default-agent case and OPENCLAW_AGENT_DIR compatibility override.

What This Does Not Fix

A separate gateway write-side issue can recreate agents/main/{models.json,sessions.json} even after the directory is archived. This PR only fixes the doctor read-side warning so users are not guided toward deleting live compatibility state.

Real behavior proof

  • Behavior or issue addressed: openclaw doctor no longer reports the live legacy compatibility agent dir as orphaned when the configured default agent is not main; genuine orphan dirs are still reported.
  • Real environment tested: Linux x86_64, kernel 6.8.0-111-generic, Node v24.11.0, OpenClaw built from this branch at a296a342a8, isolated state under /tmp/openclaw-real-test/.
  • Exact steps or command run after this patch: Created /tmp/openclaw-real-test/openclaw.json with default agent alfred, created agents/{alfred,main,zzz-stale}/agent, then ran OPENCLAW_STATE_DIR=/tmp/openclaw-real-test OPENCLAW_HOME=/tmp/openclaw-real-test OPENCLAW_CONFIG=/tmp/openclaw-real-test/openclaw.json pnpm openclaw doctor.
  • Evidence after fix: Terminal output from the real command showed doctor reporting only zzz-stale:
◇  State integrity ────────────────────────────────────────────────────────╮
│  - Found 1 agent directory on disk without a matching agents.list        │
│    Examples: zzz-stale                                                   │
│    Restore the missing agents.list entries or remove stale dirs after    │
│    confirming they are no longer needed: …/agents                        │
  • Observed result after fix: main was exempted because its realpath matched resolveOpenClawAgentDir(), while zzz-stale was still flagged as a real orphan. Additional live checks covered OPENCLAW_AGENT_DIR pointing at legacy/agent, a non-existent override path, and mixed env override plus non-main default.
  • What was not tested: The separate gateway write-side recreation behavior was not tested or fixed here.

Tests

  • pnpm test src/commands/doctor-state-integrity.test.ts
  • Contributor also reported pnpm tsgo:core, pnpm tsgo:test, and pnpm check:changed clean on the branch.

Security Impact

No new permissions, secrets handling, network calls, or data access scope. Doctor only reads local filesystem state and suppresses one unsafe false-positive warning.

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • src/commands/doctor-state-integrity.test.ts (modified, +40/-0)
  • src/commands/doctor-state-integrity.ts (modified, +13/-1)

Code Example

T+0s    mv ~/.openclaw/agents/main ~/.openclaw/agents-archive/main-<ts>
T+0s    launchctl bootstrap gui/$UID/ai.openclaw.gateway   # fresh gateway
T+3s    ls agents/  →  only ao/T+43s   agents/main/agent/models.json appears  (size ~1.9KB)
T+106s  agents/main/sessions/sessions.json appears  (content: "{}")
RAW_BUFFERClick to expand / collapse

Follow-up to #74313 (which is read-side: doctor false-positive). This is the write-side companion bug — surfaced in https://github.com/openclaw/openclaw/issues/74313#issuecomment-4387981213 but never tracked separately. Filing so it doesn't get blocked by PR #74438's review cycle.

Summary

Gateway init actively rebuilds agents/main/ on every boot, even when the directory has been archived and agents.list has a different non-main default. Net effect: agents/main/ becomes a permanent ghost write target. Once #74438 lands and exempts it from orphan reporting, it'll be ghost-written and silently exempted forever.

Reproduction (single-agent install, ao default = true, no main in agents.list)

T+0s    mv ~/.openclaw/agents/main ~/.openclaw/agents-archive/main-<ts>
T+0s    launchctl bootstrap gui/$UID/ai.openclaw.gateway   # fresh gateway
T+3s    ls agents/  →  only ao/   ✅
T+43s   agents/main/agent/models.json appears  (size ~1.9KB)
T+106s  agents/main/sessions/sessions.json appears  (content: "{}")

No codex-mode invocation, no channel/approval traffic, no user input. Pure gateway init behavior.

Suspected cause

Init-time writers reach the compat path through the same resolveOpenClawAgentDir()DEFAULT_AGENT_ID fallback that #74438 identified for models status / --probe, just on the write side. Specific callsites worth tracing:

  • whatever code refreshes <agent>/agent/models.json during gateway boot (writes to compat path even when resolveDefaultAgentId(cfg) === \"ao\")
  • the empty-{} sessions.json initializer at agents/main/sessions/

Fix shape would mirror the read-side: gate on resolveDefaultAgentId(cfg) instead of DEFAULT_AGENT_ID.

Why a separate issue

PR #74438 explicitly scopes itself to the read-side and says "That's a write-side bug, separate from this read-side fix. Follow-up issue to come." — this is that follow-up.

Environment

  • OpenClaw 2026.5.7 (still reproducible; originally observed on 2026.5.5 commit b1abf9d)
  • macOS 26.4.1 (arm64), node v25.9.0
  • npm global install (/opt/homebrew/.../openclaw)
  • agents.list: single entry ao with default: true; no main entry
  • Default model: minimax-cn/MiniMax-M2.7
  • Channels: telegram only

Happy to provide fs-watcher output during gateway boot if it helps locate the exact write callsites.

cc #74313, #74438

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: gateway init keeps writing into agents/main/ even when default agent is not main [1 pull requests, 1 comments, 2 participants]