Skip to content

feat(codex): enforce Gateway tool policy for model callbacks - #174565

Merged
stevenlee-oai merged 36 commits into
mainfrom
dev/stevenlee/codex-gateway-tool-policy-p0
Oct 21, 2026
Merged

stevenlee-oai merged 36 commits into
mainfrom
dev/stevenlee/codex-gateway-tool-policy-p0

Conversation

@stevenlee-oai

@stevenlee-oai stevenlee-oai commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Implements RFC-0021 item 5 and the Codex callback portion of item 8 (RFC), building on the merged #174547 and #174580.

What Problem This Solves

Gateway-supplied tools and callbacks in Codex must obey the deployment's Gateway tool policy.

User Impact

When tools.gatewayPolicy is configured, Codex receives only permitted Gateway tools and actions, and callbacks reject prohibited actions before execution. Codex-native tools and direct human Gateway administration retain their existing permissions. Behavior without the policy is preserved.

The policy is captured when tools are constructed. Changes require Gateway restart or replacement after affected old work ends. Saved native declarations keep their fingerprints; reconstructed callbacks can therefore deny an older advertised call.

Why This Change Was Made

The adapter reuses the shared Gateway policy for catalog projection and final argument validation after preparation and hooks, including MCP callbacks. Ordinary tool restrictions and supplemental exclusions can narrow access further.

Unreadable descriptors are quarantined before policy filtering, preserving healthy tools and genuine discovery controls. Invalid policy configuration still fails explicitly. This PR changes the Codex adapter, not native Codex or OCE's runtime pin.

Evidence

  • 86 focused cases across five adapter suites cover filtering, restored/fallback callbacks, hook-adjusted actions, discovery controls and native-tool availability. The availability suite was rerun after repairing its import alias; passing evidence for the other unchanged suites is retained.
  • Extension production/test typechecks, targeted lint, formatting, line-cap and assertion-safety checks, and the config baseline check pass.
  • Fresh independent correctness and maintainability review found no remaining material issue.
  • CI's test-ownership audit fails on a memory test assigned to both infra and extension database-worker suites. The same failure occurs on scheduled main CI; it also reproduces locally on this head. The owning configurations match main.
  • The repository-wide max-lines-suppression check reports three UI files already present on the merged main commit e9981073bdd; those files and the baseline are unchanged by this PR.

These checks use controlled adapter fixtures. Earlier isolated OCE qualification used pinned runtime c2976c807b7 with Codex 0.163.0-alpha.2; it does not qualify the updated head. Updated-head deployment qualification, CI and human review remain incomplete.

@clawsweeper

clawsweeper Bot commented Oct 16, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: M labels Oct 16, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 16, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Applies the shared Gateway tool policy to Codex tool catalogs and retained callbacks, including hook-adjusted MCP calls.

Example: The policy permits managed_task with action read, then changes to an empty allowlist during the turn.

  • Before: The Codex adapter has no explicit Gateway-policy check for the retained callback.
  • After: The retained read callback returns a policy denial without executing the tool.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is coherent and the prior finding is resolved, but fixture evidence does not qualify this authorization change for merge.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Deployment owners need Gateway-supplied Codex callbacks to obey the deployment's tool and action ceiling.
Reason: The supplied maintainer-authored direction establishes the product choice, and the adapter closes a distinct enforcement path without introducing another policy owner.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open: it provides distinct Codex policy integration, and the earlier descriptor-quarantine finding is fixed; no new actionable code defect was identified.

Priority: P2
Reviewed head: 0a32f5f9fb4e80ebbd98d16b1df4e1f0b04983ef

Before merge

  • Add real behavior proof - Authority-chain proof required: supplied checks exercise catalog projection and callback handling with controlled executors, not real Codex-to-tool side effects. Show a permitted action reaching its effect, a prohibited action and hook rewrite rejected before I/O, and a retained/restored callback rejected after policy tightening, including tightening during an awaited hook or approval. Provide redacted terminal output, logs, or a recording; remove IPs, API keys, phone numbers, and non-public endpoints. Saved declarations retain their existing format and fingerprint, so this adapter introduces no persisted-data migration. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Resolve security review attention item - Source inspection found no concrete bypass, but the changed authorization boundary still requires final-effect qualification.
  • Resolve merge risk - Qualify retained-callback enforcement at the final side-effect boundary, including policy tightening while a call awaits hooks or approval.

Findings

None.

Tests

  • Missing end-to-end proof: Provide real Codex callback traces showing allowed execution and no side effect for denied or revoked calls; base-fail/head-pass evidence for the new policy cases is not supplied.
Agent review details

How this fits together

The Codex adapter projects Gateway tools into native declarations and translates model callbacks into shared host-tool execution, where hooks, policy checks, and argument validation precede implementation dispatch.

flowchart LR
  A[Gateway tools and policy] --> B[Codex catalog projection]
  B --> C[Codex app server]
  C --> D[Retained callback bridge]
  D --> E[Hooks and final argument checks]
  E --> F[Shared policy assertion]
  F --> G[Tool implementation]
Loading

Technical review

Best possible solution:

Keep the adapter on the shared policy owner and qualify permitted, prohibited, and revoked callbacks through the real Codex execution path.

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

This is a feature integration; source inspection establishes the added enforcement path, while the submitted tests use controlled fixtures and no target code was executed during review.

Is this the best way to solve the issue?

Reusing the shared policy projector and assertion is the appropriate design, and the patch preserves native catalog identity and MCP-owned schema validation.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Qualify final-effect enforcement (recommended)
    Record allowed execution and denied side effects for prohibited actions, restored callbacks, hook rewrites, and policy revocation before dispatch.
  2. Keep the integration draft
    Retain the draft until the dependency stack and deployed callback qualification are complete.

Provenance checked

  • Descriptor quarantine keeps the original intent (3ffb360: Keep malformed plugin descriptors from preventing healthy sibling tools from registering.)
  • Saved declaration and executable separation keeps the original intent (f5f44fa: Preserve immutable native declarations while independently supplying currently eligible child-run executors.)
  • Final argument validation and shared invocation keeps the original intent (cef77d1: Validate final hook-adjusted native arguments before side effects while leaving external MCP schema validation with its server; shared invocation was subsequently consolidated in 51a27d4.)
  • Policy-filtered tool construction keeps the original intent (cbc53ac: Normalize the prepared runtime surface without activating another provider runtime during durable catalog construction.)

Testing

Proof path: in-process harness.

Security

Needs attention: Source inspection found no concrete bypass, but the changed authorization boundary still requires final-effect qualification.

Evidence

What I checked:

  • Pinned introduction and current-main boundary: The introduced diff adds policy integration to the adapter; fetched main's catalog projection and harness runtime SDK do not contain these policy additions. The shared foundation remains in the open dependency stack. (extensions/codex/src/app-server/dynamic-tool-catalog.ts:128, 0a32f5f9fb4e)
  • Previous finding resolved: Descriptors now pass through the guarded reader before policy projection, preserving concrete control identity; the regression covers available, registered, and fallback tools under absent, captured, and current policy. (extensions/codex/src/app-server/dynamic-tool-catalog.ts:121, 0a32f5f9fb4e)
  • Callback authority path: The bridge asserts captured and current policy on final arguments before exempting external MCP tools from host schema validation; the shared wrapper also checks current policy immediately before implementation dispatch. (extensions/codex/src/app-server/dynamic-tools.ts:415, 0a32f5f9fb4e)
  • Accepted policy semantics and supplied evidence: The maintainer-authored direction explicitly preserves native Codex permissions, saved declaration fingerprints, and already-dispatched work. The body and author discussion distinguish controlled fixture checks from pending deployed qualification; the draft head is mergeable. (0a32f5f9fb4e)
  • Linked deployment evidence does not qualify callbacks: The linked integration's body reports that its diagnostic did not reach policy denials, narrower-policy redeployment, or Codex qualification; its earlier shell smoke does not exercise this change.
  • Native callback contract inspected: The adapter consumes this protocol directly: DynamicToolCall items become server requests carrying thread, turn, call, namespace, tool, and arguments, and native execution waits for the host response. This establishes the dependency-contract relevance. (codex-rs/app-server/src/bespoke_event_handling.rs:1087, c1382380de69)

Likely related people:

  • Peter Steinberger: Raw commit f5f44fa adds extensions/codex/src/app-server/dynamic-tool-catalog.ts:112 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f5f44faeca4e; files: extensions/codex/src/app-server/dynamic-tool-catalog.ts)
  • Sarah Fortune: Raw commit 51a27d4 adds extensions/codex/src/app-server/dynamic-tools.ts:476 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 51a27d44d5b7; files: extensions/codex/src/app-server/dynamic-tools.ts)

PR surface

Source +66, Tests +432, Docs +13. Total +511 across 11 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 4 125 59 +66
Tests 6 497 65 +432
Docs 1 13 0 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 635 124 +511

Labels

Label changes:

  • add merge-risk: 🚨 security-boundary: The change governs model access to Gateway side effects, and final-effect rejection under retained or revoked authority remains unqualified.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: This is an opt-in deployment-policy integration with a bounded Codex adapter scope.
  • merge-risk: 🚨 security-boundary: The change governs model access to Gateway side effects, and final-effect rejection under retained or revoked authority remains unqualified.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Add final-effect proof for prohibited model actions and prove that policy revocation invalidates retained callbacks before I/O.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-16T19:21:07.361Z sha 45dd440 :: needs real behavior proof before merge. :: [P2] Preserve descriptor quarantine before applying Gateway policy

Reviewed October 16, 2026, 10:48 PM ET / October 17, 2026, 02:48 UTC (Revision 2).

@stevenlee-oai
stevenlee-oai changed the base branch from dev/stevenlee/gateway-tool-policy-p0 to dev/stevenlee/gateway-automation-policy-p0 October 16, 2026 19:33
Base automatically changed from dev/stevenlee/gateway-automation-policy-p0 to main October 21, 2026 17:44
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: XL and removed size: L labels Oct 21, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 21, 2026
@stevenlee-oai
stevenlee-oai marked this pull request as ready for review October 21, 2026 18:06

Copy link
Copy Markdown
Contributor Author

Codex: resolved the conflicts in 90d7c6a7d07 against main after #174580 merged. The diff is now limited to 11 Codex-adapter/docs/test-routing files; core policy, automation and scheduling-auth implementations come from main.

The adapter now follows the deployment contract: capture policy when constructing tools; activate changes through Gateway restart/replacement after affected old work ends. Final post-hook action authorization remains enforced, including MCP callbacks. Live-update test expectations were replaced with reconstruction coverage, including construction without a hook context.

The focused adapter suites cover 86 cases; extension production/test types, scoped lint, formatting, line-cap/assertion-safety and config-baseline checks pass. The max-lines-suppression check reports three unchanged UI files already in main, documented in the description. Fresh independent source review found no material issue. Earlier deployed proof remains attributed to its pinned runtime; it is not claimed for this updated head. CI and updated-head deployment qualification remain pending.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Codex: the failed test on 90d7c6a7d07 is an inherited test-routing defect, confirmed by matching CI signatures and a focused local reproduction.

Both fail test/vitest-projects-config.test.ts:288: extensions/memory-core/src/memory/manager-duplicate-chunks.postgres.test.ts belongs to both the infra and extension database-worker projects. The core registry explicitly lists it, while the extension project already includes extensions/memory-core/**/*.test.ts. The relevant configs, core registry and failing test are unchanged from main; this PR's routing delta only adds its separate Codex policy test.

The focused local command reproduces that exact duplicate: pnpm test test/vitest-projects-config.test.ts --maxWorkers=1 -t 'covers each normal full-suite test file exactly once after configs cached filtered includes'.

The automatic classifier labels the job new because main's job with the same shard number passed and its log lookup was unavailable. Shard contents differ: the identical failed test is in main's shard 40. The linked logs establish attribution independently of that job-name comparison. The shared routing repair should leave the memory test with one owner. This evidence is also recorded in the PR description.

@stevenlee-oai
stevenlee-oai merged commit 6796ef3 into main Oct 21, 2026
108 checks passed
@stevenlee-oai
stevenlee-oai deleted the dev/stevenlee/codex-gateway-tool-policy-p0 branch October 21, 2026 20:01
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…w#174565)

* feat(gateway): enforce required model tool and action policy

* fix(gateway): accept unvalidated tool descriptors in policy helpers

* test(gateway): qualify tool policy fixtures and config schema

* feat(codex): enforce Gateway tool policy for model callbacks

* test(gateway): type the action rewrite fixture

* refactor(agents): keep final tool policy assembly together

* feat: restrict model automation administration through Gateway policy

* fix(codex): retain genuine discovery controls in restored catalogs

* fix(worker): retain prepared prompt report in turn results

* fix(gateway): admit caller-owned automation mutations

* fix(codex): quarantine unreadable tools before policy filtering

* fix: backport managed Gateway compatibility repairs

Retain the reviewed caller-scoped automation admission and Codex descriptor quarantine repairs on the pinned runtime source.

Sources: 2f1333a and ba2c7ce.

* fix(cron): avoid host auth capture for required workers

* fix(cron): avoid host auth capture for required workers

* fix(worker): preserve Gateway tool errors across proxy calls

* fix(worker): preserve Gateway tool errors across proxy calls

* fix(cron): use selected Harness authentication for schedules

* fix(cron): use selected Harness authentication for schedules

---------

Co-authored-by: stevenlee-oai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:feature Preliminary submission classification; full source review pending. docs Improvements or additions to documentation extensions: codex merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant