Skip to content

fix(codex): honor input policy before native model starts - #153902

Closed
substrateindependent wants to merge 5 commits into
openclaw:mainfrom
Fieldcrest:adam/eng-366-enforce-linear-pickup-authorization-on-native-codex
Closed

substrateindependent wants to merge 5 commits into
openclaw:mainfrom
Fieldcrest:adam/eng-366-enforce-linear-pickup-authorization-on-native-codex

Conversation

@substrateindependent

@substrateindependent substrateindependent commented Sep 20, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Adds the configured before_agent_run input-policy decision to native Codex model submission. This expands the public hook/SDK contract to the native Codex harness.

User Impact

A blocking or failed decision stops a new native attempt before model-start diagnostics, LLM-input observation, or native turn submission. Allowed attempts retain their existing compact-turn and fresh-thread retries under one admission. Loaded session history reaches policy as a deep-cloned message graph, so a plugin cannot mutate the attempt's retained history through its input.

Why This Change Was Made

The native adapter previously proceeded to model submission without consulting the canonical input policy. The public harness helper now runs once before the attempt's first native submission. Retries inside that admitted attempt reuse the decision; each new attempt enters policy again. An advertised but uncallable gate fails closed, blocked input is safely settled/redacted, and cancellation is rechecked after pending policy.

The boundary is after runtime/thread setup and before model submission. It does not gate native process/thread setup or claim policy support for every other harness. The hook catalog and SDK documentation now agree on this scope.

Evidence

Current candidate: 3f957db3f7a0985ecf10c17e5331819bf0b64f72. The last commit adds only the native test and its database-worker routing entry; production source remains c511fde70f184c743800cddc0e3941476b9ed5a2.

Reproducible native admission test ran against the exact published head: 5/5 passed, 53.46 seconds including the supported wrapper. Environment: Node 26.1.0, pnpm 12.4.0, Linux ARM64, pinned native Codex 0.154.0. The initialize handshake verifies the actual binary version.

Case Native turn/start writes Provider requests Physical tool effects Persistence
Allowed 1 2 1 Completed native command output and exactly one matching SQLite tool result
Prior-native-history denial 0 additional 0 0 Safe replacement; rejected input absent; native history unchanged
Cancellation, then pass 0 0 0 Empty transcript; recorder neither persisted nor blocked
Cancellation, then block 0 0 0 Empty transcript; recorder neither persisted nor blocked
Canonical owner replaced during policy 0 additional 0 0 Superseded error; native and SQLite history unchanged

The ownership case observes one local request-method entry that is rejected by the real client's pre-write guard. The passive transport spy confirms zero additional RPC frames. Native notifications, HTTP receipts, command output, physical marker and SQLite reads corroborate the relevant cases. Canonical row replacement is a targeted generation-loss injection, not a full Gateway reset workflow.

Tests ran in a credential-free container with no host mounts and --network none. The native process, stdio transport, shell execution and SQLite owners are real. The loopback Responses SSE model, input policy, initial host admission and exec-approval configuration are synthetic. This is adapter proof, not hosted-model or full Gateway/channel authorization proof.

node scripts/run-vitest.mjs extensions/codex/src/app-server/admission-final-effect.native.test.ts
node scripts/run-vitest.mjs extensions/codex/src/app-server/thread-lifecycle.native.test.ts extensions/codex/src/app-server/settled-turn-finalizer.native.test.ts
Actual execution output — September 21, 14:21 UTC

These five diagnostic lines are copied from the successful exact-head run, with terminal color escapes removed. They are emitted after the corresponding assertions against the real native process/transport, loopback provider, physical marker and SQLite store. The provider and policy inputs remain synthetic as described above. The published test artifact SHA256 is 95f4744f18d1710a11accee766bb70b22115391622275307c2048d98fd0d2e8c.

3f957db3f7a0985ecf10c17e5331819bf0b64f72
Node v26.1.0; pnpm 12.4.0
NATIVE_ADMISSION_PROOF {"case":"pass","version":"0.154.0","gateCalls":1,"requestMethodEntries":1,"turnStartWireWrites":1,"nativeTurnStarted":true,"providerRequests":2,"markerWrites":1,"sqliteTranscript":true}
NATIVE_ADMISSION_PROOF {"case":"history-denial","version":"0.154.0","gateCalls":1,"additionalRequestMethodEntries":0,"additionalTurnStartWireWrites":0,"providerRequests":0,"markerWrites":0,"sqliteSafeReplacement":true,"nativeHistoryUnchanged":true}
NATIVE_ADMISSION_PROOF {"case":"cancel-pass","version":"0.154.0","gateCalls":1,"requestMethodEntries":0,"turnStartWireWrites":0,"providerRequests":0,"markerWrites":0}
NATIVE_ADMISSION_PROOF {"case":"cancel-block","version":"0.154.0","gateCalls":1,"requestMethodEntries":0,"turnStartWireWrites":0,"providerRequests":0,"markerWrites":0}
NATIVE_ADMISSION_PROOF {"case":"canonical-owner-replaced","version":"0.154.0","gateCalls":1,"additionalRequestMethodEntries":1,"additionalTurnStartWireWrites":0,"nativeTurnStarted":false,"providerRequests":0,"markerWrites":0,"supersededErrorName":"AgentHarnessSessionSupersededError","nativeHistoryUnchanged":true,"sqliteHistoryUnchanged":true}
Test Files  1 passed (1)
Tests       5 passed (5)
Duration    51.96s (Vitest; 53.46s including wrapper)
Container exit code: 0

The existing native controls passed 10/10 on production source c511fde…. Touched-file format/lint and a Codex-only test type program extending the canonical extension test settings passed. The full extension test type program exceeded this host's 8 GiB container limit; no full-type or full-build pass is claimed. The builder separately reported 269 related native-attempt tests passing on c511fde…; that source work used Node 22.23.2 and is not the supported-Node independent native proof above.

Fresh isolated review of the production change and added test artifact found no remaining actionable P0–P2 findings. The native tests include finite observation deadlines, structured output assertions and exact cancellation/persistence checks.

Fieldcrest source-review decision

Turing, the assigned Fieldcrest source-review owner for FLEET-3333, recorded ACCEPT — bounded source-review contract only on September 21 at 14:42 UTC. This section relays his prepared decision through the existing PR author's access; it is not an upstream maintainer approval. His report was read directly and retained with SHA256 f84292673c3ffba805fbbbf2ebb63b1940ebd5637d58ac9dad1c6e45e1fdb747.

His accepted contract is a fail-closed input-policy boundary after native process/thread setup and before diagnostics, LLM-input observation, turn submission, provider requests or tool effects, once per admitted attempt. With no registered policy, execution passes; an explicit block, missing callable runner, exception, timeout or malformed decision denies. The contract assumes a compatible core/plugin set.

Turing reports independent isolated execution at this same test-only head: native proof 5/5, native controls 10/10, and public-helper semantics 19/19, plus touched-file format/lint and a clean tracked worktree. He used real Codex 0.154.0, stdio, SQLite and a physical shell effect with an explicitly synthetic loopback provider and scratch state. These are his reported independent results; the captured five-case container diagnostics above are this PR author's separate execution.

His acceptance expressly excludes upstream SDK/security-owner approval, hosted-model/full-ingress behavior, and official-package fresh-install/upgrade compatibility. Source dependency installation is not package-upgrade proof. Those remaining decisions stay open below. This evidence update is submitted for fresh independent review.

Remaining Acceptance

Ready for maintainer review. Open: acceptance of the public SDK/native admission contract. Fresh-install and upgrade evidence on a compatible core/plugin package pair follows acceptance. Hosted-model and full-ingress validation stay on our side and are not claimed here.

Native Codex attempts started model diagnostics, the llm_input hook, and
turn/start without ever entering the canonical before_agent_run gate, so a
registered admission policy could deny embedded runs but never see native
Codex attempts. Add a plugin-sdk seam (runAgentHarnessBeforeAgentRun) that
runs the fail-closed gate once per attempt, before any of those paths, and
route startCodexAttemptTurn through it. Hook errors, timeouts, and malformed
decisions all resolve to a blocked terminal result with zero native starts;
the existing compact-turn and fresh-thread retries inside one attempt reuse
that single decision instead of re-entering the gate.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@clawsweeper

clawsweeper Bot commented Sep 20, 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.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. labels Sep 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 6, 2026, 6:33 PM ET / 22:33 UTC (Revision 10).

ClawSweeper review

What this changes

The PR adds a fail-closed input-policy gate before native Codex model submission, exports a public harness helper, and documents and tests admission, redaction, cancellation, and ownership loss.

Merge readiness

⛔ Blocked before merge - 5 items remain

The native capability remains missing on main, and the supplied adapter proof is sufficient. A newly merged shared admission owner now makes part of this implementation duplicative; public-contract acceptance and packaged compatibility evidence also remain unresolved.

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

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong native final-effect evidence preserves the contribution’s value, but new shared-owner duplication and unresolved package compatibility prevent merge readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The exact-head trace exercises runCodexAppServerAttempt through real Codex 0.154.0, stdio, shell effects, and SQLite, with synthetic policy and loopback provider inputs. It demonstrates allowed execution and zero additional native writes, provider requests, or tool effects on denial, cancellation, and session-owner replacement. Package install/upgrade proof remains a separate compatibility blocker; no stored-data schema or format change is introduced.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The exact-head trace exercises runCodexAppServerAttempt through real Codex 0.154.0, stdio, shell effects, and SQLite, with synthetic policy and loopback provider inputs. It demonstrates allowed execution and zero additional native writes, provider requests, or tool effects on denial, cancellation, and session-owner replacement. Package install/upgrade proof remains a separate compatibility blocker; no stored-data schema or format change is introduced.
Evidence reviewed 11 items Pinned introduced production change: The merge-base-to-head delta adds admission before diagnostics, input observation, and native submission, with cancellation rechecked after policy and denied input replaced before persistence and agent_end. Only the pinned introduced delta was attributed to this PR.
Native capability still absent on current main: Current main emits model-start diagnostics and llm_input and then invokes startCodexTurn without the proposed before_agent_run dispatch. The branch therefore retains meaningful native integration work.
Latest release explicitly excludes this capability: The v2026.9.8 hook catalog says embedded and CLI runners implement before_agent_run and explicitly advises against relying on it as a Codex input gate. This establishes a capability expansion rather than a broken shipped Codex contract.
Findings 1 actionable finding [P1] [P1] Reuse the shared admission owner now present on main
Security None None.

How this fits together

OpenClaw’s Codex plugin prepares conversation context and submits turns to the native Codex process. The proposed gate lets registered plugins deny that input before model submission and records a safe replacement for blocked turns.

flowchart TD
  A[Conversation and loaded history] --> B[Native runtime and thread setup]
  B --> C[Input policy decision]
  C -->|Allow| D[Native model submission]
  C -->|Block| E[Safe replacement transcript]
  D --> F[Provider requests and tool effects]
  E --> G[Blocked attempt result]
Loading

Decision needed

Question Recommendation
Should native Codex support fail-closed before_agent_run once per attempt after thread setup, including blocking existing registered policies on failure or runner incompatibility? Accept bounded native parity: Approve the post-setup admission contract through the SDK and security owners, consolidate the shared mechanics, and require packaged compatibility evidence before merge.

Why: The shipped contract explicitly excludes Codex, and third-party source-review acceptance does not authorize expanding the upstream SDK and native policy contract.

Before merge

  • [P1] Reuse the shared admission owner now present on main (P1) - Current main now provides runBeforeAgentRunGate and buildAgentRunBlockedUserMessage in src/agents/harness/before-agent-run.ts, used by embedded and node turns after the merged fix: node turns bypass before_agent_run policies #164270. This new helper independently implements the same decision dispatch and normalization, while the native block branch independently constructs the same persisted replacement. Keeping both creates competing policy owners and lets future fail-closed or transcript fixes diverge by harness. Route the public native seam through the shared owner and reuse its replacement builder, preserving this PR’s missing-runner handling, cancellation check, and native integration. This overlap became available through new main work after the previous review.
  • Resolve merge risk (P1) - Existing registered policies that Codex previously ignored will now stop native turns, including on policy failure or an incompatible runner; upstream acceptance of this public behavior remains unrecorded.
  • Resolve merge risk (P1) - Fresh-install and upgrade behavior for a compatible packaged core/Codex-plugin pair has not been demonstrated; the supplied source-container proof explicitly excludes it.
  • Complete next step (P2) - Obtain upstream SDK/security-owner acceptance, consolidate the shared admission mechanics, and provide packaged fresh-install and upgrade evidence before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] [P1] Reuse the shared admission owner now present on main — src/agents/harness/lifecycle-hook-helpers.ts:144-154
Agent review details

Security

None.

PR surface

Source +181, Tests +1468, Docs +67. Total +1716 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 4 184 3 +181
Tests 4 1468 0 +1468
Docs 4 69 2 +67
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 1721 5 +1716

Review metrics

Metric Value Why it matters
Public SDK expansion 1 callable and 1 outcome type added These exports establish a new supported native admission contract that requires explicit upstream acceptance.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #135371
Summary: This PR is a candidate implementation of the canonical native admission request; the merged node change supplies shared mechanics but leaves native parity missing.

Members:

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

Merge-risk options

Maintainer options:

  1. Approve and verify the package transition (recommended)
    Accept the bounded hook contract and demonstrate fresh installation and upgrade with compatible packaged core/plugin versions, including no-policy pass-through and policy denial.
  2. Pause pending contract sponsorship
    Keep the implementation available without landing it until upstream owners decide whether existing registered policies should gain native enforcement.

Technical review

Best possible solution:

Use one shared admission and redacted-message owner behind an accepted native SDK contract, with packaged installation and upgrade behavior verified before enabling the new guarantee.

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

Not applicable as a shipped-behavior bug: the released contract excludes native Codex admission. Current-main source confirms the missing capability, and the supplied native trace demonstrates the proposed behavior.

Is this the best way to solve the issue?

No, the native boundary is useful, but its decision dispatch and replacement-message construction should now reuse main’s shared admission owner rather than establish parallel mechanics.

Full review comments:

  • [P1] [P1] Reuse the shared admission owner now present on main — src/agents/harness/lifecycle-hook-helpers.ts:144-154
    Current main now provides runBeforeAgentRunGate and buildAgentRunBlockedUserMessage in src/agents/harness/before-agent-run.ts, used by embedded and node turns after the merged fix: node turns bypass before_agent_run policies #164270. This new helper independently implements the same decision dispatch and normalization, while the native block branch independently constructs the same persisted replacement. Keeping both creates competing policy owners and lets future fail-closed or transcript fixes diverge by harness. Route the public native seam through the shared owner and reuse its replacement builder, preserving this PR’s missing-runner handling, cancellation check, and native integration. This overlap became available through new main work after the previous review.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.92

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The exact-head trace exercises runCodexAppServerAttempt through real Codex 0.154.0, stdio, shell effects, and SQLite, with synthetic policy and loopback provider inputs. It demonstrates allowed execution and zero additional native writes, provider requests, or tool effects on denial, cancellation, and session-owner replacement. Package install/upgrade proof remains a separate compatibility blocker; no stored-data schema or format change is introduced.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: This is a bounded native harness capability expansion with concrete proof, rather than a demonstrated default-path regression.
  • merge-risk: 🚨 compatibility: Previously ignored registered policies can now block existing native turns, and packaged core/plugin installation and upgrade compatibility remain unverified.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The exact-head trace exercises runCodexAppServerAttempt through real Codex 0.154.0, stdio, shell effects, and SQLite, with synthetic policy and loopback provider inputs. It demonstrates allowed execution and zero additional native writes, provider requests, or tool effects on denial, cancellation, and session-owner replacement. Package install/upgrade proof remains a separate compatibility blocker; no stored-data schema or format change is introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. The exact-head trace exercises runCodexAppServerAttempt through real Codex 0.154.0, stdio, shell effects, and SQLite, with synthetic policy and loopback provider inputs. It demonstrates allowed execution and zero additional native writes, provider requests, or tool effects on denial, cancellation, and session-owner replacement. Package install/upgrade proof remains a separate compatibility blocker; no stored-data schema or format change is introduced.

Evidence

What I checked:

  • Pinned introduced production change: The merge-base-to-head delta adds admission before diagnostics, input observation, and native submission, with cancellation rechecked after policy and denied input replaced before persistence and agent_end. Only the pinned introduced delta was attributed to this PR. (extensions/codex/src/app-server/run-attempt-turn-start.ts:73, 3f957db3f7a0)
  • Native capability still absent on current main: Current main emits model-start diagnostics and llm_input and then invokes startCodexTurn without the proposed before_agent_run dispatch. The branch therefore retains meaningful native integration work. (extensions/codex/src/app-server/run-attempt-turn-start.ts:69, dd619529b24a)
  • Latest release explicitly excludes this capability: The v2026.9.8 hook catalog says embedded and CLI runners implement before_agent_run and explicitly advises against relying on it as a Codex input gate. This establishes a capability expansion rather than a broken shipped Codex contract. Public docs: docs/plugins/hooks.md. (docs/plugins/hooks.md, fc23bc864e45)
  • New canonical shared admission owner: GitHub verifies fix: node turns bypass before_agent_run policies #164270 as merged. Its October 3 commit added runBeforeAgentRunGate and buildAgentRunBlockedUserMessage; current embedded and node callers use those owners. It does not implement native Codex admission, but it supersedes the need for independent decision and replacement-message mechanics in this branch. (src/agents/harness/before-agent-run.ts:14, dd619529b24a)
  • Exact-head native final-effect proof: The captured PR body reports five passing cases on the pinned head using real Codex 0.154.0, stdio, shell execution, and SQLite with a synthetic loopback provider and policy. The inspected test observes actual stdin writes: allowance produces one native submission and one physical effect; denial, cancellation, and canonical-owner replacement produce no additional native submission or provider/tool effect. The test file hash matches the published SHA256 95f4744f18d1710a11accee766bb70b22115391622275307c2048d98fd0d2e8c. No contributor code was executed during this review. (extensions/codex/src/app-server/admission-final-effect.native.test.ts:333, 3f957db3f7a0)
  • Final native write retains current-authority validation: The turn request supplies connection.assertCurrent to the real client, which invokes that guard immediately before writeMessage. This supports the proof’s distinction between a rejected request-method entry and an actual native RPC write. (extensions/codex/src/app-server/client.ts:735, 3f957db3f7a0)

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Consolidate decision dispatch and redacted-message construction with main’s shared admission owner.
  • Record upstream SDK and security-owner acceptance of the bounded native admission contract.
  • Show fresh-install and upgrade results for a compatible packaged core/plugin pair.

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 (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-20T20:15:59.780Z sha 3fcee10 :: needs real behavior proof before merge. :: [P1] Pass loaded session history to the admission hook | [P2] Document only the admission boundary this patch implements
  • reviewed 2026-09-21T00:06:17.510Z sha 3fcee10 :: needs real behavior proof before merge. :: [P1] Pass loaded session history to the admission hook | [P2] Document only the admission boundary this patch implements
  • reviewed 2026-09-21T00:48:23.864Z sha 17aacdd :: needs real behavior proof before merge. :: [P2] Deep-clone loaded messages before passing them to policy hooks | [P2] Document the actual Codex model-submission boundary
  • reviewed 2026-09-21T06:04:56.975Z sha 17aacdd :: needs real behavior proof before merge. :: [P2] Deep-clone loaded messages before passing them to policy hooks | [P2] Document the actual Codex model-submission boundary
  • reviewed 2026-09-21T06:26:41.695Z sha c511fde :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-21T14:33:48.656Z sha 3f957db :: blocked before merge. :: none
  • reviewed 2026-09-21T15:50:32.332Z sha 3f957db :: blocked before merge. :: none
  • reviewed 2026-09-24T15:26:50.039Z sha 3f957db :: blocked before merge. :: none

Resolve reviewed findings on the native Codex admission gate:

- Fail closed when before_agent_run hooks are registered but the hook
  runner has no callable runBeforeAgentRun, instead of treating that
  the same as no gate being registered.
- Derive the admission event's channelId from the canonical
  hookContext.channelId (per-conversation identity) instead of the
  shared messageChannel/messageProvider pair, so distinct conversations
  on one provider get distinct admission identities.
- Settle a denial as the canonical hook:before_agent_run terminal so
  the outer harness lifecycle reports it as blocked, not a generic
  prompt error.
- Replace the rejected prompt with a redacted placeholder through the
  attempt's userTurnTranscriptRecorder before it reaches agent_end, the
  returned snapshot, or persistence.
- Stop logging raw before_agent_run hook exception text; log fixed,
  safe metadata only.
- Fail closed on cancellation that races with a still-pending admission
  call, instead of starting a native turn for an abandoned attempt.
- Document the admission helper's compatibility semantics in the
  Plugin SDK docs.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Sep 20, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. P1 High-priority user-facing bug, regression, or broken workflow. labels Sep 20, 2026
adam-fieldcrest and others added 3 commits September 20, 2026 19:36
The native Codex admission gate's `messages` field always reused the
llm_input event's historyMessages, which Codex intentionally leaves
empty for native turns. A before_agent_run policy could therefore never
make a history-dependent decision: it always observed a run with no
prior conversation context, regardless of what was actually loaded for
the session.

Build the admission event's `messages` from an isolated snapshot
(copy, not a live reference) of the attempt's own historyState.messages
instead, so a registered policy sees the loaded session history the
doc contract already promises. Document the distinction in the SDK
attempt-runtime reference and add the before_agent_run support row to
the Codex v1 support contract table.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… docs

Deep-clone each loaded history message before handing it to the
before_agent_run admission event instead of shallow-copying the array: a
hook mutating a prior message's nested content object previously mutated
the attempt's own history, later exposed via agent_end and the returned
snapshot, including on denial. Only pay for the snapshot and its clone when
a before_agent_run hook is actually registered, matching
runAgentHarnessBeforeAgentRun's own no-op pass-through and avoiding
needless cloning on every native Codex attempt.

Add a regression covering a hook that mutates nested message content on
denial, asserting agent_end and the returned snapshot still carry the
original text.

Narrow the admission-gate docs (attempt-runtime.md) to the boundary this
patch actually implements: after a harness's native runtime/thread setup,
not before every native session RPC. Reconcile hooks.md's hook catalog,
which still said Codex was unsupported, to describe Codex's post-setup
model-submission boundary.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 21, 2026
@clawsweeper clawsweeper Bot added 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 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 Sep 21, 2026
@substrateindependent
substrateindependent marked this pull request as ready for review September 24, 2026 15:18
@substrateindependent

Copy link
Copy Markdown
Author

Taking this out of draft for a maintainer decision on the contract question in the review above, which #135371 is also waiting on: should native Codex honor before_agent_run as a fail-closed admission gate, once per attempt, after thread setup and before model submission? The last ClawSweeper pass found no code or security findings and marked the native proof sufficient. This adds one callable and one outcome type to plugin-sdk/agent-harness-runtime, so if that needs a surface-budget bump it belongs to the same decision. If you accept the contract, we'll follow with fresh-install and upgrade evidence on a compatible core/plugin package pair. If you'd rather Codex not take this gate, please say so.

@clawsweeper clawsweeper Bot added 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 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 Oct 6, 2026
@barnacle-openclaw

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@barnacle-openclaw barnacle-openclaw Bot added the stale Marked as stale due to inactivity label Oct 15, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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 extensions: codex merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: XL stale Marked as stale due to inactivity status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants