Repository navigation
fix: node turns bypass before_agent_run policies - #164270
Conversation
Run before_agent_run under the retained plugin generation before node input persistence or worker launch. Reuse the local/CLI fail-closed gate and redacted message owner, fence blocked writes, and release the placement claim. Lease proof: 148 owner/sibling tests; five regressions fail on original code; core and core-test types, typed lint, and changed structural checks passed. Live blocked input produced no node deltas/tools; a following tool turn passed. Committed with --no-verify because the sparse worktree has no dependencies. The full changed-file oxfmt check passed on the isolated AWS validation lease.
Keep policy admission and admitted transcript context at the user-message owner. Reuse the standard hook context projection and remove narration and one-use type aliases. Rebased owner/sibling proof: 71 tests pass; core types, typed lint, line cap, and formatting pass on the AWS lease. The sparse local pre-commit hook was skipped only after that remote formatting proof. Independent review found no actionable P0-P2 findings.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 7:32 AM ET / 11:32 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR applies plugin input policies before node-hosted turns persist approved input or launch a worker, and shares fail-closed blocking behavior with local and CLI runners. Merge readiness✅ Ready for maintainer review This repair remains necessary on current main. No actionable introduced defects were found, and source comparison resolves the previous transcript compatibility blocker. Priority: P0 Review scores
Verification
How this fits togetherThe Gateway dispatches agent turns to node-hosted workers. Input admission sits between incoming prompts and conversation history, transcript persistence, and worker execution. flowchart TD
A[Incoming prompt and history] --> B[Gateway node admission]
B --> C[Plugin input policy]
C -->|Blocked or failed| D[Redacted transcript and blocked reply]
C -->|Allowed| E[Recheck live authority]
E --> F[Approved transcript and worker launch]
D --> G[Release turn claim]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +121, Tests +144, Docs +11, Other -1. Total +275 across 13 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Use the shared fail-closed admission owner for node turns while preserving transcript compatibility and the documented Gateway-context boundary. Do we have a high-confidence way to reproduce the issue? Yes: current main's node path lacks the existing input-policy gate, and the supplied baseline evidence demonstrates rejected input reaching the node model. This review inspected source without executing the runtime. Is this the best way to solve the issue? Yes: sharing the existing gate and redacted-message builder repairs the bypass at Gateway admission without adding configuration or changing stored transcript contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e40ed06f23cb. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
* fix: enforce input policies before node worker turns Run before_agent_run under the retained plugin generation before node input persistence or worker launch. Reuse the local/CLI fail-closed gate and redacted message owner, fence blocked writes, and release the placement claim. Lease proof: 148 owner/sibling tests; five regressions fail on original code; core and core-test types, typed lint, and changed structural checks passed. Live blocked input produced no node deltas/tools; a following tool turn passed. Committed with --no-verify because the sparse worktree has no dependencies. The full changed-file oxfmt check passed on the isolated AWS validation lease. * refactor: consolidate node input preparation Keep policy admission and admitted transcript context at the user-message owner. Reuse the standard hook context projection and remove narration and one-use type aliases. Rebased owner/sibling proof: 71 tests pass; core types, typed lint, line cap, and formatting pass on the AWS lease. The sparse local pre-commit hook was skipped only after that remote formatting proof. Independent review found no actionable P0-P2 findings. (cherry picked from commit c81d86e)
* fix: enforce input policies before node worker turns Run before_agent_run under the retained plugin generation before node input persistence or worker launch. Reuse the local/CLI fail-closed gate and redacted message owner, fence blocked writes, and release the placement claim. Lease proof: 148 owner/sibling tests; five regressions fail on original code; core and core-test types, typed lint, and changed structural checks passed. Live blocked input produced no node deltas/tools; a following tool turn passed. Committed with --no-verify because the sparse worktree has no dependencies. The full changed-file oxfmt check passed on the isolated AWS validation lease. * refactor: consolidate node input preparation Keep policy admission and admitted transcript context at the user-message owner. Reuse the standard hook context projection and remove narration and one-use type aliases. Rebased owner/sibling proof: 71 tests pass; core types, typed lint, line cap, and formatting pass on the AWS lease. The sparse local pre-commit hook was skipped only after that remote formatting proof. Independent review found no actionable P0-P2 findings.
What Problem This Solves
Fixes OpenClaw node-hosted turns bypassing plugin
before_agent_runpolicies: input rejected locally could still reach a model on a node.User Impact
The Gateway now gates node input before transcript persistence or worker launch. Blocks and hook failures return the redacted block message, and the placement remains available for the next turn.
Node admission sees the Gateway prompt and loaded history. It omits the system prompt assembled later on the node; policies requiring that final context must use a supported local runner. This does not establish parity for other lifecycle hooks or change pending-input retention.
Why This Change Was Made
Node admission now uses the same fail-closed decision and redacted-message owners as local and CLI runners, under the retained executable plugin generation. The standard hook context projection supplies the admitted identity. The Gateway rechecks run, placement, cancellation, and transcript authority after the hook, and releases a blocked turn's claim.
The security repair adds 120 net production lines (+292/-172), within the approved policy-bypass exception. Gateway admission and persistence fencing require new integration code; duplicated local/CLI policy decisions, message construction, and casts were removed. The cast baseline only shrinks.
Evidence
node scripts/run-vitest.mjs src/gateway/worker-environments/worker-turn-execution.test.ts --maxWorkers=1, the repository test wrapper). Core and every core-test type lane, changed-file formatting, typed lint, and the selected structural guards passed. Initial lint findings were fixed and the failed lint plus remaining planned guards rerun; passing type and guard evidence was retained. After rebasing and consolidating context preparation, all 71 Gateway owner/sibling tests passed again in 302.99 s wall. Exact-head CI run 37119128403 passed, including openclaw/ci-gate, selected Node suites, production/test types, and lint. The execution suite passed all 26 cases in 75.38 s in hosted shard agentic-gateway-server-isolated-hosted-20; its containing CI job completed in 175 s including setup and other shard work.SHOULD_NOT_RUN. Candidate: both hosts returned the policy block with zero deltas/tools. The same node session then executedexecand returnedCONTINUATION_OK; its transcript contains the redacted block rather than the original prompt.Six local and six node pong turns on the same lease at base
47a026ea3fe6; medians exclude turn 0. Candidate is the final committed implementation. All values are milliseconds.Node tail increased 10 ms and local tail increased 146 ms in this small sample. This is a policy repair, not evidence of a speed improvement.
The execution suite uses the existing placement fixture and real transcript storage to prove admission ordering and claim release; a helper-only test cannot detect this bypass.
Compatibility review: ClawSweeper completed its exact-head review with no code findings. Its serialized-state heuristic flagged
cli-run-transcript.ts; the reviewed diff replaces only the inline blocked-message builder with the shared builder. Both emit the samerole, text content, timestamp,hook-block:before_agent_run:user:<runId>idempotency key, and__openclaw.beforeAgentRunBlocked.{blockedBy,blockedAt}fields and values. The transcript writer, reader, schema, and schema version are unchanged. Existing CLI/local block regressions and real transcript readback pass; no stored-data migration is introduced or required.