Skip to content

feat(agents): SAM Codex sessions run repository hooks; Codex rule delivery and Stop gate - #2804

Merged
simple-agent-manager[bot] merged 17 commits into
mainfrom
sam/codex-repo-hook-trust
Nov 17, 2026
Merged

simple-agent-manager[bot] merged 17 commits into
mainfrom
sam/codex-repo-hook-trust

Conversation

@simple-agent-manager

@simple-agent-manager simple-agent-manager Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

SAM-managed Codex sessions now run a repository's own Codex hooks, as Claude Code sessions already run .claude/settings.json hooks. With that, the Codex rule-delivery hook and the Codex test-quality Stop gate from stream A ship. Decision: Raphaël, 2026-11-16 ("if the hooks are defined in the repo ... I think they should" / "Yup. Do it."), idea 01M7J0TXAHGRY8CWA7Y7SJZAK0. Follows PR #2790.

Why nothing ran before

Codex (rust-v0.160.0, which SAM's 0.160.0-sam-c2.2 build is based on) runs a non-managed hook only when its definition has been trusted by hash, which takes an interactive /hooks review. codex-acp 2.1.1 already marks the session's roots as trusted projects (dist/index.js: projects: {<root>: {trust_level: "trusted"}}), so the repository's .codex/ layer was loading, but every hook in it stayed unreviewed and Codex skipped it (probe task 01M7HZ6Q1EVPVPCBN00AM3WN8A). An earlier note blamed project trust; that was wrong.

Change

  • buildCodexACPManagedConfigEnv (moved with the other per-agent startup config writers to packages/vm-agent/internal/acp/session_host_agent_config.go, pure-move commit 2d13120) adds bypass_hook_trust: true to CODEX_CONFIG. codex-acp passes that JSON to every app-server thread as request overrides; codex-rs/app-server/src/config_manager.rs (rust-v0.160.0) maps the key to the hook-trust bypass. Same path for VM and Instant sessions. A first version also added a projects trust entry; the real-process test showed it redundant (codex-acp already does it), so it was removed.
  • Restores from branch sam/codex-rule-delivery-hook: .codex/hooks/rule-context.mjs, the generated .codex/hooks/rule-scopes.json (--check fails when stale), the Codex SessionStart/PreToolUse/Stop entries, .gitignore re-include.
  • Closes the Codex-hook test gaps from the chore(agents): rule 73 becomes a blocking check, Stop test gate on, Codex hook config validated #2790 test review (deny-once with deferred rules, cd and subdirectory cwd, ignored directories, a write/read table, Update/Delete/Move patches, SessionStart sources, per-session state, config wiring, a smoke test with the committed lookup). additionalContextLimit raised to 20000 tokens: the test showed the hook's maximum byte cap sat exactly on the old threshold.
  • Docs: public agents guide (Codex section) and security model, scripts/quality/README.md, rule routing and the generated AGENTS.md block.
  • scripts/diagnostics/seed-codex-hook-probe.sh: seeds a disposable repo for the staging probe.

Security (security-auditor review): hooks run repository-controlled scripts with the session's credentials, whoever wrote them (another project member, a repository contributor). In SAM the agent already runs with full access in that workspace, so no new capability; it applies to every user's repository, which is the decision recorded above. The bypass also runs hooks in the workspace's ~/.codex. Codex strips provider/base-URL keys from project config, and CODEX_CONFIG outranks project config, so SAM's sandbox, approval and model settings hold. The repository's config.toml (including MCP servers that could reuse SAM's bearer env var) was already loaded before this PR, through codex-acp's project trust; documented, not changed here.

Validation

  • TestCodexRunsRepositoryHooksWithSAMConfig (new, opt-in): real codex-acp 2.1.1 + codex-cli 0.160.0 (stock npm, the Instant runtime versions), started through SAM's buildCodexACPManagedConfigEnv, synthetic Responses API. With SAM's config: SessionStart context reaches the model; the canary rule body arrives as a developer message between a read and its output; a shell write into governed paths is refused once with the rule attached and the file is not created; the Stop gate continues the turn once. Control with the pre-change config: none of it. Setting BypassHookTrust back to false turns the two trusted cases red.
  • go test ./internal/acp/ (full package, with the real-process probe enabled), go vet, gofmt
  • pnpm quality:agent-tooling:test (152 tests), pnpm quality:agent-context-budget --check
  • Mutation: BypassHookTrust false -> unit and gateway tests red (13 assertions) and real-process trusted cases red
  • Staging: passed on staging (sammy.party), VM and Instant (below)
  • SonarCloud: duplication and HTTPS findings fixed in 42a7941 (shared real-adapter test helpers, curl --proto =https); real-binary probe re-run 3/3 after the refactor

Staging Verification (REQUIRED for all code changes — merge-blocking)

Deploy run 43971455359 of 14a835910 to staging: success, smoke tests included. No nodes existed before the run; every node below was provisioned after this deploy uploaded the VM agent binaries (rule 27).

