Skip to content

fix(codex): unify conversation permission policy - #128464

Merged
steipete merged 3 commits into
mainfrom
steipete/fix-codex-conversation-permission-policy
Aug 24, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/fix-codex-conversation-permission-policy

Conversation

@steipete

@steipete steipete commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Split authorization ownership allowed conversation recovery, dynamic Gateway execution, and recovery compaction to consume raw or stale permission overlays after native Codex capability and requirements clamps had already narrowed the effective policy. Missing or rebound v2 source sessions could also continue toward client acquisition instead of failing closed.

Why This Change Was Made

One post-clamp effective permission mode, workspace root, and execution tuple now owns native Codex execution, dynamic tools and the Gateway alias, cwd/workspace roots, restart recovery, side questions, and compaction/shared tool construction. The run carries that final tuple through overflow/recovery compaction instead of reconstructing authority from the originally requested session mode.

Legacy conversation-binding permission fields are parse-only, so stale overlays cannot silently reclaim authorization ownership. The repair also uses existing safe-bin configuration in its boundary tests rather than importing broad internal SDK/runtime test surfaces.

User Impact

Guarded mode pins human approval even for allowlisted Gateway commands. Unclamped full mode remains no-prompt, while clamped full mode becomes workspace/Guardian or a safer effective policy. Compaction cannot restore the originally requested full policy after that clamp. Generic sessions without an explicit permission mode continue using their configured defaults.

Missing or rebound v2 source sessions now fail closed before client acquisition. Native conversation-bound Codex cannot transport human approval prompts, so guarded bound turns fail visibly with actionable guidance; ordinary harness guarded Gateway execution still reaches the real human-approval boundary.

The production path changes by +278/-254 (net +24). Tests change by +552/-49 (net +503).

Evidence

Test-first regression coverage reproduced the permission-policy and stale-source failures before the fixes. The final focused permission, conversation, Gateway, side-question, and compaction suite passes 613 tests across nine files and three shards. Changed-file checks, the plugin import-boundary scan across 6,644 files, branch diff checks, types/lint/import-cycle gates, and a fresh structured autoreview are clean.

The upstream Codex contract was checked directly in codex-rs/app-server-protocol/src/protocol/v2/shared.rs, codex-rs/protocol/src/protocol.rs, codex-rs/app-server/src/request_processors/thread_processor.rs, and the v2 thread-resume tests: never never escalates, on-request may request approval, the three sandbox modes are distinct, resume overrides beat persisted policy, and live-thread policy mismatches are rejected rather than silently applied.

Focused proof covers:

  • full native and Gateway execution remain no-prompt only for the final danger-full-access + never tuple
  • guarded allowlisted Gateway execution still returns approval_required
  • capability/requirements clamps are applied before dynamic tools and native connection setup consume policy
  • full → workspace/auto survives overflow/recovery compaction without regaining full execution
  • full/full survives compaction unchanged
  • stale or rebound source sessions fail before Codex client acquisition
  • rootless partial permission state fails closed
  • generic sessions without a permission mode preserve config-owned defaults

Final-effect authority proof

Trusted-source fallback was used because the remote Testbox client was unauthenticated. At exact head 765c6728c0db3f5c9e19910725b4d7431789e854:

node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tool-build.test.ts -t 'enforces the final'

The proof-only augmentation exercised the real createOpenClawCodingTools → gateway_exec composition with the same allowlisted touch executable in both modes. Full mode completed and created its marker with no approval request. Explicit guarded mode returned failureKind: approval_required, and its marker remained absent (ENOENT), proving rejection before spawn/I/O. Both cases passed in one file; the augmentation was then restored byte-for-byte and the branch remained clean at the reviewed SHA.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 24, 2026 02:51
@steipete steipete self-assigned this Aug 24, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 24, 2026, 4:42 AM ET / 08:42 UTC.

ClawSweeper review

What this changes

This PR derives one post-clamp Codex permission tuple and carries it through native turns, Gateway tools, side questions, conversation recovery, and compaction.

Regression provenance

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

Merge readiness

⚠️ Needs maintainer review before merge - 7 items remain

Keep open: the central policy propagation is coherent and the reported final-effect trace is relevant, but the branch changes the established meaning of permissions default and strands older pinned session records without an upgrade path.

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

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused authority proof is useful, but the patch needs compatibility and migration corrections before it is merge-ready.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body supplies an after-fix terminal trace through the real coding-tool composition: guarded execution returned approval_required and left its marker absent before I/O; independently checking the Codex protocol remains separate reviewer work.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies an after-fix terminal trace through the real coding-tool composition: guarded execution returned approval_required and left its marker absent before I/O; independently checking the Codex protocol remains separate reviewer work.
Evidence reviewed 7 items Permission policy owner: The new resolver derives the effective mode only after the resolved app-server sandbox, approval policy, and reviewer are known, then supplies the matching exec mode.
Final tuple reaches dynamic tools: Dynamic tool construction overrides raw exec mode with the effective policy and passes the same policy to the shared coding-tool factory.
Default command behavior changed: The branch now writes guarded for the command called default; its focused test confirms that persisted state. The available pre-PR main mirror shows the prior implementation deleted the explicit permission mode.
Findings 2 actionable findings [P1] Preserve the configured meaning of permissions default
[P1] Migrate rootless persisted permission modes before consuming them
Security Needs attention Verify the pinned Codex protocol contract before merge: This resolver turns Codex sandbox and approval fields into final Gateway execution authority. The local checkout contains no sibling Codex source, so the claimed behavior of the pinned upstream protocol remains unverified by this review.

Live Verification

Command: node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tool-build.test.ts -t 'enforces the final'

Result: PASS (completed)

node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tool-build.test.ts -t 'enforces the final'
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128464-GoViU0/target$ node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tool-build.test.ts -t
 'enforces the final'
node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tool-build.test.ts -t 'enforces the final'
[test] starting test/vitest/vitest.extension-codex.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128464-GoViU0/target

 ✓  extension-codex  extensions/codex/src/app-server/dynamic-tool-build.test.ts (87 tests | 85 skipped) 2380ms
     ✓ enforces the final 'guarded' policy for an allowlisted Gateway command  1566ms
     ✓ enforces the final 'full' policy for an allowlisted Gateway command  809ms

 Test Files  1 passed (1)
      Tests  2 passed | 85 skipped (87)
   Start at  08:42:55
   Duration  28.12s (transform 21.57s, setup 967ms, import 24.40s, tests 2.38s, environment 0ms)

[test] passed 1 Vitest shard in 34.13s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128464-GoViU0/target$ node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tool-build.test.ts -t
 'enforces the final'































Assertions:

  • PASS expect_output: enforces the final

How this fits together

Codex conversation sessions feed a selected permission mode and workspace root into the app-server runtime and OpenClaw tool builder. That policy controls native Codex execution, Gateway shell aliases, and recovery compaction before commands can reach process I/O.

flowchart LR
  A[Conversation session] --> B[Requested permission and root]
  B --> C[App-server policy clamp]
  C --> D[Effective permission tuple]
  D --> E[Native Codex turn]
  D --> F[Gateway and side tools]
  D --> G[Recovery compaction]
  F --> H[Process approval and I/O]
  G --> H
Loading

Decision needed

Question Recommendation
Should permissions default continue to clear the session override and use configured defaults, or intentionally become a persistent guarded mode? Preserve reset semantics: Keep default as removal of the explicit pin, route configured defaults through the centralized effective-policy resolver, and add an upgrade test for rootless legacy rows.

Why: The branch deliberately changes a previously resettable persisted user setting, and the safe migration behavior depends on which public meaning maintainers choose.

Before merge

  • Preserve the configured meaning of `permissions default` (P1) - default previously removed the per-session override, but this now persists guarded while still telling the user it set the mode to default. That silently replaces configured defaults for existing sessions; either retain reset semantics through the centralized resolver or make guarded mode an explicit, approved user-facing setting.
  • Migrate rootless persisted permission modes before consuming them (P1) - Older permission commands could persist permissionMode without sessionRoot. Conversation recovery now consumes that mode and the policy owner rejects it for lacking a root, so those existing sessions fail instead of receiving an upgrade repair. Normalize or retire the legacy row in a migration/Doctor path before this runtime boundary.
  • Resolve security concern: Verify the pinned Codex protocol contract before merge - This resolver turns Codex sandbox and approval fields into final Gateway execution authority. The local checkout contains no sibling Codex source, so the claimed behavior of the pinned upstream protocol remains unverified by this review.
  • Resolve merge risk (P1) - The required direct inspection of the pinned Codex app-server protocol could not be completed because no sibling Codex source checkout is available in this read-only environment.
  • Resolve merge risk (P1) - The bug fix adds a net 24 production lines; retain only the canonical effective-policy flow after resolving the compatibility findings.
  • Complete next step (P2) - A maintainer must choose the public meaning of permissions default before a safe compatibility repair can be made.

Findings

  • [P1] Preserve the configured meaning of permissions default — extensions/codex/src/conversation-control.ts:334-344
  • [P1] Migrate rootless persisted permission modes before consuming them — extensions/codex/src/conversation-binding.ts:217-260
  • [medium] Verify the pinned Codex protocol contract before merge — extensions/codex/src/app-server/session-permission-policy.ts:212
Agent review details

Security

Needs attention: The authority path is thoughtfully narrowed, but the required direct upstream Codex protocol check could not be independently performed in this environment.

PR surface

Source +24, Tests +503. Total +527 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 14 293 269 +24
Tests 9 562 59 +503
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 855 328 +527

Review metrics

Metric Value Why it matters
Permission reset semantics 1 command changed: clears override → persists guarded Existing sessions that request the documented/default mode no longer return to their configured policy.
Production versus tests production +278/-254 (net +24); tests +552/-49 (net +503) The added production surface is security-sensitive and should remain limited to the canonical policy owner.

Stored data model

Persistent data-model change detected: serialized state: extensions/codex/src/app-server/session-permission-policy.test.ts, serialized state: extensions/codex/src/app-server/session-permission-policy.ts, unknown-data-model-change: extensions/codex/src/app-server/session-permission-policy.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Preserve configured reset behavior (recommended)
    Restore default as an actual reset and add a migration-safe test for existing permission rows before merging.
  2. Make guarded reset an explicit product change
    If the hardened behavior is intended, rename the command/result and add an upgrade recovery path rather than silently persisting guarded mode.

Technical review

Best possible solution:

Keep one post-clamp policy tuple, but make the user-facing default reset release the explicit override and migrate or repair legacy rootless permission rows before ordinary runtime reads.

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

Yes, from source: a prior session with an explicit mode but no stored root now reaches the conversation policy application path and fails; permissions default also demonstrably persists guarded instead of clearing the override.

Is this the best way to solve the issue?

No: the centralized final tuple is the right owner boundary, but the changed default-setting contract and legacy stored rows need an explicit compatibility decision and migration path.

Full review comments:

  • [P1] Preserve the configured meaning of permissions default — extensions/codex/src/conversation-control.ts:334-344
    default previously removed the per-session override, but this now persists guarded while still telling the user it set the mode to default. That silently replaces configured defaults for existing sessions; either retain reset semantics through the centralized resolver or make guarded mode an explicit, approved user-facing setting.
    Confidence: 0.97
  • [P1] Migrate rootless persisted permission modes before consuming them — extensions/codex/src/conversation-binding.ts:217-260
    Older permission commands could persist permissionMode without sessionRoot. Conversation recovery now consumes that mode and the policy owner rejects it for lacking a root, so those existing sessions fail instead of receiving an upgrade repair. Normalize or retire the legacy row in a migration/Doctor path before this runtime boundary.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9b2b195e10fa.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: It changes a persisted session setting from resettable to explicit guarded behavior and now requires a session root.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an after-fix terminal trace through the real coding-tool composition: guarded execution returned approval_required and left its marker absent before I/O; independently checking the Codex protocol remains separate reviewer work.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit 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 PR body supplies an after-fix terminal trace through the real coding-tool composition: guarded execution returned approval_required and left its marker absent before I/O; independently checking the Codex protocol remains separate reviewer work.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: The PR can alter existing Codex conversation permission behavior and block prior persisted sessions.
  • merge-risk: 🚨 compatibility: It changes a persisted session setting from resettable to explicit guarded behavior and now requires a session root.
  • merge-risk: 🚨 security-boundary: The changed tuple controls whether Gateway commands require approval before process I/O.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit 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 PR body supplies an after-fix terminal trace through the real coding-tool composition: guarded execution returned approval_required and left its marker absent before I/O; independently checking the Codex protocol remains separate reviewer work.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an after-fix terminal trace through the real coding-tool composition: guarded execution returned approval_required and left its marker absent before I/O; independently checking the Codex protocol remains separate reviewer work.

Evidence

Security concerns:

  • [medium] Verify the pinned Codex protocol contract before merge — extensions/codex/src/app-server/session-permission-policy.ts:212
    This resolver turns Codex sandbox and approval fields into final Gateway execution authority. The local checkout contains no sibling Codex source, so the claimed behavior of the pinned upstream protocol remains unverified by this review.
    Confidence: 0.98

What I checked:

Likely related people:

  • steipete: Authored the three commits on this PR and the available adjacent main history attributes the surrounding Codex policy and compaction work to the same contributor. (role: recent permission-policy contributor; confidence: high; commits: 68c48422cc6e, 765c6728c0db; files: extensions/codex/src/app-server/session-permission-policy.ts, extensions/codex/src/conversation-control.ts, src/agents/embedded-agent-runner/prepared-compaction-runtime.ts)

Rank-up moves

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

  • Restore or explicitly rename the changed permissions default contract and cover configured-default behavior.
  • Add an upgrade-safe migration or recovery path for rootless stored permission modes.
  • Have a reviewer with the sibling Codex source inspect the pinned approval, sandbox, and resume contract directly.

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 (3 earlier review cycles)
  • reviewed 2026-08-24T02:56:40.415Z sha 83b8b9a :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-24T03:27:56.943Z sha 83b8b9a :: needs real behavior proof before merge. :: [P1] Verify the effective exec mode during compaction
  • reviewed 2026-08-24T06:31:25.051Z sha 765c672 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 24, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor Author

Direct upstream Codex contract review is complete against the sibling openai/codex source checkout:

  • codex-rs/app-server-protocol/src/protocol/v2/shared.rs:174-247,303-324 defines the v2 approval policy, approval reviewer, and distinct sandbox modes consumed by this plugin.
  • codex-rs/protocol/src/protocol.rs:924-946,1006-1057,1140-1179 confirms never does not escalate, on-request may request approval, and danger-full-access/workspace-write/read-only have distinct write and network authority.
  • codex-rs/app-server/src/request_processors/thread_processor.rs:138-177 compares requested approval/reviewer/sandbox values with the active thread configuration and reports mismatches instead of silently applying them to a live thread.
  • codex-rs/app-server/tests/suite/v2/thread_resume.rs:727-753 proves persisted approval policy is restored on resume and an explicit resume override wins.

These contracts support the PR's final tuples: full is no-prompt only as danger-full-access + never; guarded/workspace remain on-request; and a post-clamp tuple must remain authoritative through resume and compaction. The remaining pre-merge gate is the redacted final-effect authority trace requested by ClawSweeper.

@steipete

Copy link
Copy Markdown
Contributor Author

Final-effect authority proof is complete on exact head 765c6728c0db3f5c9e19910725b4d7431789e854.

The remote Testbox client was unavailable (not authenticated), so I used the repository-approved trusted-source fallback:

node scripts/run-vitest.mjs extensions/codex/src/app-server/dynamic-tool-build.test.ts -t 'enforces the final'

The proof-only augmentation exercised the real createOpenClawCodingTools → gateway_exec composition with touch configured as the same allowlisted executable in both cases:

  • full: result status: completed; the marker file existed; no approval request
  • guarded: result status: failed, failureKind: approval_required; fs.stat(marker) returned ENOENT

That proves guarded policy rejects before command spawn/I/O rather than merely projecting a guarded option object. The focused run passed both cases in one file (85 unrelated cases skipped; 20.16s wrapper). The augmentation was restored byte-for-byte (SHA-256 81061698bc642e3653aa84e52b599b4a45ab0af3226919b6e46a8361aba77a73), and the branch is clean at the reviewed SHA.

The native review artifacts now validate with READY FOR /prepare-pr, zero findings.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🧂 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 24, 2026
@steipete
steipete merged commit a435cf6 into main Aug 24, 2026
243 of 245 checks passed
@steipete
steipete deleted the steipete/fix-codex-conversation-permission-policy branch August 24, 2026 08:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 25, 2026
* fix(codex): unify conversation permission policy

* fix(codex): reject stale conversation sources

* fix(codex): preserve permissions through compaction
nvtoroy added a commit to nvtoroy/openclaw that referenced this pull request Sep 11, 2026
…1009)

Adds plugins.entries.codex.config.appServer.nativeHookRelay = { enabled? } -
a single narrowly scoped opt-out wiring the existing internal relay options of
the run-attempt and side-question paths to plugin config. Without the key the
parse layer returns the historical { enabled: true } byte-for-byte.

The parse layer carries no policy logic. A single guard
(resolveCodexNativeHookRelayForApprovalPolicy) applies the safety floor in
both run paths after runtime policy resolution, keyed on the EFFECTIVE
approval policy - the resolved value, which can force a prompting policy over
a configured "never" (unknown-model or exec-mode reviewer forcing, forced
guardian reviewer, forced danger-full-access sandbox), and on the
side-question path is the bound thread's policy when a persistent binding
carries one:

- effective "never" AND no active OpenClaw before-tool policy
  (hasBeforeToolCallPolicy(): before_tool_call hook or trusted-tool policy -
  the same predicate the relay's own local-work gate uses) -> the opt-out is
  honored verbatim: the opt-out overlay clears OpenClaw's four session-layer
  hook arrays and writes disabled hooks.state markers for its session-layer
  command keys, leaving features.hooks and independent user/project/plugin/
  managed Codex hooks untouched (review finding: features.hooks=false would
  disable the whole hook engine pre-discovery; the overlay also deliberately
  OMITS features.hooks rather than asserting true, because it merges last and
  would otherwise re-enable hooks for ring-zero callers). The harness-
  restricted sandbox path keeps full suppression via its own builder. This is
  the constrained-host case from openclaw#91009, including stock yolo deployments.
- otherwise (a prompting/forced effective policy, or an active before-tool
  policy under explicit "never") -> enabled:false narrows to the required
  before-tool policy relay (events: ["pre_tool_use"]) and logs a one-line
  deduped warning naming the actual reason. The floor mirrors
  loopDetectionPreToolUseRelay's contract ("before-tool plugin hooks and
  trusted-tool policy still install their required relay").

Event scoping stays an internal option of the run paths with upstream's own
semantics (openclaw#116117, "honor hook approval ownership"); it is deliberately not
exposed to operator config. The
relay object is strict at BOTH boundaries: the plugin manifest
(additionalProperties: false) rejects unknown keys at load time with a named
config error, and the zod parser stays strict as defense in depth; covered at
the manifest/loader boundary against the real manifest.

The approval transport is out of this key's reach by construction: approvals
ride the app-server approval bridge over JSON-RPC and fall back to the
in-process before_tool_call hook when the relay is absent. The forced-policy
case is pinned by an integration test through
resolveCodexAppServerRuntimeOptions; a manifest/zod parity test covers the
schema. An opt-in live capture lane
(gateway-codex-harness.native-hook-relay-proof.live.test.ts) reproduces the
wire evidence against a real codex app-server and asserts the captured
thread/start and thread/fork hook overlays per mode and per path.

Rebased onto app-server 0.153.4 main. Three adaptations were needed. (1) The
managed-only hook attestation added since the merge base gates
assertCodexNativeHookRelayAllowed on nativeHookRelayRequired, which read the
RAW operator relay config; a narrowed opt-out would therefore have skipped
attestation while still installing the enforcing relay, failing open on
allowManagedHooksOnly installs. It now reads the guarded shape, so the
narrowing arms the assert instead of disarming it (regression test added).
(2) openclaw#128464 removed resolveCodexAppServerForOpenClawToolPolicy and its
never->untrusted promotion; the effective policy now comes from
applyCodexSessionPermissionPolicy, which never consults
hasBeforeToolCallPolicy() and resolves permission mode "full" to "never". The
guard's two-predicate design is unchanged, but its rationale comment now cites
session permission modes and config-runtime's forced policies. (3) Loop
detection became explicit opt-in and the selected-but-no-work PreToolUse
marker was removed, so the live proof lane now enables tools.loopDetection so
its "installed" expectations still hold and attestation is exercised;
deliberately loop detection rather than a global before_tool_call hook, which
would narrow the disabled-never mode and stop the lane proving the full
kill-switch.

Re-based again onto current main. The three adaptations above still hold; the
refresh only followed upstream moves. The reference table the relay row lives in
was split out to docs/plugins/codex-harness-reference/app-server-transport.md.
CodexPluginConfig is now derived from the zod schema, so the relay field comes
from config-parsing and CodexNativeHookRelayOptions moved to the leaf
config-contracts.shared.ts (config-contracts re-exports it) to keep the module
graph acyclic. Live-shard membership is now discovery-driven, so the proof lane
needs no shard-list edit; it still routes to native-live-src-gateway-core. On
the side-question path the guard keys on appServer.approvalPolicy, the same
value the relay's own event scoping uses, rather than the MCP-elicitation-
widened policy introduced since, which grants elicitation only and opens no
tool-approval path.

Coverage extended to the canonical fork preparation path (openclaw#134660).

Proof-lane refresh: request/test timeouts resized to real backend latency, the two approval modes migrated off the retired "untrusted" policy to on-request with an explicit approvalsReviewer: "user" so the escalation escapes the in-process auto_review subagent and is observable on the wire, and all captures re-recorded on codex 0.153.4 / gpt-5.6-terra.

The proof lane also covers existing-session transitions (mode `transition`): one
gateway, one session and one native thread across three real turns while an
operator flips `nativeHookRelay.enabled` off and back on between them. Phase 1
opens the thread with `thread/start` and installs the relay; the flip changes the
merged thread config, so the warm live-thread path's config fingerprint no longer
matches and each later turn is served by a cold `thread/resume` carrying the whole
rebuilt config - the opt-out overlay in phase 2, the relay restored byte-for-byte
in phase 3, on the same thread id. Every phase also asserts that each `hooks.state`
key the overlay writes names OpenClaw's own `<session-flags>` layer and that
`features.hooks` is never written false, which is the mechanical form of "the
opt-out cannot reach a hook it did not install": Codex discovers hooks per config
layer and keys their state by source path.

Re-based onto current main once more; five adaptations, none of them behavior on
the configured path. (1) The cyber-refusal escalation added to `runAttempt` since
the last rebase now runs both its attempts with the resolved relay options rather
than the hardcoded literal, so an escalated retry carries the same kill-switch
decision as the first try. (2) The plugin entry no longer imports the
`app-server/config.js` barrel eagerly, so the harness reads
`resolveCodexAppServerNativeHookRelay` from the `config-parsing.js` leaf it already
loads; importing the barrel would have pulled the app-server runtime graph into
plugin registration (registration-imports.test.ts pins that boundary).
(3) `config-contracts.ts` no longer re-exports `CodexNativeHookRelayOptions`: every
consumer reads the canonical `config-contracts.shared.ts`, and the re-export had no
callers. (4) The live proof lane moved to `src/gateway/test/` and split per topic -
the five static modes, the existing-session transition, and a shared
`*.test-helpers.ts` that owns the gateway bootstrap both use: `src/gateway/*.test.ts`
sits at the 720-root tsgo core-test shard cap, and the single file had outgrown the
1000-line test ceiling. The new attestation suite joins the codex attempt-extra
vitest project so every full-suite test file keeps exactly one owner. (5) The
kill-switch raises the plugin config-surface budget by the two entries it adds
(`nativeHookRelay` and its `enabled` flag) in
docs/.generated/config-baseline.counts.json.

Rebased onto current main again (8b343fc). One further adaptation, in the
tests only: openclaw#145105 made `readCodexCyberAttemptVerdict` read `result.terminal.kind`
directly, so an attempt result without a `terminal` now throws where it previously
read as "not refused". The stub results in this change's own harness and plugin
tests, which only pin the relay options `runAttempt` forwards, carry the same
`{ terminal: { kind: "ok" } }` shape upstream gave its fixtures in that commit.
The escalation invariant is unchanged and still holds: both attempts run through
one `runAttemptOnModel` closure over the resolved relay options, so a retry can
never widen the kill-switch decision the first attempt ran under.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex maintainer Maintainer-authored PR 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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.

1 participant