Skip to content

feat(claude-code-bridge): cloud-mirror reads instanceId for per-vault scoping (Phase D2.1)#14

Merged
LightDriverCS merged 2 commits into
mainfrom
feat/cloud-mirror-instance-id
Apr 28, 2026
Merged

feat(claude-code-bridge): cloud-mirror reads instanceId for per-vault scoping (Phase D2.1)#14
LightDriverCS merged 2 commits into
mainfrom
feat/cloud-mirror-instance-id

Conversation

@LightDriverCS

@LightDriverCS LightDriverCS commented Apr 28, 2026

Copy link
Copy Markdown

Summary

The cloud-mirror daemon now reads instanceId from ~/.openclaw/openclaw.json (or BENCH_INSTANCE_ID env override) and scopes its filesystem footprint per-instance.

Why

Phase D2.1 — when multiple Bench instances eventually share infrastructure (Tier B local, Tier C cloud), the cloud-mirror daemon needs to:

  1. Watch only its instance's vault (not all of ~/.openclaw/wiki/).
  2. Keep a separate state file per instance so switching instanceId doesn't re-POST the previous vault.
  3. Stamp each ingest payload with sourceInstanceId so the cloud side (/api/v1/wiki/ingest) can attribute deltas correctly.

Changes

  • extensions/claude-code-bridge/cloud-mirror.mjs:
    • readInstanceIdFromConfig() — reads instanceId from openclaw.json (env override first), validates against /^[A-Za-z0-9_-]{1,128}$/ (local copy of the same regex used in src/config/zod-schema.ts — daemon runs without TS toolchain).
    • VAULT_DIR derived from ~/.openclaw/wiki/{instanceId || "main"}/.
    • State file becomes wiki-mirror.{instanceId}.json when scoped, wiki-mirror.json otherwise.
    • Each scanned entry includes sourceInstanceId (when set) for upstream tagging.
    • Startup log now includes the resolved instanceId.

Stacked PR

Stacked on #11. Once #11 merges, GitHub auto-rebases this onto main.

Test plan

  • Pre-commit hooks green
  • Manual smoke (deferred, post-merge): set BENCH_INSTANCE_ID=test-shard, verify ~/.openclaw/state/wiki-mirror.test-shard.json is created when the daemon runs and deltas hit /api/v1/wiki/ingest with sourceInstanceId: "test-shard".

🤖 Generated with Claude Code

Anvil Handoff

  • Hammer summary: Cloud-mirror daemon (.mjs, no TS) reads instanceId from ~/.openclaw/openclaw.json (or BENCH_INSTANCE_ID env override) at startup. Watches per-instance vault, uses per-instance state file wiki-mirror.{instanceId}.json, stamps sourceInstanceId on each ingest payload. Validation regex is a third local copy of [A-Za-z0-9_-]{1,128}. Stacked on feat(config): top-level instanceId field (Phase D2.1 foundation) #11.
  • Primary paths changed: extensions/claude-code-bridge/cloud-mirror.mjs
  • Verification run: No automated test (long-running daemon). Pre-commit green.
  • Known risks: (1) Switching instanceId orphans the previous wiki-mirror.json state and triggers a full re-POST of the new vault — confirm cloud-side /api/v1/wiki/ingest handles re-POST of pre-existing slugs without duplicate creation. (2) BENCH_INSTANCE_ID env override bypasses the openclaw.json check entirely; intentional for advanced/test scenarios but worth verifying it doesn't shadow operational misconfig. (3) Read-side bundle hooks need to honor sourceInstanceIdfor tenant scoping — confirm a pairedBenchAGI_Mono_Repo` PR is wired or in-flight.
  • Suggested Anvil focus: Manual smoke: BENCH_INSTANCE_ID=test-shard node extensions/claude-code-bridge/cloud-mirror.mjs — verify (a) ~/.openclaw/state/wiki-mirror.test-shard.json is created, (b) ingest payloads include sourceInstanceId: "test-shard". Diff the regex constants across this PR + feat(config): top-level instanceId field (Phase D2.1 foundation) #11 + feat(memory-wiki): scope vault path to instanceId (Phase D2.1) #13 byte-for-byte. Confirm the sourceInstanceId field name matches what the cloud-side ingest endpoint expects.

Cory Shelton and others added 2 commits April 28, 2026 01:03
Adds an optional `instanceId` field to OpenClawConfig. Validates
1-128 chars matching `[A-Za-z0-9_-]+` so the value can serve as a
filesystem-safe path component. When set, downstream features
(memory-wiki vault path, cloud-mirror state file, health snapshot,
shard directory layout) scope per-instance resources to this id.
When unset, single-user Tier A defaults apply.

This is the foundation PR for Phase D2.1 (per-instance harness
hardening); subsequent PRs surface the field on health, scope the
memory-wiki vault, and update the cloud-mirror daemon.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… scoping (Phase D2.1)

The cloud-mirror daemon now reads `instanceId` from
~/.openclaw/openclaw.json (or `BENCH_INSTANCE_ID` env override) and:

- Watches the per-instance vault dir (`~/.openclaw/wiki/{instanceId}/`)
  instead of the hardcoded `main/`.
- Uses a per-instance state file
  (`~/.openclaw/state/wiki-mirror.{instanceId}.json`) so switching
  instanceId looks like a fresh sync rather than re-POSTing the
  previous vault.
- Stamps each ingest payload with `sourceInstanceId` so the cloud
  side (`/api/v1/wiki/ingest`) can attribute deltas to the correct
  Bench instance.

InstanceId validation matches `src/config/zod-schema.ts`
(`/^[A-Za-z0-9_-]{1,128}$/`) — kept local because the daemon runs
without the TS toolchain. Falls back to `main` on any invalid input.

Depends on PR #11 (the field has to be valid in openclaw.json before
this daemon will see it).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
LightDriverCS added a commit that referenced this pull request Apr 28, 2026
Phase D2.1 foundation. Adds optional top-level instanceId to OpenClawConfig with strict regex /^[A-Za-z0-9_-]{1,128}$/ for filesystem-safe per-instance scoping. Stack of #12 (health), #13 (memory-wiki vault), #14 (cloud-mirror) follows.

Codex Anvil (gpt-5.5 xhigh) verdict: PASS. 54 tests pass; pnpm config:schema:check + pnpm config:docs:check both green. Repair patch from first smoke (regenerate config-baseline.sha256) applied as second commit.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@LightDriverCS
LightDriverCS changed the base branch from feat/config-instance-id to main April 28, 2026 08:23
@LightDriverCS
LightDriverCS merged commit 3bb2756 into main Apr 28, 2026
4 of 15 checks passed
@LightDriverCS
LightDriverCS deleted the feat/cloud-mirror-instance-id branch April 28, 2026 08:24
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