Setup: disposable Artifacts project (smoke user), seeded by a Claude Code task running scripts/diagnostics/seed-codex-hook-probe.sh 14a835910… (commit ca6e9db: SAM's Codex hooks, a canary rule .claude/rules/10-probe.md scoped to src/**, src/existing.txt). Then real Codex (openai-codex) conversation sessions:

Session Runtime Result
Read, write, cross-boundary file VM (Hetzner, fresh node) SessionStart text reached the model. Before sed -n 1,2p src/existing.txt the hook injected the rule body including PROBE-RULE-CANARY-7731 (the model never opened the rule file). The later write under src/ was allowed, as designed, because that rule was already delivered. At turn end the Stop gate continued the turn: "Test-quality gate … Cross-boundary source changed on this branch, but no test that covers it changed: apps/api/src/services/probe.ts"
Write first VM (Hetzner, fresh node) printf 'x\n' > src/new.txt refused once: "Command blocked by PreToolUse hook: Not run yet: 1 repository rule(s) governing "src/new.txt" were not in your context. They are attached as context…", canary rule attached; the retry succeeded and the file holds x
Write first Instant (cf-container node) Same as the VM write-first session: refused once with the canary rule, retry succeeded

Pre-existing, not from this PR: each Codex session first said get_instructions was unavailable (deferred MCP tools), as tracked in tasks/backlog/2026-11-07-codex-first-turn-misses-deferred-sam-mcp-tools.md with production examples predating this branch; node logs showed the SAM MCP server registered and written into Codex's config with no errors. The prompts told Codex to skip it.

Cleanup: all four nodes, the agent profile and the project (with its Artifacts repo) deleted; staging lease released early (run 43979032242) and the next queued task notified.

Specialist Review Evidence (Required for agent-authored PRs)

Reviewer Status Outcome
security-auditor ADDRESSED No CRITICAL. HIGH is inherent to the decision (repo code runs with the opener's credentials). MEDIUMs: docs now state the full scope (agents guide, security model, code comment); MCP-redirect deferred with reason (no new capability; project config already loaded before this PR)
go-specialist ADDRESSED No CRITICAL/HIGH. Move verified byte-identical. Trust key/cwd questions resolved by removing the redundant projects entry; real Codex probe added for "0.160.0 accepts the key"
task-completion-validator ADDRESSED WARN, no CRITICAL/HIGH. Stale task-file text from the removed projects design fixed; note added at the Codex pins (gateway.go) to rerun the real-process probe on a bump (2464bbc). Staging pending, as known

CodeRabbit Review Evidence (Required for agent-authored PRs)

  • CodeRabbit requested when the PR was marked ready for review

CodeRabbit Notes

Requested 18:08Z via coderabbit-bot-review.yml (run 43925636583, success). CodeRabbit answered with its Review skipped status (check state skipping), so the wait ended there with no review to resolve (rule 25, policy 73ed7a68).

Agent Preflight (Required)

  • Preflight completed before code changes

Classification

  • external-api-change
  • cross-component-change
  • business-logic-change
  • public-surface-change
  • docs-sync-change
  • security-sensitive-change
  • ui-change
  • infra-change

External References

Codex source at tag rust-v0.160.0 (official repository https://github.com/openai/codex): codex-rs/app-server/src/config_manager.rs (request override bypass_hook_trust), codex-rs/config/src/loader/mod.rs (project trust), codex-rs/hooks/src/engine/discovery.rs (hook trust by hash, bypass). codex-acp v2.1.1 (https://github.com/agentclientprotocol/codex-acp): src/index.ts parses CODEX_CONFIG and passes it to threads; the published dist/index.js trusts the session roots as projects. Codex hooks docs https://developers.openai.com/codex/hooks. Context7 not used: primary sources above.

Codebase Impact Analysis

packages/vm-agent/internal/acp (CODEX_CONFIG for every Codex session, VM and Instant), .codex/ (hooks), .claude/hooks/verify-test-quality.mjs (now also Codex Stop), scripts/quality (lookup generator, tests, docs), apps/www agents guide.

Documentation & Specs

apps/www/src/content/docs/docs/guides/agents.md (Codex: repository hooks run), scripts/quality/README.md ("Codex hooks"), .claude/rules/00-rule-routing.md, generated AGENTS.md.

Constitution & Risk Check

Principle XI: no new hardcoded limits (hook byte cap configurable via SAM_CODEX_RULE_CONTEXT_MAX_BYTES). Risk: a repository's hooks now run in Codex sessions; mitigated by the existing full-access model and documented for users. Rollout (rule 54): additive env for new agents; old agents keep the old CODEX_CONFIG.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codspeed

codspeed Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing sam/codex-repo-hook-trust (5f5fa08) with main (0f52c9c)2

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩

  2. No successful run was found on main (2c5ee4d) during the generation of this report, so 0f52c9c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

…usts the session project); real-process test of repository hooks through codex-acp
@simple-agent-manager
simple-agent-manager Bot marked this pull request as ready for review November 16, 2026 17:09
@simple-agent-manager simple-agent-manager Bot added the coderabbit-review Trigger CodeRabbit review for opt-in PRs label Nov 16, 2026
@github-actions
github-actions Bot requested a deployment to staging November 16, 2026 18:13 Abandoned
raphaeltm and others added 3 commits November 16, 2026 18:18
…s; force HTTPS in the probe seed script

SonarCloud flagged 33 duplicated new lines (the hook probe repeated the
adapter-start and Responses-stream code of the pinned and steering process
tests) and plain curl redirects in seed-codex-hook-probe.sh. The three tests now
use startACPAdapterProcess, adapterCommand and writeResponsesTurn; the hook
probe still passes against codex-acp 2.1.1 and Codex 0.160.0. gateway.go gets
the blank line gofmt wants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions
github-actions Bot requested a deployment to staging November 16, 2026 23:27 Abandoned
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@simple-agent-manager
simple-agent-manager Bot merged commit cbe12a4 into main Nov 17, 2026
66 of 68 checks passed
simple-agent-manager Bot added a commit that referenced this pull request Nov 17, 2026
…s archived task (#2827)

The archive move in #2804 staged the rename before these edits, so main kept
the unticked checklist. Ticks the staging, review and acceptance items and adds
the staging evidence note (deploy 43971455359, VM and Instant sessions).

Co-authored-by: Raphaël Titsworth-Morin <raphael@raphaeltm.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coderabbit-review Trigger CodeRabbit review for opt-in PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant