Repository navigation
refactor(codex): deny native child spawns outside runner policy - #8122
Conversation
Golden files rendered from the current code, with no production change, so the commits that follow show their effect on the rendered files as a diff. Each SHA-256 in a launch command is stored as <sha256>; a command is stored one fragment per line. Regenerate after an intended change with go test ./internal/runtime/ -run TestCodexGolden -update. Signed-off-by: Dharit Shah <dhshah@redhat.com>
With harness security on, hooks.json starts with one PreToolUse group whose matcher covers codex's two multi-agent namespaces and any bare spawn_agent or resume_agent name, and whose handler is the embedded adapter in a SpawnGuard mode (ADR 0126). The group is written whenever hooks.json is, with every sandbox hook off included. Inside the matched set the handler is deny-by-default: it admits a V1 spawn from the root thread of a registered role with fork_context false and no model or reasoning_effort argument, passes the V1 wait, close and send_input through from the parent, and denies everything else, its own errors included, with exit 2 and a reason on stderr. An admission is recorded in the findings log with the spawn's tool_use_id and role. No role is registered yet, so every spawn is denied, and [agents] enabled = false leaves codex with no spawn tool to reach the handler. Signed-off-by: Dharit Shah <dhshah@redhat.com>
The runner-held digest set gains RoleFiles, role name to digest of agents/<name>.toml, and the launch command exports it with the hooks.json digest as FULLSEND_CODEX_SPAWN_DIGESTS, after .env and next to the hook-script digests. Before it applies the policy, the spawn guard re-hashes every listed file and requires agents/ to hold exactly the registered role files: codex reads both again when a child starts, so the launch-time guard does not cover a child. It denies on its own deadline, below the hooks.json timeout at which codex kills a handler without blocking, and reads only regular files under the adapter's size cap, so a stalled or swapped file denies the spawn. Nothing registers a role yet; the value is hooks.json alone and every spawn is denied. The findings log is written with a non-blocking open and only when the path is a regular file, the way the digest reads work: every deny, the deadline handler included, records itself before block(), and a FIFO planted at the log's path under the workspace would otherwise stall the deny past codex's timeout, which does not block. Signed-off-by: Dharit Shah <dhshah@redhat.com>
PR Summary by QodoGuard Codex child spawns with runner-held policy and file digests
AI Description
Diagram
High-Level Assessment
Files changed (15)
|
|
🤖 Review · Commit: |
Code Review by Qodo
1.
|
Site previewPreview: https://8511277f-site.fullsend-ai.workers.dev Commit: |
…n admission The admit record was written while the guard's SIGALRM deadline was still armed. An alarm firing between the write and the disarm denied the spawn after the findings log already said it was admitted, which the after-run cross-check would read as an admitted spawn that never ran. The disarm now comes first; the write itself cannot stall, since the log is opened non-blocking and written only as a regular file. Signed-off-by: Dharit Shah <dhshah@redhat.com>
|
🤖 Finished Review · ✅ Success · Started 8:33 PM UTC · Completed 8:41 PM UTC Commit: Runtime: pi · Model: openai/gpt-6.1-sol → gpt-6.1-sol · Effort: high · Cost: $2.27 |
|
Risk Assessment: moderate (2/5) DetailsModerate risk: large diff driven predominantly by unit tests and golden test fixtures with no protected paths or dependency modifications, elevated churn in active runtime files, and an inert enforcement slice aligned with ADR 0126 that is safely revertible. Previous runRisk Assessment: moderate (2/5) DetailsModerate risk: large diff driven predominantly by unit tests and golden test fixtures with no protected paths or dependency modifications, elevated churn in active runtime files, and an inert enforcement slice aligned with ADR 0126 that is safely revertible. Previous run (2)Risk Assessment: moderate (2/5) DetailsModerate risk: large diff driven predominantly by unit tests and golden test fixtures with no protected paths or dependency modifications, elevated churn in active runtime files, and an inert enforcement slice aligned with ADR 0126 that is safely revertible. |
|
Looks good to me Earlier findings
Previous runReviewFindingsLow
Next steps:
Previous run (2)Looks good to me Labels: The PR adds runner-owned enforcement of Codex child-agent spawning and associated sandbox security checks. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Could you redo the comments and docs with "redo the comments and docs: be briefer and do not include unnecessary context in them", they are very lengthy and sometimes include context that refers to stuff a few hundred files away, which makes them a pain to read. |
rh-hemartin
left a comment
There was a problem hiding this comment.
In my ignorance of this topic, looks good to me.
…trings A value with newlines, the developer instructions first of all, was one basic string with \n escapes, which made config.toml and its golden hard to read. It is now a TOML multi-line basic string: the text reads as written, and backslashes, quotes and control characters stay escaped, so a body holding triple quotes or ending in a backslash still cannot end the literal early. The parsed value is unchanged; the round-trip test and the renderer's table cover both forms. Signed-off-by: Dharit Shah <dhshah@redhat.com>
Superseded by updated review
codexTOMLString renders a value with a newline as a multi-line basic string, and the project table header used the same helper, so a target directory with a newline in its name rendered a multi-line string as the key, which TOML does not accept. The header now uses codexTOMLKey, the single-line form with the same escaping, and the round-trip test's repository path carries a newline. Signed-off-by: Dharit Shah <dhshah@redhat.com>
|
🤖 Finished Review · ✅ Success · Started 12:46 PM UTC · Completed 12:56 PM UTC Commit: Runtime: pi · Model: openai/gpt-6.1-sol → gpt-6.1-sol · Effort: high · Cost: $1.78 |
Superseded by updated review
|
Validated locally at 33270ae merged with main 2150af8:
The guard is inert until a role is registered, as the PR says, so the admit path is covered by the Go tests only. My earlier ProjectKey comment is addressed by |
Summary
With harness security on, codex runs a fullsend handler before any spawn or resume tool.
Inert until PR 6:
[agents] enabled = false(#7829) leaves codex with no spawn tool, and no roleis registered yet, so the handler is written but no run reaches it.
Related Issue
Part of #6970. Implements the enforcement of ADR 0126 (#7827). Replaces the guard part of the
closed #7809.
Changes
internal/runtime/codex_hook/fullsend-codex-hook.py: theSpawnGuardmode re-checkshooks.jsonand the role files against the runner-held digest set (agents/must hold exactly the registered files), then admits only a V1 spawn from the root thread of a registered role withfork_context: false(absent is denied) and nomodelorreasoning_effortkey, whatever its value. Everything else, its own errors and its own deadline below codex's handler timeout included, is exit 2 with a reason on stderr; an admission is recorded in the findings log (codex_spawn_guard_admit).internal/runtime/codex_config.go:hooks.jsongets the guard group first, also with every sandbox hook off (matcher^(multi_agent_v1|collaboration)|(spawn|resume)_agent$, adapter modeSpawnGuard). On review request,codexTOMLStringrenders a value with newlines as a TOML multi-line basic string, with the same escaping; the renderer's table and the TOML round-trip test cover both forms. The project table key stays single-line (codexTOMLKey), since a table header cannot hold a multi-line string.internal/runtime/codex_integrity.go,codex_run.go:RoleFileson the runner-held digest set;FULLSEND_CODEX_SPAWN_DIGESTSexported after.envnext to the hook-script digests.internal/runtime/codex_golden_test.go,testdata/codex/golden/*:config.toml,hooks.jsonand the launch command pinned byte for byte (commit 1, frommain); the later commits add the guard group to bothhooks.jsongoldens and one line to the launch command, and regenerateconfig.tomlfor the multi-line strings.go test ./internal/runtime/ -run TestCodexGolden -updateregenerates them.internal/runtime/codex_config_test.go,codex_hook_test.go,codex_integrity_test.go,codex_run_test.go: one deny row per rule and error branch (35), the admit cases, the matcher and its position, the export fragment.TestCodexHooksJSON_SecurityDisabledPlanRendersNothingbecomesTestCodexHooksJSON_AllHooksOffKeepsSpawnGuard,TestCodexHooksJSON_DefaultPlanskips the guard group andTestBuildCodexRunCommand_OrderAndFlagscounts one morehooks.jsondigest; the adapter tests (TestCodexAdapter*) are unedited.docs/contributing/runtime-implementation.md: the guard group, the role-file anchor, the variable, the re-check row.Points of interpretation, for a maintainer to correct (what the ADR does not say):
agent_typepresent but not a string is denied, like an unregistered role; the ADR recognises a child by the
agent_idin its hook payload, and the guard also treats a top-levelagent_typeas that marker(the pinned CLI sends both in a child's payload and neither in the parent's).
Testing
make lintpasses (staged first)go test -race ./internal/runtime/,make script-test. Every new test was seen failing before its code existed; the golden test was also failed by hand with a changed template value.origin/mainatcb9825e6.go tool cover -func):codexHooksJSON,codexSpawnDigestsValue,buildCodexRunCommandat 80% or more. About 1250 added lines: about 340 production, the rest tests, goldens (about 230 generated lines) and docs.Checklist
🤖 Generated with Claude Code