Skip to content

Make update-client idempotent when a GBrain source already exists #24

Description

@100yenadmin

TLDR

scripts/update-client.mjs should treat an already-registered openclaw-support-kb GBrain source as success, even when newer gbrain sources add returns only a generic Error: command failed. During the Golden VM Eva Brain canary, the KB repo updated correctly and the existing source was healthy, but the installer aborted before sync/embed because source registration was not idempotent enough.

Why this matters

Fleet upgrades need to be boring. Existing customer VMs will usually already have an openclaw-support-kb source, so the updater must refresh that source instead of failing and requiring an agent to SSH in and manually run sources federate, sync, and embed.

flowchart TD
  A[update-client.mjs] --> B[git pull KB repo]
  B --> C[install support skills]
  C --> D[gbrain sources add openclaw-support-kb]
  D -->|generic nonzero when already exists| E[installer aborts]
  E --> F[sync/embed/status skipped]
  D -->|desired| G[recognize existing source]
  G --> H[gbrain sources federate]
  H --> I[gbrain sync --source openclaw-support-kb]
  I --> J[gbrain embed --stale --source openclaw-support-kb]
Loading

Repro from Golden VM

Environment:

  • VM: golden / 178.104.117.126
  • Eva Brain: upgraded to gbrain 0.33.0
  • Existing source: openclaw-support-kb at /root/.gbrain/sources/openclaw-support-kb
  • Source status before manual recovery: healthy, 654 pages

Failure path:

node /root/.gbrain/sources/openclaw-support-kb/scripts/update-client.mjs

Observed output:

Installed 4 OpenClaw support skills into /root/.openclaw/skills
Updated agent hint block in /root/.openclaw/AGENTS.md
Updated agent hint block in /root/.openclaw/workspace/AGENTS.md
gbrain sources add failed for openclaw-support-kb
[ai.gateway] recipe "google" declares an embedding touchpoint without max_batch_tokens; recursion is the only safety net for batch caps.
Error: command failed

Direct command evidence:

gbrain sources add openclaw-support-kb \
  --path /root/.gbrain/sources/openclaw-support-kb \
  --name "OpenClaw Support KB" \
  --federated

returns exit code 1 with only:

Error: command failed

The source already existed and was valid:

{
  "id": "openclaw-support-kb",
  "name": "OpenClaw Support KB",
  "local_path": "/root/.gbrain/sources/openclaw-support-kb",
  "federated": true,
  "page_count": 654
}

Manual recovery that worked

gbrain sources federate openclaw-support-kb
gbrain sync --repo /root/.gbrain/sources/openclaw-support-kb --source openclaw-support-kb
gbrain embed --stale --source openclaw-support-kb
node /root/.gbrain/sources/openclaw-support-kb/scripts/status.mjs

Result:

  • gbrain 0.33.0
  • source pages: 649
  • embeddings: completed for stale KB chunks
  • support KB status: healthy

Acceptance criteria

  • update-client.mjs succeeds when the named source already exists and points at the target dir.
  • If sources add returns a generic failure, the script checks gbrain sources list --json or equivalent before aborting.
  • Existing source with matching path is federated/refreshed, not removed.
  • Existing source with mismatched path still follows the current safe recreate path.
  • The script runs source-scoped sync/embed after an existing-source success path.
  • Regression test covers the generic-error existing-source case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions