Repository navigation
fix(codex): honor input policy before native model starts - #153902
substrateindependent wants to merge 5 commits into
Conversation
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]>
|
🦞👀 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: blocked before merge. Reviewed October 6, 2026, 6:33 PM ET / 22:33 UTC (Revision 10). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherOpenClaw’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]
Decision needed
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
Findings
Agent review detailsSecurityNone. PR surfaceSource +181, Tests +1468, Docs +67. Total +1716 across 12 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against dd619529b24a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
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]>
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]>
|
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. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
What Problem This Solves
Adds the configured
before_agent_runinput-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 remainsc511fde70f184c743800cddc0e3941476b9ed5a2.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.
turn/startwritesThe 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.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.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 onc511fde…; 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.