Skip to content

fix(templates): earlier Template agents fail every turn after a config edit - #196338

Closed
anmol0b wants to merge 7 commits into
openclaw:mainfrom
anmol0b:fix/claw-managed-tools-consent
Closed

anmol0b wants to merge 7 commits into
openclaw:mainfrom
anmol0b:fix/claw-managed-tools-consent

Conversation

@anmol0b

@anmol0b anmol0b commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #190694

What Problem This Solves

Fixes: an agent enrolled by the earlier claws add / claws migrate lifecycle refuses every turn when its config is changed, for example with openclaw config set agents.entries.<id>.tools.exec '{"mode":"full"}'. The error (configuration does not match its consent provenance) tells the operator to repair the state database, and there is no supported way to keep the change. This still reproduces on the latest stable, v2026.11.2.

User Impact

With the Gateway stopped, an operator can review and release the agent:

openclaw templates release <agent-id>

The agent then runs with the operator's settings and keeps its workspace, sessions, cron jobs, MCP servers, and plugins. The runtime error now names this command. Agents added on current main are unaffected; they have no consent record.

This changes how historical consent provenance can end, so it needs an owner decision and a security review. No CODEOWNERS rule or security-review-policy.yml class covers src/templates/**, so it needs to be routed to openclaw-secops by hand.

Why This Change Was Made

Add has created ordinary agents since #171623, and #175577 deliberately kept the legacy consent check fail-closed. That check is unchanged here. The missing piece was an explicit operator action that moves a legacy agent onto the ordinary-agent model, as ClawSweeper recommended on the issue.

  • templates release uses the same exclusive offline ownership as templates add (runWithLocalStateOwner with onForeignOwner: "refuse"). No Gateway method or protocol change.
  • The write is one worker operation (templateRelease.apply). Its admission rechecks offline custody (the owner's assertCurrent: the state lock is still held and no exit signal has arrived) at both the transaction and commit stages. Inside the transaction it re-reads the install record and deletes only if the schema version and digest still match what the operator reviewed.
  • It then removes that agent's rows from template_installs, template_workspace_files, template_package_refs, template_mcp_server_refs, and template_cron_refs. On main, the only runtime reader of those child tables is Add's package rollback guard, which also requires its own install stamp. So jobs, servers, and plugins are left alone (shown below).
  • The digest comparison moved into matchTemplateConsent, shared by the runtime and the command. A mismatch is now its own result with an actionable message, instead of a state error.
  • Manifests still reject tools.exec and tools.message, so a Template cannot grant full exec or cross-provider messaging at Add. The docs say to set them after Add.
Root cause

src/templates/tool-policy-runtime.ts compared the live agent config digest with the one in the legacy install record, and turned any mismatch into a state error. The digest covers the whole agent entry except model and subagents, so any edit trips it; on main, renaming the agent (name) also blocks it. Undoing the edit was the only recovery.

Evidence

All runs used an isolated HOME, OPENCLAW_STATE_DIR, and Gateway port, with scripts/e2e/mock-openai-server.mjs as the model. API keys are mock values.

Upgrade path: 2026.10.9 → latest stable 2026.11.2 → this branch

Agent ops was created by 2026.10.9 claws add from a package declaring a cron job and an MCP server. Each version ran doctor --fix on the previous version's state.

On 2026.11.2 (b556fdf):

  • The untouched agent runs: "text": "OPENCLAW_E2E_OK".
  • After config set agents.entries.ops.tools.allow '["read","exec"]' and config set agents.entries.ops.tools.exec '{"mode":"full"}', the turn fails: Cannot verify the installed tool authority for Claw-managed agent "ops". Repair the OpenClaw state database before running it. | Claw agent configuration does not match its consent provenance.
  • templates release gives OpenClaw does not know the command "templates".

On this branch, same state:

  1. doctor --fix exits 0. Before release, the install, cron, and MCP ref rows for ops are each 1.
  2. templates release ops --yes prints Its settings changed after the Template consent was recorded., Tool settings it keeps: {"profile":"full","allow":["read","exec"],"exec":{"mode":"full"}}, and Released ops., exit 0. All three ref counts are now 0.
  3. Resources intact: the stored job 7211420c-…|ops|Daily summary|1 in cron_jobs is unchanged, and mcp list still shows statuspage. config get agents.entries.ops.tools still has exec.mode: "full".
  4. Real exec call after restart: a turn with OPENCLAW_E2E_DRAFTPROOF makes the model call exec with sleep 2 && echo openclaw-draft-proof, a compound command. The turn completes, and the captured model request contains the tool output openclaw-draft-proof.

Authority boundary (worker, enrolled by 2026.10.9 claws migrate)

  • With the Gateway running: Cannot admit templates.release ... requires exclusive offline state ownership. No local mutation was attempted., exit 1.
  • Gateway stopped, no --yes, non-TTY stdin: Release not confirmed., exit 1, install row still present.
  • --yes releases it. After a restart the turn completes, and a second release prints Nothing to release.
  • Custody ending after confirmation: covered by a test. The operator confirms, then SIGINT goes through the CLI's real signal-exit path before the delete. The command rejects and consent stays enforced. On the previous head (0606c13) the same test fails (promise resolved "undefined" instead of rejecting): the delete committed after the signal. This revision adds the custody recheck.

Edge case

When agents.defaults.models is set, adopted consent cannot be recomputed. The agent is blocked with the state-database message on both main and this branch (the #193383 symptom). Release prints Its settings cannot be compared with the Template consent: ..., releases, and the next turn completes.

Tests and gates

  • src/cli/templates-cli.release.test.ts (3 tests) uses a real SQLite install record and real state-lock custody: release unblocks an edited agent after restart; an unconfirmed release keeps consent; custody lost after confirmation keeps consent.
  • src/templates/tool-policy-runtime.preparation.test.ts was updated for the release guidance. With the production files reverted to the base it fails on the old message.
  • src/templates/schema.test.ts pins the CLAW.md manifest rejection of tools.exec and tools.message (moved there after feat: configure Templates in one CLAW.md manifest #196322 folded profiles into CLAW.md). It passes on main too; the schema is intentionally unchanged.
  • pnpm test on the touched suites and consumers (templates-cli, templates-cli.state-owner, openclaw-state-worker-registry, tool-policy-runtime, io.runtime-models, tool-policy-pipeline, agent-tools.prefix-stability) passes.
  • These also pass: pnpm tsgo:core; run-oxlint and run-format --check on the touched files; git diff --check; check:test-lines-ratchet.

Gaps

  • The state lock being taken over by another process is not exercised separately. It goes through the same assertCurrent as the signal case.
  • The "record changed during review" refusal inside the worker transaction has no test.
  • cron list does not show the ops job after a Gateway restart on 2026.10.9 itself, before any upgrade, although the row stays in cron_jobs. Release does not touch cron_jobs. That listing behavior predates this change.

Merge risk: two-way door. Reverting removes the command and restores the old message. Released agents stay ordinary, since their records are deleted, and need no migration. Blast radius is agents that still have a legacy Template install record.

Agents enrolled by the earlier installed-Template lifecycle (claws add or
claws migrate) refuse every turn after any edit to their config, such as
setting tools.exec.mode=full, and the error told operators to repair the
state database. Add is now one-way, so there was no supported way to keep
the change.

Add `openclaw templates release <agent-id>`. It needs exclusive offline
state ownership, shows the agent's tool settings and whether they still
match the recorded consent, asks for confirmation (--yes in scripts), and
removes that agent's Template ownership rows in one transaction after
re-reading the install record. The agent, workspace, sessions, cron jobs,
MCP servers, and plugins stay as ordinary resources.

A config mismatch now gets its own error naming the release command.
Template profiles still cannot set tools.exec or tools.message.
@clawsweeper

clawsweeper Bot commented Nov 10, 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 size: M labels Nov 10, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: stale review; fresh review needed.

Summary
The latest durable ClawSweeper review was for head 5d65938e56c1169d87c6125ef625eacc9e080c67, but the PR head is now 1ab986cd6ecfcdd144b822879eb486a95ffaf8f0. Its old verdict and PR readiness labels are no longer current.

Next step
Comment @clawsweeper re-review when the current head is ready; pushes after the first review are not reviewed automatically.

Review history (3 earlier review cycles)
  • reviewed 2026-11-10T00:37:24.326Z sha 0606c13 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-10T08:46:37.856Z sha ce22b86 :: blocked before merge. :: none
  • reviewed 2026-11-10T20:14:44.823Z sha 5d65938 :: needs real behavior proof before merge. :: none

The release delete only checked database admission, so a signal or lost state lock after the operator confirmed still let it commit. Recheck the offline owner's custody in the write admission at the transaction and commit stages, and cover custody ending after confirmation.
…ols-consent

# Conflicts:
#	docs/cli/templates.md
@anmol0b

anmol0b commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

The Templates lifecycle is now one-way Add (#171623), and #175577 kept legacy consent fail-closed. That leaves agents enrolled by the earlier claws add / claws migrate with no way to keep an intentional config change: any edit makes every turn fail. I reproduced this on v2026.11.2.

#196338 proposes an explicit, offline, operator-confirmed release. It removes only that agent's Template ownership records, keeps the agent and its resources, and keeps the consent check itself unchanged. Template manifests still cannot grant tools.exec or tools.message.

Is this transition acceptable to the Templates owners? If not, which recovery would you prefer?

@anmol0b

anmol0b commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@anmol0b
anmol0b marked this pull request as ready for review November 10, 2026 11:32
@clawsweeper clawsweeper Bot removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Nov 10, 2026
@anmol0b

anmol0b commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
…ols-consent

# Conflicts:
#	docs/cli/templates.md
#	src/templates/openclaw-profile.test.ts
@clawsweeper clawsweeper Bot removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 17, 2026
Patrick-Erichsen added a commit that referenced this pull request Nov 17, 2026
* fix(templates): release earlier Template-managed agents

Let operators release an earlier Template-managed agent after an intentional
configuration edit while retaining its agent, workspace, conversation and
integrations. Require explicit confirmation and exclusive offline custody,
recheck that custody at the write, and remove only its Template ownership
records. Point changed-consent errors at the supported recovery command.

Maintainer-owned replacement of #196338
from source 1ab986c, preserving Anmol's
implementation and subsequent main documentation and test changes.

Co-authored-by: Anmol Bhardwaj <[email protected]>

* docs(templates): align release guidance with preferred models

---------

Co-authored-by: Anmol Bhardwaj <[email protected]>
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Landed and verified in credited maintainer replacement #200303 (merge d46027380a1872e669f93e3544e9925098d4a72c). It preserves Anmol Bhardwaj’s implementation and co-author credit while retaining current-main documentation and test integration.

Closing this original as superseded after replacement merge and verification. The replacement records its focused regression/upgrade proof, limitations and the specifically qualified unrelated Windows updater CI failure.

Exact merged-commit security, documentation publishing and workflow checks passed.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
)

* fix(templates): release earlier Template-managed agents

Let operators release an earlier Template-managed agent after an intentional
configuration edit while retaining its agent, workspace, conversation and
integrations. Require explicit confirmation and exclusive offline custody,
recheck that custody at the write, and remove only its Template ownership
records. Point changed-consent errors at the supported recovery command.

Maintainer-owned replacement of openclaw#196338
from source 1ab986c, preserving Anmol's
implementation and subsequent main documentation and test changes.

Co-authored-by: Anmol Bhardwaj <[email protected]>

* docs(templates): align release guidance with preferred models

---------

Co-authored-by: Anmol Bhardwaj <[email protected]>
@anmol0b
anmol0b deleted the fix/claw-managed-tools-consent branch November 17, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Claw-managed agents cannot get tools.exec.mode=full or crossContext: live set breaks consent, manifest rejects the keys

2 participants