Skip to content

fix(codex): gate native runs before agent start - #128400

Closed
johnny7861532 wants to merge 1 commit into
openclaw:mainfrom
johnny7861532:fix/codex-native-before-agent-run-hook
Closed

johnny7861532 wants to merge 1 commit into
openclaw:mainfrom
johnny7861532:fix/codex-native-before-agent-run-hook

Conversation

@johnny7861532

Copy link
Copy Markdown

Summary

  • run before_agent_run admission for native Codex app-server attempts before lifecycle start and model-input events
  • memoize the admission decision across retries of the same logical run
  • persist blocked outcomes with redaction and clean up run-scoped state
  • add regression coverage for ordering, retries, fail-closed behavior, redaction, and cleanup

Verification

  • 334 regression tests passed
  • 31 final gate tests passed
  • full changed-file checks passed, including typecheck, type-aware lint, SDK surface, dead-export, and import-cycle guards
  • fresh exact-commit review passed

Security

  • reviewed lifecycle ordering, hook identity, retry/replay behavior, persisted blocked results, and cleanup
  • no remaining confirmed security findings

@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling extensions: codex size: L triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 23, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 23, 2026
@clawsweeper

clawsweeper Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 23, 2026, 7:02 PM ET / 23:02 UTC.

ClawSweeper review

What this changes

The PR adds a fail-closed before_agent_run gate to native Codex app-server attempts, memoizes its decision over retries, and records blocked attempts.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 13 items remain

Keep this PR open: the proposed gate can be bypassed by a plugin harness, leaks thrown hook text to logs, and still permits app-server prewarm before a block decision.

Priority: P1
Reviewed head: f5628e44281501c070ea5e6a6edfc6dc5fe3d855
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The branch has concrete security and admission-order defects, and its claimed validation is mock-only.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: Authority-chain proof required: the body reports tests and checks only; add redacted real app-server evidence showing blocked admission neither initializes/spawns Codex nor permits a hostile harness to bypass the gate. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Authority-chain proof required: the body reports tests and checks only; add redacted real app-server evidence showing blocked admission neither initializes/spawns Codex nor permits a hostile harness to bypass the gate. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 8 items Mutable admission crosses the plugin boundary: The changed dispatcher adds the mutable admission object to attempt parameters, while the plugin projection intentionally strips other host-owned state but not this field.
Gate trusts a preseeded decision: The new helper returns an existing decision before checking whether a before-agent-run hook is registered, so an external harness receiving the object can force proceed.
Hook exception is logged without redaction: The new catch interpolates the thrown value, although the hook receives prompt, history, and system prompt and the hook decision contract forbids exposing internal details.
Findings 3 actionable findings [P1] Keep the admission memo out of plugin harness parameters
[P1] Do not log thrown before-agent-run errors verbatim
[P1] Gate before starting the app-server prewarm
Security Needs attention Writable gate decision bypasses fail-closed admission: A non-builtin harness receives the mutable memo and can preseed a proceed result that the new helper trusts before executing registered policy hooks.
Thrown hook errors can expose prompt data in logs: The gate receives prompt and history data, while the new catch serializes arbitrary exception text into the agent-harness log.

How this fits together

The embedded runner selects a harness and passes an attempt into the Codex extension. The extension prepares prompt and tool state, then starts a Codex app-server process and its turn; this gate is intended to stop that path before model work begins.

flowchart LR
A[Incoming agent turn] --> B[Embedded runner]
B --> C[Plugin harness handoff]
C --> D[Codex admission gate]
D -->|allow| E[Codex app-server]
D -->|block| F[Redacted blocked result]
E --> G[Native model turn]
Loading

Decision needed

Question Recommendation
Should native harnesses receive a host-owned admission operation, with any SDK export explicitly designed and documented, rather than a writable admission memo? Keep admission host-owned: Move the memo behind a core-owned closure or capability, add hostile-harness proof, and only expose the minimum SDK operation Codex needs.

Why: The PR changes which plugin-owned code can bypass a configured fail-closed gate and adds a public SDK helper, so the permanent trust boundary cannot safely be inferred from this branch alone.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Authority-chain proof required: the body reports tests and checks only; add redacted real app-server evidence showing blocked admission neither initializes/spawns Codex nor permits a hostile harness to bypass the gate. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Keep the admission memo out of plugin harness parameters (P1) - The dispatcher now passes a writable beforeAgentRunAdmission object to plugin harnesses, but the hook helper returns any preseeded decision before consulting registered gates. A harness can set proceed and bypass configured fail-closed admission; keep this state host-private and add a hostile-harness regression.
  • Do not log thrown before-agent-run errors verbatim (P1) - A gate receives the prompt and history, so a throwing plugin can include that content in its error. This new interpolation writes it to logs despite the gate contract's redaction rule; use the existing fixed warning and test a secret-bearing exception.
  • Gate before starting the app-server prewarm (P1) - This call happens after runtime preparation, which launches and initializes the shared Codex app-server through prewarm. A blocked run therefore still starts the native process; defer prewarm until successful admission and prove a blocked real-client path makes no initialize or spawn.
  • Resolve security concern: Writable gate decision bypasses fail-closed admission - A non-builtin harness receives the mutable memo and can preseed a proceed result that the new helper trusts before executing registered policy hooks.
  • Resolve security concern: Thrown hook errors can expose prompt data in logs - The gate receives prompt and history data, while the new catch serializes arbitrary exception text into the agent-harness log.
  • Resolve merge risk (P1) - The new public Plugin SDK helper expands a compatibility-sensitive harness contract without maintainer confirmation of the permanent API shape.
  • Resolve merge risk (P1) - The PR adds production +292 net lines for a cross-cutting gate; the intended refactor should absorb this into a host-owned admission boundary rather than preserve parallel mutable state.
  • Resolve merge risk (P1) - The required sibling Codex source was unavailable in this read-only review environment, so exact app-server initialize behavior still needs direct maintainer-side contract verification.
  • Improve patch quality - Keep the admission memo host-private and prove an external harness cannot preseed or alter it before final I/O.
  • Improve patch quality - Replace raw gate-error logging with a redacted path and demonstrate that a secret-bearing throw is absent from logs and blocked records.
  • Improve patch quality - Add a redacted real app-server trace proving a blocked turn produces no client spawn or initialize activity.

Findings

  • [P1] Keep the admission memo out of plugin harness parameters — src/agents/embedded-agent-runner/run/run-attempt-dispatch.ts:273
  • [P1] Do not log thrown before-agent-run errors verbatim — src/agents/harness/lifecycle-hook-helpers.ts:170-174
  • [P1] Gate before starting the app-server prewarm — extensions/codex/src/app-server/run-attempt.ts:39-42
  • [high] Writable gate decision bypasses fail-closed admission — src/agents/embedded-agent-runner/run/run-attempt-dispatch.ts:273
  • [high] Thrown hook errors can expose prompt data in logs — src/agents/harness/lifecycle-hook-helpers.ts:170
Agent review details

Security

Needs attention: The patch exposes a writable authorization decision to plugin-owned code and can log sensitive gate input through thrown errors.

PR surface

Source +292, Tests +582, Other +3. Total +877 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 9 298 6 +292
Tests 2 582 0 +582
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 5 2 +3
Total 12 885 8 +877

Review metrics

Metric Value Why it matters
Production versus test LOC production +298/-6, tooling +5/-2, tests +582 The substantial production growth introduces a cross-boundary admission mechanism and needs an owner-boundary refactor rather than additive parallel state.
Public Plugin SDK surface 1 helper added The surface-report budget increase confirms a new harness-facing SDK contract that needs explicit compatibility direction.

Stored data model

Persistent data-model change detected: serialized state: extensions/codex/src/app-server/run-attempt.before-agent-run.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair the host-owned admission boundary (recommended)
    Keep the retry memo private, prevent prewarm until admission succeeds, redact exception logging, and add hostile-harness plus real app-server proof.
  2. Approve a documented public SDK shape
    If a cross-plugin gate helper is intentional, explicitly approve and document its stable capability contract before accepting its compatibility risk.

Technical review

Best possible solution:

Keep admission state closure-bound in the host, run the gate before any prewarm, redact thrown-hook logs, and expose only a deliberately approved narrow SDK capability if Codex needs one.

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

Yes for the source paths: a non-builtin harness can preseed the exposed memo, and runtime preparation invokes app-server prewarm before the new gate; no live app-server reproduction was run in this read-only review.

Is this the best way to solve the issue?

No: the fix must make admission host-owned, run it before prewarm, and use the existing redaction precedent rather than expose writable state and raw exceptions.

Full review comments:

  • [P1] Keep the admission memo out of plugin harness parameters — src/agents/embedded-agent-runner/run/run-attempt-dispatch.ts:273
    The dispatcher now passes a writable beforeAgentRunAdmission object to plugin harnesses, but the hook helper returns any preseeded decision before consulting registered gates. A harness can set proceed and bypass configured fail-closed admission; keep this state host-private and add a hostile-harness regression.
    Confidence: 0.98
  • [P1] Do not log thrown before-agent-run errors verbatim — src/agents/harness/lifecycle-hook-helpers.ts:170-174
    A gate receives the prompt and history, so a throwing plugin can include that content in its error. This new interpolation writes it to logs despite the gate contract's redaction rule; use the existing fixed warning and test a secret-bearing exception.
    Confidence: 0.97
  • [P1] Gate before starting the app-server prewarm — extensions/codex/src/app-server/run-attempt.ts:39-42
    This call happens after runtime preparation, which launches and initializes the shared Codex app-server through prewarm. A blocked run therefore still starts the native process; defer prewarm until successful admission and prove a blocked real-client path makes no initialize or spawn.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3d302c58c6e9.

Labels

Label changes:

  • add P1: The branch can let a plugin harness bypass a configured fail-closed admission gate before native execution.
  • add merge-risk: 🚨 compatibility: The branch exports a new public Plugin SDK helper and raises the public-surface budget without an approved long-term contract.
  • add merge-risk: 🚨 security-boundary: A mutable host admission decision is passed into non-builtin harness parameters and trusted before hook execution.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Authority-chain proof required: the body reports tests and checks only; add redacted real app-server evidence showing blocked admission neither initializes/spawns Codex nor permits a hostile harness to bypass the gate. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P1: The branch can let a plugin harness bypass a configured fail-closed admission gate before native execution.
  • merge-risk: 🚨 security-boundary: A mutable host admission decision is passed into non-builtin harness parameters and trusted before hook execution.
  • merge-risk: 🚨 compatibility: The branch exports a new public Plugin SDK helper and raises the public-surface budget without an approved long-term contract.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Authority-chain proof required: the body reports tests and checks only; add redacted real app-server evidence showing blocked admission neither initializes/spawns Codex nor permits a hostile harness to bypass the gate. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [high] Writable gate decision bypasses fail-closed admission — src/agents/embedded-agent-runner/run/run-attempt-dispatch.ts:273
    A non-builtin harness receives the mutable memo and can preseed a proceed result that the new helper trusts before executing registered policy hooks.
    Confidence: 0.98
  • [high] Thrown hook errors can expose prompt data in logs — src/agents/harness/lifecycle-hook-helpers.ts:170
    The gate receives prompt and history data, while the new catch serializes arbitrary exception text into the agent-harness log.
    Confidence: 0.97

What I checked:

Likely related people:

  • jesse-merhi: Local commit metadata identifies the feature that added the user-input blocking lifecycle gate and its redacted persistence behavior. (role: introduced generic hook contract; confidence: high; commits: 1c42c774339c; files: src/plugins/hook-types.ts, src/plugins/hook-decision-types.ts)
  • steipete: Recent Codex trajectory work directly touched native attempt-resource and trajectory ownership adjacent to this blocked-start cleanup. (role: recent Codex native lifecycle contributor; confidence: high; commits: 5301fb5e7f3c; files: extensions/codex/src/app-server/run-attempt-resources.ts, extensions/codex/src/app-server/trajectory.ts)
  • joshavant: Recent work on native approval scope is adjacent to the authority boundary this PR changes. (role: recent Codex native authority contributor; confidence: medium; commits: 50720c3b8e57; files: extensions/codex/src/app-server/approval-bridge.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.

@johnny7861532
johnny7861532 deleted the fix/codex-native-before-agent-run-hook branch August 23, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: codex 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant