Skip to content

fix(templates): agent kept by a failed offline Add has no AGENTS.md - #199082

Merged
Patrick-Erichsen merged 4 commits into
openclaw:mainfrom
anmol0b:fix/templates-kept-agent-bootstrap
Nov 15, 2026
Merged

Patrick-Erichsen merged 4 commits into
openclaw:mainfrom
anmol0b:fix/templates-kept-agent-bootstrap

Conversation

@anmol0b

@anmol0b anmol0b commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Related: #198744 (this restores the default files; recovering the held package BOOTSTRAP.md after a failed offline Add stays open there)

What Problem This Solves

Fixes: when offline openclaw templates add keeps the new agent after a later step fails, the agent's workspace holds only the Template's SOUL.md, and it stays that way after every turn. The failure message says "Continue setup in this agent", but the agent runs without AGENTS.md, IDENTITY.md or USER.md.

User Impact

After a failed offline Add keeps the agent, its workspace also gets the default AGENTS.md, IDENTITY.md and USER.md, the same files an agent gets on its first turn after a successful Add. The Template's own files are not replaced, and the operator's agents.defaults.skipBootstrap and skipOptionalBootstrapFiles are honored exactly as ordinary CLI preparation applies them (src/agents/command/prepare.ts). The package BOOTSTRAP.md is still held back, because its first-run instructions can depend on the plugin, MCP server or automation whose setup failed. Successful Adds and Gateway Adds are unchanged.

Why This Change Was Made

#196392 holds a Template's workspace bootstrap while Add runs: it sets bootstrapDeferred and ensureAgentWorkspace returns early while it is set (src/agents/workspace.ts:592), so no turn can seed defaults or a generic BOOTSTRAP.md ahead of the package one. The deferral is cleared when the package BOOTSTRAP.md is seeded, which is the last Add step (src/templates/add-stateless.ts:674). When a later step fails and the agent is kept, nothing clears it. Gateway Add resumes that agent through Retry, which reaches the seed step. Offline Add has no resume, so the hold never ends and every turn skips the default files.

Holding the package BOOTSTRAP.md is intentional, and conversation.workspace.test.ts keeps proving that a later seed still applies. So this change does not lift the hold. A new seedDeferredWorkspaceDefaults in workspace-preparation.ts, beside the deferral it respects, writes only the default instruction files that ordinary preparation would write under the current agents.defaults (nothing with skipBootstrap, minus any skipOptionalBootstrapFiles), with the existing exclusive-create publisher, and leaves BOOTSTRAP.md and setup state untouched. It does nothing when the workspace is not held. The offline CLI, which owns offline custody, calls it after a partial result with agentRetained.

It is not called from applyTemplateAddPlanStateless itself: Gateway-kept agents carry a configured checkpoint whose workspaceIdentity covers every file in the workspace (src/templates/add-checkpoint.ts), so adding files there would make Retry report that the workspace changed.

Accepted edge: if writing the default files itself fails, the CLI reports that error instead of the partial result. The agent is still kept and the next failure message names the cause.

Evidence

Current integrated candidate: 7b69a60f36cdd3661b29cfe3dfc7a52dd3aeb126

The conflict repair preserves contributor ancestry and incorporates main at 355e5ae57e4eef2d39d1afa765613f2981d8d62c through the native baseline workflow. The retained-defaults caller now passes the workspace preparation owner's captured filesystem evidence to the existing exclusive publisher through WorkspaceStateGuard. The complete product diff against that baseline remains four files, +83/-2; permitted defaults, suppression settings, existing-file preservation and package BOOTSTRAP.md custody retain the original repair's behavior.

  • Exact integrated candidate: all 97/97 focused tests passed across conversation.workspace.test.ts, templates-cli.test.ts, templates-agent-conversation.test.ts and agents/workspace.test.ts (73 infrastructure + 24 CLI). The fresh-process custody regression, both suppression controls, existing SOUL.md preservation and subsequent package bootstrap seeding pass with the current filesystem owner.
  • Core typecheck, scoped production lint, formatting of all four changed files and git diff --check passed.
  • Fresh independent source review of the complete integrated delta found no actionable findings. The existing ClawSweeper review covers incoming head edab73ce2d97d08edb92aa723262608ade9b9b11; its original correctness findings were already resolved. This paragraph does not claim a new hosted review of the integrated head.
  • Paired behavior proof: the real isolated offline CLI captures below show baseline SOUL.md only after a failed retained Add and later turn, versus permitted default AGENTS.md, IDENTITY.md and USER.md with this repair; package bootstrap stays held. Those captures are reused for unchanged CLI behavior. The new exact-candidate test/typecheck run specifically validates the filesystem-owner integration; no new model-backed CLI session was run for that mechanical adaptation.

Hosted CI for this new candidate is pending publication; the earlier head's CI is not new-head evidence. The broader package-bootstrap recovery in #198744 remains open.

Offline CLI from main (de20049) and from this branch, Gateway stopped, isolated HOME, OPENCLAW_STATE_DIR and OPENCLAW_CONFIG_PATH, a local OpenAI-compatible stub for the model. The failing Add is a Template with a package BOOTSTRAP.md whose opening model turn fails after the agent is committed (the stub is stopped during Add, then started again). This trigger does not depend on #198743.

  • Main: Add exits 1 with "The agent was already made available and was kept. Continue setup in this agent". The workspace is SOUL.md, and still SOUL.md after openclaw agent --local --agent kept --message hello.
  • This branch: same Add result; the workspace is AGENTS.md IDENTITY.md SOUL.md USER.md after Add and after the turn. No BOOTSTRAP.md.
  • This branch with agents.defaults.skipBootstrap: true in the config: the same failing Add leaves only the Template SOUL.md in the workspace, as ordinary preparation would.
  • Control on both trees: the same Template with the model up adds normally, has BOOTSTRAP.md SOUL.md after Add and all five files after one turn.
Main (RED) and this branch (GREEN)
# main de200490f82
$ openclaw templates add <run>/kept
Added agent: kept
Couldn't connect to the AI service. ... The agent was already made available and was kept. Continue setup in this agent; do not add another copy.
[exit 1]
$ ls -A <state>/workspace-kept
  SOUL.md
$ openclaw agent --local --agent kept --message hello
[exit 0]
$ ls -A <state>/workspace-kept
  SOUL.md

# this branch
$ openclaw templates add <run>/kept
[exit 1]   (same message)
$ ls -A <state>/workspace-kept
  AGENTS.md IDENTITY.md SOUL.md USER.md
$ openclaw agent --local --agent kept --message hello
[exit 0]
$ ls -A <state>/workspace-kept
  AGENTS.md IDENTITY.md SOUL.md USER.md

# control, both trees
$ openclaw templates add <run>/control
[exit 0]
$ ls -A <state>/workspace-control
  BOOTSTRAP.md SOUL.md
$ openclaw agent --local --agent control --message hello
$ ls -A <state>/workspace-control
  AGENTS.md BOOTSTRAP.md IDENTITY.md SOUL.md USER.md

Tests: "retains package bootstrap custody through a fresh process after setup fails" in src/templates/conversation.workspace.test.ts now gives the kept agent its defaults the way the offline CLI does, runs ensureAgentWorkspace in a fresh process, and expects AGENTS.md IDENTITY.md SOUL.md USER.md, the Template SOUL.md unchanged, no setupCompletedAt, and that seedTemplatePackageBootstrap still seeds the package BOOTSTRAP.md. With the helper doing nothing (main's behavior) it fails with expected [ 'SOUL.md' ] to deeply equal [ 'AGENTS.md', 'IDENTITY.md', …(2) ]. Two more rows defer a workspace and seed it with skipOptionalBootstrapFiles: ["USER.md"] and with skipBootstrap: true; with the helper from e15f086 they fail with expected [ 'AGENTS.md', 'IDENTITY.md', …(2) ] to deeply equal [ 'AGENTS.md', 'IDENTITY.md', …(1) ] and … to deeply equal []. node scripts/test-projects.mts src/templates/conversation.workspace.test.ts src/cli/templates-cli.test.ts src/cli/templates-agent-conversation.test.ts src/agents/workspace.test.ts --maxWorkers=1 passes (91 tests). pnpm tsgo:core, pnpm tsgo:test:src, targeted oxlint, format check, pnpm check:import-cycles and git diff --check pass.

Merge risk: two-way door; reverting brings back the bare kept workspace with no state or config migration. Blast radius is offline openclaw templates add runs that end partial with the agent kept and a held package bootstrap.

Current-head CI qualification

CI run 43770661392, attempt 2 completed with one inherited updater-test failure. Its candidate-admission test still expects the old joined Failing check node-runtime output; upstream 764761ee6450 intentionally changed this path to a one-line refusal plus recovery steps and updated the analogous target-schema test, leaving this assertion behind. The refusal and no-side-effect checks pass before that formatting assertion.

The actual tested merge f182b244ade18deffa10e28c083da923dd9973d0 has protected-main parent 5b750071d1d31b2af9c8d2e58d0f65da010845dc and this exact PR head 7b69a60f36cdd3661b29cfe3dfc7a52dd3aeb126. Its complete four-file delta leaves the failing updater, report, fixture, runner and dependency inputs unchanged. All other independent CI leaves passed or were normally skipped. The failed run remains failed; the 97 focused tests and type/lint/format proof above passed. Landing uses the repository's narrowly scoped inherited-CI qualification, preserving security and enforced review gates.

When offline Add keeps the agent after a later step fails, the CLI now
writes the default AGENTS.md, IDENTITY.md and USER.md into its
workspace. The package BOOTSTRAP.md stays held, as openclaw#196392 intends,
so a completed setup can still seed it.
@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes agents Agent runtime and tooling size: S labels Nov 14, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: ready, awaiting a maintainer decision.

What this changes

This PR seeds permitted default instruction files after a failed offline Template Add retains an agent, while keeping package bootstrap deferred.

Example: Offline Add creates agent kept, then its opening model request fails.

  • Before: workspace-kept contains only SOUL.md, even after a subsequent agent turn.
  • After: With ordinary bootstrap settings, AGENTS.md, IDENTITY.md and USER.md are also present; package BOOTSTRAP.md remains withheld.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch resolves the prior defect and has relevant CLI proof; partial recovery and the outstanding owner direction cap overall readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Supplied terminal traces exercise the real offline CLI with isolated state and a local compatible model endpoint: failed Add retains permitted defaults, subsequent turns preserve them, package bootstrap stays absent, and successful Add plus skipBootstrap controls retain their expected behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: A retained offline Template agent continues running without its ordinary default instructions after Add fails.
Reason: The repair offers clear bounded value, but changes the feature owner's deliberate defaults-deferral behavior and leaves package-bootstrap recovery unresolved.

Merge readiness

⏳ Ready, awaiting maintainer decision

Keep this PR open: it addresses a current failure, resolves the earlier suppression-setting finding, and has no remaining concrete correctness findings; a Templates owner should decide whether to ship this partial recovery.

Priority: P2
Reviewed head: edab73ce2d97d08edb92aa723262608ade9b9b11
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should failed offline Add seed default instructions while package BOOTSTRAP.md remains deferred, as this PR proposes?
  • Recommendation: Ship the defaults-only repair: Accept the bounded improvement and keep [Bug]: Template agent kept after a failed Add never receives BOOTSTRAP.md or the default workspace files #198744 open for same-agent package-bootstrap recovery.
  • Why: The existing feature intentionally withheld defaults under initializer custody; the contributor gives a sound reason for this narrow exception, but no recorded owner approval settles that change or the linked issue's broader recovery expectation.

Before merge

None.

Findings

None.

Agent review details

How this fits together

The offline Templates CLI consumes the shared installer's retained partial result and asks the workspace preparation owner to publish missing default instructions for later agent turns.

flowchart TD
A[Offline Templates CLI] --> B[Shared Add installer]
B --> C[Retained partial result]
C --> D[Workspace preparation owner]
D --> E[Exclusive file publisher]
E --> F[Default instruction files]
F --> G[Later agent turn]
Loading

Technical review

Best possible solution:

Seed permitted defaults through existing workspace owners while preserving package-bootstrap custody and tracking complete recovery separately.

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

Current-main source confirms durable deferral suppresses defaults after retained failure, and the contributor supplies matching CLI traces; this read-only review executed no target code.

Is this the best way to solve the issue?

The smallest complete fix for the stated defaults problem fits the existing preparation owner, preserves existing files and suppression settings, and avoids invalidating Gateway checkpoints; it intentionally does not complete the linked issue's package-bootstrap recovery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 088178a6559f.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Exact introduced change: The pinned introduction adds an offline-only recovery call and a workspace-owner operation using the existing preparation queue and exclusive-create publisher. (src/agents/workspace-preparation.ts:50, edab73ce2d97)
  • Earlier finding resolved: The CLI now passes agents.defaults; the seeder honors skipBootstrap and filters skipOptionalBootstrapFiles, matching ordinary CLI preparation. (src/cli/templates-cli.runtime.ts:488, edab73ce2d97)
  • Current-main failure remains: Current main's four affected files match the introduction base: retained failure preserves bootstrap deferral, and ensureAgentWorkspace returns before creating defaults while that flag remains set. (src/agents/workspace.ts:592, 088178a6559f)
  • Original custody contract: Merged feat(templates): open durable chat before verified setup #196392 deliberately persisted initializer custody across ordinary turns and restarts; this PR explains its narrower defaults-only exception while preserving package-bootstrap ordering. (src/agents/workspace-preparation.ts:17, caa978caae7a)
  • Gateway recovery boundary: workspaceIdentity inventories workspace entries and contents, supporting the PR's decision to keep default-file publication outside the shared installer and Gateway retry path. (src/templates/add-checkpoint.ts:16, edab73ce2d97)
  • Contributor's shipped-CLI evidence: The full PR body supplies before/after offline Add and subsequent agent-turn terminal traces, a successful-Add control, a skipBootstrap control, and reported red/green regressions; the model endpoint is explicitly a local compatible stub. (edab73ce2d97)

Likely related people:

  • Patrick Erichsen: Raw commit caa978c adds src/agents/workspace-preparation.ts:8 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: caa978caae7a; files: src/agents/workspace-preparation.ts)

PR surface

Source +56, Tests +24, Docs +3. Total +83 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 57 1 +56
Tests 1 25 1 +24
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 85 2 +83

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The repair addresses missing agent instructions after a later failure in the Labs-enabled offline CLI workflow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-14T18:46:55.720Z sha e15f086 :: blocked before merge. :: [P2] [P2] Honor the configured bootstrap-file suppression settings

Reviewed November 14, 2026, 3:41 PM ET / 20:41 UTC (Revision 2).

Offline Add now applies agents.defaults.skipBootstrap and skipOptionalBootstrapFiles when it gives a kept agent its default files, matching ordinary CLI preparation.
@anmol0b

anmol0b commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 14, 2026
@anmol0b
anmol0b marked this pull request as ready for review November 14, 2026 20:55
@Patrick-Erichsen
Patrick-Erichsen merged commit 9d62664 into openclaw:main Nov 15, 2026
127 of 130 checks passed
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

@anmol0b
anmol0b deleted the fix/templates-kept-agent-bootstrap branch November 15, 2026 23:26
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…penclaw#199082)

* fix(templates): agent kept by a failed offline Add has no AGENTS.md

When offline Add keeps the agent after a later step fails, the CLI now
writes the default AGENTS.md, IDENTITY.md and USER.md into its
workspace. The package BOOTSTRAP.md stays held, as openclaw#196392 intends,
so a completed setup can still seed it.

* fix(templates): kept agent's default files honor bootstrap suppression

Offline Add now applies agents.defaults.skipBootstrap and skipOptionalBootstrapFiles when it gives a kept agent its default files, matching ordinary CLI preparation.

* fix(templates): retain workspace evidence while seeding kept defaults

---------

Co-authored-by: Patrick Erichsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants