Repository navigation
Stop Codex rejecting SessionStart hook output (split stdout/stderr) - #19
Merged
Merged
Conversation
The host-enrollment bootstrap wrote its full diagnostic status object to
stdout on every SessionStart:
{"host":"codex","needs_restart":true,"status":"needs_restart",
"systemMessage":"Promptless telemetry configured for Codex..."}
Codex validates SessionStart hook *stdout* against a strict schema (serde
`deny_unknown_fields`): only continue/stopReason/systemMessage/
suppressOutput/hookSpecificOutput are accepted. The diagnostic keys
(status/host/needs_restart/reason) are outside that schema, so Codex
rejects the whole object with "hook returned invalid session start JSON
output" — on every session, including the common gate-disabled case.
The #15 premise ("the extra field is ignored by the host hook parsers")
holds for Claude Code (lenient) but not Codex (strict). The error first
appeared in #11, which dropped --quiet and started writing this JSON to
Codex's stdout; #15 added systemMessage on the same wrong assumption.
Fix: split the streams in `_emit`. stdout carries only the schema-valid
systemMessage (and nothing when there is no message — Codex treats empty
stdout as success); the full diagnostic object goes to stderr, which
neither host parses as hook output but remains available for debugging.
- Tests assert the stream split (stdout is empty or exactly
{systemMessage}; stderr carries the diagnostic) via a shared helper, so
every bootstrap run now guards against stdout schema leaks.
- New regression test pins the exact Codex-breaking fields out of stdout.
uv run pytest (136 passed); ruff check / format --check / ty check clean;
bootstrap script py_compiles and is ruff/format-clean.
…t-stdout-schema # Conflicts: # tests/test_managed_bootstrap.py
Codex Bug BotNo new bugs detected in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Codex now fails the host-enrollment
SessionStarthook every session:The bootstrap writes its full diagnostic status object to stdout on every
SessionStart:{"host":"codex","needs_restart":true,"status":"needs_restart","systemMessage":"Promptless telemetry configured for Codex. Restart Codex to start telemetry."}Codex validates SessionStart hook stdout against a strict schema — its Rust parser deserializes into a fixed struct with serde
deny_unknown_fields, accepting onlycontinue/stopReason/systemMessage/suppressOutput/hookSpecificOutput. Our diagnostic keys (status,host,needs_restart,reason) are outside that schema, so Codex rejects the whole object as "invalid session start JSON output". This hits every Codex session — including the common gate-disabled steady state ({"status":"disabled",...}), not just the configured case. (Strict per-event validation confirmed by openai/codex#18887, #27052.)The premise added in #15 — "the extra field is ignored by the host hook parsers" — holds for Claude Code (lenient: ignores unrecognized top-level fields, which is why Claude never errored) but is false for Codex (strict). The error actually first appeared in #11, which dropped
--quietand started writing this JSON to Codex's stdout; #15 addedsystemMessageon the same wrong assumption and so didn't fix it.Fix
Split the streams in
_emit:systemMessage({"systemMessage": "..."}), and nothing at all when there is no message — Codex treats empty stdout as success.status/host/needs_restart/reason, plus the message), which neither host parses as hook output but stays available for manual troubleshooting (the--quiet-off intent from Run host enrollment SessionStart hook without --quiet #11).Claude keeps rendering the
systemMessagebanner; Codex stops erroring.Tests
_assert_session_start_streamshelper now asserts the split on every bootstrap run: stdout is empty or exactly{systemMessage}(never the schema-breaking keys), stderr carries the diagnostic. This guards all existing cases against future stdout leaks.test_bootstrap_stdout_stays_codex_schema_safepins the exact Codex-breaking fields out of stdout and verifies steady-state stdout is empty.stderr == ""→stdout == "") since the diagnostic now lives on stderr.Validation
uv run pytest— 136 passeduv run ruff check src tests,uv run ruff format --check src tests,uv run ty check src tests— cleanpy_compiles and is ruff/format-clean