Skip to content

fix(agents): preserve tool authority through hook rebuilds - #159532

Merged
steipete merged 1 commit into
mainfrom
codex/preserve-tool-authority
Sep 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/preserve-tool-authority

Conversation

@steipete

@steipete steipete commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Crabbox create-and-show requests failing with Environment screen has no matching captured tool authority before a machine is provisioned.

User Impact

Agents can open an authorized Crabbox portal or desktop beside the conversation. Captured permission denials, cancellation, and live-run authority remain enforced throughout the call.

Why This Change Was Made

Rebuilding before_tool_call hooks restored the original tool body and dropped the surrounding caller and lifetime wrappers. Preserve those wrappers in their original order through the existing metadata owner, and retain the final source-execution guard through catalog rebuilding and plugin views. This also prevents effects or result delivery after the admitted run ends during preparation or finalization.

Evidence

  • Regression coverage exercises real host binding, catalog dispatch, the environment handler, and sidebar command delivery with isolated state and a fake provisioning provider. Allowed requests reach presentation; captured denials prevent provisioning.
  • Additional regressions cover caller identity and cancellation during preparation, plus revocation before source execution and result delivery, including plugin views.
  • All seven new regression cases demonstrably failed on original production code and pass with this change; 13 tests across the two regression files pass. The five host/catalog cases reproduce the reported missing-authority error and the lost source/result guards.
  • 329 existing sibling tests pass, covering tool search, Code Mode, caller context, host capabilities, activity, and before-tool-call integration. The source-only integration fixture used its documented OPENCLAW_E2E_SKIP_BUILD=1 route after default setup refused to rebuild artifacts associated with an active local Gateway.
  • node scripts/check-changed.mjs and git diff --check pass, including core/test typechecks, lint, import-cycle and dead-export checks.
  • Measured with pnpm test <file> --maxWorkers=1: metadata regression file 99.44 s wall including cold shared worker compilation (under 0.1 s test execution); host delegation file 31.65 s wall (about 8.2 s test execution). The latter uses the real environment and UI-dispatch owners with isolated SQLite state to cover the composition the previous helper tests missed. Exact-head CI passed in 837 s overall (including all selected jobs).
  • Deslop completed. Independent Codex review and exact-head ClawSweeper review found no actionable findings; no live Gateway or cloud lease was used for validation.

@clawsweeper

clawsweeper Bot commented Sep 27, 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 agents Agent runtime and tooling size: M labels Sep 27, 2026
@steipete
steipete marked this pull request as ready for review September 27, 2026 08:14
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 27, 2026, 5:12 AM ET / 09:12 UTC (Revision 2).

ClawSweeper review

What this changes

The branch preserves caller, cancellation, activity, and run-lifetime wrappers when agent tool hooks are rebuilt, and adds regression tests and Code Mode maintainer guidance.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main and the latest release still lack the wrapper replay needed for this reported path. The branch is a focused fix with regression coverage through catalog dispatch and the Gateway environment handler; this review found no actionable patch defect.

Priority: P2
Reviewed head: a236b76b4d5d27038996765715e058efa1abfa79

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused repair and boundary regressions provide good review confidence, with live cloud behavior left unclaimed.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The supplied repository state identifies a member-authored PR, so the external-contributor proof gate does not apply. Production-path catalog and Gateway-handler tests use an injected provider to check allowed, denied, and revoked effects; the body does not claim a live cloud run. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a member-authored PR, so the external-contributor proof gate does not apply. Production-path catalog and Gateway-handler tests use an injected provider to check allowed, denied, and revoked effects; the body does not claim a live cloud run. No stored-data contract changes.
Evidence reviewed 10 items Wrapper preservation: The introduced metadata records execution wrappers, and hook rebuilding reapplies them around the rebuilt tool.
Final source guard: The rebuilt hook retains source-execution guards; the hook checks that guard after awaited preparation and before source execution.
Allowed and denied effects: The new test calls Tool Search through the production environment handler with an injected provisioning provider. It checks that an allowed call reaches provisioning and the UI command, while denied screen authority reaches neither.
Findings None None.
Security None None.

How this fits together

OpenClaw assembles agent tools, wraps them with hooks and run authority, and exposes them directly or through Tool Search. The Gateway uses the resulting caller authority to decide whether an environment can be created and shown beside a conversation.

flowchart LR
 A[Agent run] --> B[Tool assembly]
 B --> C[Hook rebuild]
 C --> D[Tool Search call]
 D --> E{Caller and run authorized?}
 E -- Yes --> F[Environment and UI command]
 E -- No --> G[Denied result]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +67, Tests +317, Docs +6. Total +390 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 8 86 19 +67
Tests 2 317 0 +317
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 409 19 +390

Review metrics

Metric Value Why it matters
Production and test growth production +67 net lines; tests +317 net lines The production growth preserves existing authority wrappers, while the test growth exercises catalog dispatch and revocation at the affected boundary.
New host regression cost 8.2 s test execution; 31.65 s wall The PR records the cost of the production-composition test and explains its broader setup.

Technical review

Best possible solution:

Keep one metadata-owned wrapper chain so direct, catalog, and plugin-view calls retain their admitted caller and reject revoked work before effects or result delivery.

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

Yes, from source: current main rebuilds a hook around the source execute function without replaying outer wrappers, and the submitted catalog regression targets the resulting missing-authority error. This read-only review did not execute the tests or a live Gateway.

Is this the best way to solve the issue?

Yes. Recording and replaying the existing wrappers at their metadata owner repairs the lost authority path while the Gateway keeps its final authorization checks.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded agent-tool workflow defect with focused regression coverage.
  • merge-risk: 🚨 security-boundary: The patch changes how caller and run authority survive tool rebuilding; the denied and revoked cases are therefore material to merge review.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies a member-authored PR, so the external-contributor proof gate does not apply. Production-path catalog and Gateway-handler tests use an injected provider to check allowed, denied, and revoked effects; the body does not claim a live cloud run. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Sarah Fortune: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (1 earlier review cycle)
  • reviewed 2026-09-27T08:22:11.206Z sha a236b76 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 0ce91c7 into main Sep 27, 2026
272 of 274 checks passed
@steipete
steipete deleted the codex/preserve-tool-authority branch September 27, 2026 09:18
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

1 participant