Skip to content

[Bug] Null agent workspace field causes crash loop — auto-restore does not repair missing required fields #77718

Closed

Description

@slideshow-dingo

Bug Summary

If any agent in agents.list has a missing/null workspace field, the gateway crashes with Invalid input: expected string, received null and enters a crash loop. The openclaw doctor --fix auto-restore mechanism does not repair this field, so subsequent restarts also fail until the user manually edits the config.

Environment

  • OpenClaw: 2026.5.3-1
  • Node.js: 22.22.2 (Linux)
  • Config: ~/.openclaw/openclaw.json

Steps to Reproduce

  1. Create or modify an agent entry in agents.list without a workspace field
  2. Start or restart the gateway
  3. Observe crash with startup bundle reason gateway.startup_failed
  4. Run openclaw doctor or openclaw gateway restart
  5. Gateway crashes again — doctor does not repair the missing field

Observed Error Log

Invalid config at /home/moltbot/.openclaw/openclaw.json.
agents.list.2.workspace: Invalid input: expected string, received null
Run `openclaw doctor` to repair, or fix the keys above manually.

Error: systemctl restart failed: Job for openclaw-gateway.service failed because the control process exited with error code.

Observed Behavior

After the crash, stability bundles are written every 6 seconds:

wrote stability bundle: ...openclaw-stability-...-gateway.startup_failed.json

This creates a tight crash loop until the bad config entry is manually fixed.

Root Cause

The agents.list[N].workspace field is a required string in the config schema. The gateway validates this on startup and refuses to start if it's null. However:

  1. The openclaw doctor tool does not repair missing required string fields (only repairs certain known patterns)
  2. The last-known-good auto-restore mechanism (doctor-invalid-config) restores the same broken config because it was the last valid config before the field went null
  3. No sentinel or schema validation repair is applied during the restore

Impact

  • Gateway downtime ~7 minutes (observed in production)
  • Requires manual config editing to recover
  • Crash loop generates ~60 stability bundles per minute

Suggested Fix

One of:

  1. Schema default: Treat missing workspace as inheriting the global default (agents.defaults.workspace)
  2. Doctor repair: Make openclaw doctor --fix detect and repair null/missing required string fields in agent entries
  3. Startup guard: If an agent entry is missing required fields, warn instead of crashing; start the gateway with the other valid agents

Config Entry That Causes This

{
  "id": "small-model-sandbox",
  "model": "ollama/qwen2.5-coder:7b",
  "sandbox": { "mode": "all" },
  "tools": { "deny": ["group:web", "browser"] }
  // ← no "workspace" field
}

Fix: add "workspace": "/path/to/workspace" to resolve.

Activity

  1. clawsweeper commented on May 5, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 14, 2026, 3:12 PM ET / 19:12 UTC.

    Summary
    This should stay open: current main and v2026.6.6 already handle an omitted per-agent workspace by falling back to the default workspace, but a literal null workspace still fails schema validation and the doctor compatibility pipeline does not appear to repair that malformed field.

    Reproducibility: yes. for the null case from source inspection: workspace is optional but must be a string, invalid snapshots are preserved as invalid, and gateway startup throws on invalid config. Missing workspace alone no longer reproduces because the current resolver falls back to configured/default workspace paths.

    Next step
    This is a narrow, source-backed repair candidate in core doctor/config code with clear files and validation targets.

    Review details

    Best possible solution:

    Add a narrow doctor --fix compatibility repair that removes or normalizes null agents.list[].workspace values so runtime config remains strict and workspace resolution continues through the existing fallback path.

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

    Yes for the null case from source inspection: workspace is optional but must be a string, invalid snapshots are preserved as invalid, and gateway startup throws on invalid config. Missing workspace alone no longer reproduces because the current resolver falls back to configured/default workspace paths.

    Is this the best way to solve the issue?

    Yes, the best fix is a doctor-owned repair for null agents.list[].workspace, not a startup guard or runtime shim. That matches the repository policy that runtime reads canonical config while doctor migrates malformed shipped/user config.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The omitted-workspace half of the report appears fixed and shipped, so a fix PR should avoid adding a runtime fallback or broad compatibility shim for valid missing fields.
    • The remaining null-workspace case is source-proven but was not live-reproduced in this read-only review.

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

    Label changes

    Label changes:

    • add P1: A malformed agent workspace value can still fail gateway startup and produce the reported crash-loop recovery path for affected installs.
    • add impact:crash-loop: The issue is explicitly about gateway startup repeatedly failing after invalid config validation.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:queueable-fix: Current issue advisory state selects this label.
    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.

    Label justifications:

    • P1: A malformed agent workspace value can still fail gateway startup and produce the reported crash-loop recovery path for affected installs.
    • impact:crash-loop: The issue is explicitly about gateway startup repeatedly failing after invalid config validation.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs src/commands/doctor-legacy-config.migrations.test.ts
    • node scripts/run-vitest.mjs src/config/config.schema-regressions.test.ts
    • node scripts/run-vitest.mjs src/gateway/server-startup-config.recovery.test.ts

    What I checked:

    • Issue report: The reporter's log is for agents.list.2.workspace receiving null, and the example also shows an omitted workspace field; this makes the remaining issue specifically about malformed/null workspace repair rather than only optional workspace inheritance.
    • Current schema: AgentEntrySchema defines workspace as an optional string, so an omitted workspace is valid, but null is still rejected by Zod as a non-string value. (src/config/zod-schema.agent-runtime.ts:1047, a189baa4b344)
    • Current workspace fallback: resolveAgentWorkspaceDir falls back from a missing per-agent workspace to agents.defaults.workspace, the default agent workspace, or a stateDir-derived per-agent workspace. (src/agents/agent-scope-config.ts:183, a189baa4b344)
    • Startup failure path: Gateway startup still throws when the loaded config snapshot is invalid, which means a null workspace schema error can still stop startup before services are exposed. (src/gateway/server-startup-config.ts:430, a189baa4b344)
    • Doctor repair gap: The doctor compatibility pipeline currently runs base, plugin, channel, SecretRef, commands, OpenAI Codex metadata, and binding pruning migrations, but no agents.list[].workspace null repair is present in this central pipeline. (src/commands/doctor/shared/legacy-config-core-migrate.ts:47, a189baa4b344)
    • Doctor applies compatibility normalization: doctor-config-flow calls normalizeCompatibilityConfigValues and applies its mutations when --fix is active, so this is the right narrow repair point for a malformed config value. (src/commands/doctor-config-flow.ts:223, a189baa4b344)

    Likely related people:

    • steipete: Recent GitHub history shows repeated work on config schema helpers, agent scope, doctor legacy repair helpers, and gateway runtime helpers that surround this bug. (role: recent area contributor; confidence: high; commits: 43190f5248b5, 00d8d7ead059, e12a6d6a67d7; files: src/config/zod-schema.agent-runtime.ts, src/agents/agent-scope-config.ts, src/commands/doctor/shared/legacy-config-core-migrate.ts)
    • vincentkoc: The checked-out main commit/blame is attributed to Vincent Koc and recent gateway config-adjacent history includes startup/secrets fast-path work. (role: current-main provenance; confidence: medium; commits: a189baa4b344, 3995d577973c; files: src/config/zod-schema.agent-runtime.ts, src/agents/agent-scope-config.ts, src/gateway/server-startup-config.ts)
    • Yuval Dinodia: Recent history includes a focused fix preserving agents.list and adding doctor repair coverage around malformed agent lists and bindings. (role: adjacent doctor repair contributor; confidence: medium; commits: bbdff39b6a3f; files: src/commands/doctor/shared/legacy-config-core-migrate.ts, src/commands/doctor-legacy-config.migrations.test.ts)
    How this review workflow works
    • 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.
  2. openclaw-barnacle commented on May 31, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  3. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:crash-loopCrash, hang, restart loop, or process-level availability failure.
    no-staleExclude from stale automation
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    and removed
    staleMarked as stale due to inactivity
    on Jun 14, 2026
  4. added a commit that references this issue on Jun 16, 2026
    7f32988
  5. added a commit that references this issue on Jun 16, 2026
    2b752ac
  6. added a commit that references this issue on Jun 17, 2026
    f60d7bd
  7. locked as resolved and limited conversation to collaborators on Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.no-staleExclude from stale automation

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions