Skip to content

fix(system-agent): apply approved proposal exactly once - #119389

Merged
sallyom merged 1 commit into
openclaw:mainfrom
Cuttingwater:fix/system-agent-exact-approval
Aug 5, 2026
Merged

sallyom merged 1 commit into
openclaw:mainfrom
Cuttingwater:fix/system-agent-exact-approval

Conversation

@Cuttingwater

@Cuttingwater Cuttingwater commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #119387.

A delegated system-agent can freeze a persistent operation in agentSession.proposalRef.operation, bind it to a stable hash, and publish that proposal for human approval. On current main, approving that hash does not execute the frozen operation. The approval helper discards proposal.operation, emits a synthetic approval chat message, and starts a second model turn with approvalArmed: true.

That makes the operator-visible approval non-authoritative: the post-approval model can return a different directive, return no directive, or fail before applying anything. The operation that runs is reconstructed by inference rather than being the immutable operation the human approved.

Why This Change Was Made

The approval boundary already owns the authoritative { operation, hash } pair. The canonical fix is to preserve that object through the decision helper and apply the exact operation at the existing approved-operation executor.

This change:

  • keeps exact hash comparison before any effect;
  • passes the verified proposal.operation through resolveOperatorApprovalDecision;
  • clears both pending proposal stores before execution, so authority is one-shot even when execution fails;
  • calls applyApprovedPersistentOperation(operation) directly;
  • removes the second model turn from the approval path;
  • makes host-seeded and agent-loop proposals use the same exact-operation apply path;
  • records a source-neutral [proposal-resolved] marker for the next conversational turn.

Rejected alternative: keeping the synthetic message and strengthening its prompt still delegates an operator-owned security decision back to probabilistic inference. The exact operation is already available, so another model round trip is neither necessary nor the approved action.

Adjacent work is unaffected: #117432 addresses delegated messaging handoff/copy, while #118960 addresses gateway approval-bus routing. Neither changes this post-approval execution boundary.

Production delta: +17/-14 across the approval helper and chat engine. Test delta: +25/-11.

User Impact

System-agent approvals now apply exactly the persistent operation shown to and approved by the operator. They no longer depend on a provider/model response after approval.

A wrong hash remains a no-op. A duplicate approval callback remains a no-op. Delivery, approval UI, proposal hashing, operation validation, inference binding checks, post-write verification, and audit behavior are unchanged.

Evidence

Verified after rebasing onto fetched upstream/main 50c7444edf4be40a075d3689bec8fd5b676c2843; exact PR head 7c1df916dd9beba99655525d77c673fb406143a1.

Isolated real-write approval canary

The after-fix canary used a fresh temporary OPENCLAW_STATE_DIR and OPENCLAW_CONFIG_PATH, the production SystemAgentChatEngine, production approval resolver, production operation executor, and production config writer. It queued one delegated config-set, resolved a wrong hash, approved the exact hash, retried the same callback, and read the persisted config back from disk.

It did not start a Gateway, use the household config, or touch ~/.openclaw.

./node_modules/.bin/tsx /tmp/openclaw-system-approval-canary.mts
{
  "liveStateUntouched": true,
  "queuedForOperator": true,
  "wrongHashNoOp": true,
  "appliedExactlyOnce": true,
  "duplicateNoOp": true,
  "modelTurns": 1,
  "persistedGatewayPort": 19001
}

The temporary config began with gateway.port = 18789. The exact approved operation persisted 19001. No second model turn ran, and the temp state directory was removed after verification.

Focused tests

node scripts/run-vitest.mjs \
  src/system-agent/chat-engine.test.ts \
  src/gateway/server-methods/system-agent.test.ts
Test Files 2 passed (2)
Tests 132 passed (132)

The regression coverage proves the initial proposal capture, wrong-hash no-op, exact operation/value delivery, one-shot consumption, duplicate no-op, source-neutral next-turn marker, and gateway session notification.

Static checks

./node_modules/.bin/oxfmt --check \
  src/system-agent/operator-approval.ts \
  src/system-agent/chat-engine.ts \
  src/system-agent/chat-engine.test.ts

./node_modules/.bin/oxlint --type-aware --deny-warnings \
  src/system-agent/operator-approval.ts \
  src/system-agent/chat-engine.ts \
  src/system-agent/chat-engine.test.ts

git diff --check upstream/main...HEAD

All passed.

Independent review

.agents/skills/autoreview/scripts/autoreview \
  --mode branch --base upstream/main --max-priority P1
trufflehog: clean
autoreview clean: no accepted/actionable findings reported
overall: patch is correct (0.91)

AI-assisted by Codex. The source path, authorization invariant, callers, sibling paths, focused tests, isolated real-write behavior, and final diff were reviewed before submission.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 10:22 PM ET / August 5, 2026, 02:22 UTC.

ClawSweeper review

What this changes

The PR makes system-agent operator approval consume and directly execute the hash-verified stored persistent operation once instead of starting another model turn to recreate it.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still reconstructs an agent-loop-approved operation through a second model turn, while this exact head replaces that path with the shared guarded executor and has no blocking review finding.

Priority: P1
Reviewed head: 7c1df916dd9beba99655525d77c673fb406143a1

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong production-path proof and a focused owner-boundary repair support an above-average review rating.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body supplies an isolated production-path canary showing one persisted exact operation, wrong-hash and duplicate no-ops, and no post-approval model turn.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies an isolated production-path canary showing one persisted exact operation, wrong-hash and duplicate no-ops, and no post-approval model turn.
Evidence reviewed 6 items Current-main defect: Current main's approval helper retains only the hash and passes synthetic approval text to its callback; the engine sends agent-loop proposals into a new assistant turn instead of the existing direct executor.
Exact-head repair: The PR verifies the stored proposal hash, clears both proposal stores before execution, and passes the retained operation directly to the persistent-operation executor.
Existing safeguards remain on the execution boundary: Direct approval still uses the shared executor, whose guarded commit revalidates inference immediately before each persistent effect and writes the audit result afterward.
Findings None None.
Security None None.

How this fits together

A system-agent turn can retain a hash-bound persistent operation while an operator approves it through the Gateway. The resolver validates and consumes that proposal, then the chat engine applies it through the persistent-operation executor, audit, and post-write verification flow.

flowchart LR
A[System-agent turn] --> B[Stored hash-bound operation]
B --> C[Gateway operator approval]
C --> D{Hash matches?}
D -->|No| E[No-op]
D -->|Yes| F[Consume proposal]
F --> G[Guarded persistent executor]
G --> H[Audit and verified outcome]
Loading

Before merge

  • Resolve merge risk (P1) - Required checks for this exact head were still running at review time; merge only after the normal exact-head GitHub gate is green.
  • Complete next step (P2) - No repair action is needed; this open PR already owns the defect, pending normal exact-head checks and maintainer merge review.
Agent review details

Security

None.

PR surface

Source +3, Tests +14. Total +17 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 17 14 +3
Tests 1 25 11 +14
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 42 25 +17

Review metrics

Metric Value Why it matters
Production vs test LOC production +17/-14, tests +25/-11 The small production increase establishes the approval ownership boundary, with regression coverage for exact payload, one-shot consumption, and no second model turn.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #119387
Summary: This PR is the concrete candidate fix for the canonical issue's agent-loop approval execution defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one authoritative hash-bound operation path for both agent-loop and host-seeded approvals, and land this repair after the exact-head gate passes.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one authoritative hash-bound operation path for both agent-loop and host-seeded approvals, and land this repair after the exact-head gate passes.

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

Yes. Current source gives a direct path: an agent-loop proposal supplies a stored operation and matching hash, then operator approval invokes a second model turn; the submitted isolated production-path canary demonstrates the repaired path with a persisted write and duplicate no-op.

Is this the best way to solve the issue?

Yes. Applying the already hash-verified operation at the approval owner removes probabilistic reconstruction while retaining the shared executor's inference revalidation, audit, and post-write checks.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: A current operator-approval path for persistent operations can fail to apply the exact approved action because it delegates that decision back to model inference.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body supplies an isolated production-path canary showing one persisted exact operation, wrong-hash and duplicate no-ops, and no post-approval model turn.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an isolated production-path canary showing one persisted exact operation, wrong-hash and duplicate no-ops, and no post-approval model turn.

Evidence

What I checked:

  • Current-main defect: Current main's approval helper retains only the hash and passes synthetic approval text to its callback; the engine sends agent-loop proposals into a new assistant turn instead of the existing direct executor. (src/system-agent/chat-engine.ts:745, 50c7444edf4b)
  • Exact-head repair: The PR verifies the stored proposal hash, clears both proposal stores before execution, and passes the retained operation directly to the persistent-operation executor. (src/system-agent/operator-approval.ts:40, 7c1df916dd9b)
  • Existing safeguards remain on the execution boundary: Direct approval still uses the shared executor, whose guarded commit revalidates inference immediately before each persistent effect and writes the audit result afterward. (src/system-agent/operations-execution-helpers.ts:256, 7c1df916dd9b)
  • Focused regression coverage: The changed test covers a wrong hash, the exact config-set payload, duplicate-callback no-op, one write, no second armed model turn, and source-neutral next-turn context. (src/system-agent/chat-engine.test.ts:368, 7c1df916dd9b)
  • Gateway caller and sibling path: The Gateway carries the frozen proposal hash into the serialized resolver, while host-seeded proposals already use the same direct executor; the Gateway test exercises a real restart and audit completion. (src/gateway/server-methods/system-agent.ts:249, 50c7444edf4b)
  • Head provenance: The reviewed PR commit is a direct child of current main and is not contained by a local release tag, so the fix is neither on main nor shipped. (7c1df916dd9b)

Likely related people:

  • Peter Steinberger: The system-agent delegation feature dates to this commit, with further verified-route work in the same area. (role: feature origin and sustained area contributor; confidence: high; commits: b1f4aac349f9, d96a5e2c9ebe; files: src/system-agent/agent-turn.ts, src/system-agent/chat-engine.ts)
  • Jesse Merhi: Recent system-agent fixes touch the same chat-engine surface. (role: recent chat-engine contributor; confidence: medium; commits: 9aceb1620d4f, aa743c9f8186; files: src/system-agent/chat-engine.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-05T01:02:30.464Z sha 1ef898292ca4b9e0ebb29f87ab8bc9d967771a7c :: needs real behavior proof before merge. :: [P3] Use a source-neutral marker after agent-loop approval
  • reviewed 2026-08-05T02:04:02.354Z sha b7bb45e1cccf0b0c95e53b33ec501dde7c66a3fc :: needs maintainer review before merge. :: none
  • reviewed 2026-08-05T02:11:35.806Z sha b7bb45e1cccf0b0c95e53b33ec501dde7c66a3fc :: needs maintainer review before merge. :: none

@Cuttingwater

Copy link
Copy Markdown
Contributor Author

Addressed both review moves at b7bb45e1cccf0b0c95e53b33ec501dde7c66a3fc.

  • Replaced the host-specific follow-up marker with source-neutral [proposal-resolved] context and added next-turn coverage.
  • Added isolated real-write evidence: a controlled delegated proposal and non-live inference fixture entered the production SystemAgentChatEngine; the production approval resolver, operation executor, config writer, verification, and audit path then changed a temporary on-disk config from port 18789 to 19001.
  • Wrong hash and duplicate callback both returned null; one exact write occurred; model turn count stayed at one.
  • Live ~/.openclaw state was not read or changed.
  • Focused tests: 132/132.
  • Targeted format, type-aware lint, and diff checks passed.
  • Fresh autoreview: TruffleHog clean, no P0/P1 findings, patch correct (0.87).

The PR body now contains the command and redacted canary result.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 5, 2026
@Cuttingwater
Cuttingwater force-pushed the fix/system-agent-exact-approval branch from b7bb45e to 7c1df91 Compare August 5, 2026 02:16

Copy link
Copy Markdown
Contributor Author

Final exact-head refresh: 7c1df916dd9beba99655525d77c673fb406143a1 is rebased onto fetched upstream/main 50c7444edf4be40a075d3689bec8fd5b676c2843. Focused tests remain 132/132; format, type-aware lint, diff check, TruffleHog, and fresh branch autoreview pass with no P0/P1 findings. The isolated production-path canary again changed only a temporary config from port 18789 to 19001, with wrong-hash and duplicate callbacks both no-op and modelTurns: 1.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 5, 2026
@sallyom sallyom self-assigned this Aug 5, 2026

sallyom commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merge-ready at HEAD 7c1df916dd9beba99655525d77c673fb406143a1: CI is green, manual review and independent P1 autoreview are clean, and this is the best narrow fix at the approval owner boundary.

@sallyom
sallyom merged commit f0a7497 into openclaw:main Aug 5, 2026
129 of 131 checks passed
@sallyom

sallyom commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System-agent UI approval reruns the model instead of applying the exact frozen operation

2 participants