Repository navigation
feat(agents): SAM Codex sessions run repository hooks; Codex rule delivery and Stop gate - #2804
Conversation
…ry, with the review's missing tests
…host_agent_config.go (pure move)
… (bypass_hook_trust + project trust in CODEX_CONFIG)
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
… test; docs state the full trust scope
Merging this PR will not alter performance
Comparing Footnotes
|
…usts the session project); real-process test of repository hooks through codex-acp
…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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
…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>



Summary
SAM-managed Codex sessions now run a repository's own Codex hooks, as Claude Code sessions already run
.claude/settings.jsonhooks. 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.2build is based on) runs a non-managed hook only when its definition has been trusted by hash, which takes an interactive/hooksreview. 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 topackages/vm-agent/internal/acp/session_host_agent_config.go, pure-move commit 2d13120) addsbypass_hook_trust: truetoCODEX_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 aprojectstrust entry; the real-process test showed it redundant (codex-acp already does it), so it was removed.sam/codex-rule-delivery-hook:.codex/hooks/rule-context.mjs, the generated.codex/hooks/rule-scopes.json(--checkfails when stale), the Codex SessionStart/PreToolUse/Stop entries,.gitignorere-include.additionalContextLimitraised to 20000 tokens: the test showed the hook's maximum byte cap sat exactly on the old threshold.scripts/quality/README.md, rule routing and the generatedAGENTS.mdblock.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, andCODEX_CONFIGoutranks project config, so SAM's sandbox, approval and model settings hold. The repository'sconfig.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'sbuildCodexACPManagedConfigEnv, 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. SettingBypassHookTrustback to false turns the two trusted cases red.go test ./internal/acp/(full package, with the real-process probe enabled),go vet, gofmtpnpm quality:agent-tooling:test(152 tests),pnpm quality:agent-context-budget --checkBypassHookTrustfalse -> unit and gateway tests red (13 assertions) and real-process trusted cases redstaging(sammy.party), VM and Instant (below)curl --proto =https); real-binary probe re-run 3/3 after the refactorStaging Verification (REQUIRED for all code changes — merge-blocking)
Deploy run 43971455359 of
14a835910tostaging: 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…(commitca6e9db: SAM's Codex hooks, a canary rule.claude/rules/10-probe.mdscoped tosrc/**,src/existing.txt). Then real Codex (openai-codex) conversation sessions:sed -n 1,2p src/existing.txtthe hook injected the rule body includingPROBE-RULE-CANARY-7731(the model never opened the rule file). The later write undersrc/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"printf 'x\n' > src/new.txtrefused 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 holdsxcf-containernode)Pre-existing, not from this PR: each Codex session first said
get_instructionswas unavailable (deferred MCP tools), as tracked intasks/backlog/2026-11-07-codex-first-turn-misses-deferred-sam-mcp-tools.mdwith 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)
projectsentry; real Codex probe added for "0.160.0 accepts the key"projectsdesign fixed; note added at the Codex pins (gateway.go) to rerun the real-process probe on a bump (2464bbc). Staging pending, as knownCodeRabbit Review Evidence (Required for agent-authored PRs)
CodeRabbit Notes
Requested 18:08Z via
coderabbit-bot-review.yml(run 43925636583, success). CodeRabbit answered with itsReview skippedstatus (check stateskipping), so the wait ended there with no review to resolve (rule 25, policy 73ed7a68).Agent Preflight (Required)
Classification
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 overridebypass_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.tsparsesCODEX_CONFIGand passes it to threads; the publisheddist/index.jstrusts 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/wwwagents 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, generatedAGENTS.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