Skip to content

fix: resolve the OpenClaw state dir consistently (md-mirror workspace map, CLI and workspace defaults) - #994

Draft
gorkem2020 wants to merge 1 commit into
CortexReach:masterfrom
gorkem2020:fix/md-mirror-workspace-map-and-state-dir
Draft

fix: resolve the OpenClaw state dir consistently (md-mirror workspace map, CLI and workspace defaults)#994
gorkem2020 wants to merge 1 commit into
CortexReach:masterfrom
gorkem2020:fix/md-mirror-workspace-map-and-state-dir

Conversation

@gorkem2020

Copy link
Copy Markdown
Contributor

Problem

The plugin assumed a single OpenClaw instance living at ~/.openclaw:

  • resolveAgentWorkspaceMap (md-mirror) only read the legacy agents.list array. OpenClaw 2026.9 writes the keyed agents.entries form, so the mirror logged mdMirror: no agent workspaces found and wrote every agent's mirror into the default directory.
  • When the runtime config carried no agents, the fallback read ~/.openclaw/openclaw.json. On a host running a second instance (OPENCLAW_STATE_DIR pointing elsewhere) that is another instance's config; the observed effect was the second instance's mirror landing inside the first instance's main-agent workspace.
  • The default db, workspace and md-mirror directories, the CLI --openclaw-home default and OAuth file path, and the workspace capability default were all rooted at homedir()/.openclaw regardless of OPENCLAW_STATE_DIR.

Change

  • src/openclaw-paths.ts: one resolver. State dir = OPENCLAW_STATE_DIR, then OPENCLAW_HOME, then ~/.openclaw; config path = OPENCLAW_CONFIG_PATH, then <state dir>/openclaw.json. Blank or whitespace-only values count as unset.
  • The md-mirror workspace map reads both agents.entries (keyed) and agents.list (array), from the runtime config first and from the resolved config file second.
  • Plugin defaults, the CLI and the workspace capability default all go through the resolver. Single-instance installs resolve to exactly the same paths as before, so there is no behaviour change for the default layout.

Tests

  • test/openclaw-paths.test.mjs: precedence and blank-variable handling.
  • test/mdmirror-workspace-map-entries.test.mjs: entries form, list form, OPENCLAW_CONFIG_PATH fallback, state-dir fallback, state-dir-rooted and home-rooted defaults.
  • Both are registered in the npm test chain and in scripts/ci-test-manifest.mjs (core-regression). Full suite, core-regression, cli-smoke, packaging-and-workflow and verify-package-runtime are green locally; dist is rebuilt and committed.

Verification on a live install

Running as a hotfix on a seven-agent OpenClaw 2026.9.2 install: the startup log went from mdMirror: no agent workspaces found to mdMirror: resolved 7 agent workspace(s), and mirror files land in each agent's own workspace.

…LI and workspace defaults

- md-mirror workspace map: read the keyed agents.entries form as well as the legacy agents.list array; fall back to OPENCLAW_CONFIG_PATH, then <state dir>/openclaw.json, never another instance's home config
- src/openclaw-paths.ts: one resolver for the state dir (OPENCLAW_STATE_DIR, then OPENCLAW_HOME, then ~/.openclaw) and the config path; blank values count as unset
- default db, workspace and md-mirror dirs, the CLI --openclaw-home default and OAuth path, and the workspace capability default all resolve through it
- tests: openclaw-paths, mdmirror-workspace-map-entries (registered in the test chain and the CI manifest); dist rebuilt
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.

1 participant