Repository navigation
feat: lower Codex functions.exec children into typed actions - #3063
Conversation
|
Warning Review limit reached
Next review available in: 57 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (9)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 170ce42b38
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| calls.append( | ||
| _CodexExecChildCall( | ||
| tool_path=tool_path, | ||
| tool_name=_code_mode_tool_name(tool_path, registry_type), | ||
| registry_type=registry_type, |
There was a problem hiding this comment.
Do not equate JavaScript call sites with executed actions
When a functions.exec script contains control flow, such as a tool call in an untaken branch or a loop over several commands, this scanner emits exactly one tool_use for each syntactic call site without knowing whether or how often it ran. This fabricates actions for untaken branches and collapses repeated loop invocations into one action, causing incorrect action counts, commands, and result pairing; static call sites should not become ordinary actions unless runtime evidence establishes their invocation multiplicity.
Useful? React with 👍 / 👎.
| emitted: list[object] = [] | ||
| for item in parsed: | ||
| emitted.extend(_decoded_structural_text_item(item)) | ||
| if len(emitted) >= child_count: | ||
| break |
There was a problem hiding this comment.
Avoid treating every JSON emission as a child result
When valid Code Mode source emits an unrelated JSON diagnostic through text() before emitting the actual tool result, every decodable JSON content item is accepted as a child result. For a single child this loop reaches child_count on the diagnostic and stops, discarding the real result and potentially attaching the diagnostic's path or outcome fields to the action; ambiguous JSON emissions need recognizable result provenance before positional pairing.
Useful? React with 👍 / 👎.
Problem: modern Codex Code Mode wraps nested tool operations
(exec_command, apply_patch, write_stdin, update_plan, wait, web search,
image, MCP resource calls) inside a JavaScript envelope passed as the
argument to an outer exec/functions.exec function_call. Polylogue only
ever saw the outer transport call, so a session with 14,004 nested calls
projected zero normalized file paths and zero structured outcomes even
though many results were expressible outcomes.
What changed:
- polylogue/sources/parsers/codex.py: add a conservative JS-literal
scanner (_JsLiteralParser + _scan_code_mode_child_calls) that walks
`tools.*`/`functions.*` member-call syntax without ever evaluating
JavaScript. Unparseable/dynamic arguments are retained as raw evidence
with parse_state="malformed" rather than guessed. Each recognized
child call/result is lowered into an ordinary child tool_use/tool_result
block pair (tool_id = `<transport_tool_id>::polylogue-child::<n>`),
transport-linked via a `_polylogue` provenance object on tool_input.
Outcome fields (is_error/exit_code) are populated only from structural
JSON fields (exit_code/is_error, optionally nested under
metadata/result/output) — free-text mentions of "exit_code=N" are never
promoted, matching the "structural or unknown, never regex-guessed"
invariant. Repeated calls against the same transport tool_id pair
deterministically by occurrence rank (Nth use to Nth result), including
when a result envelope arrives before its call.
- polylogue/archive/viewport/tools.py: add apply_patch to FILE_EDIT and
wait to the Codex agent-tool alias set so the new child tool names
classify correctly for query/facet surfaces.
- devtools/codex_exec_child_census.py (new): reporting-only script that
counts transport vs. typed-child actions, paired/orphaned results, path
and structured-outcome coverage, and an explicit outer-transport-only
counterfactual baseline, over one or more Codex session files.
- Fixtures: tests/data/codex_event_stream/functions_exec_{single,multiple}.jsonl
cover a single child call, and ten children spanning every registry
type plus an unknown and a malformed call, including two results whose
free text contains "exit_code=N" strings that must NOT be promoted.
- Tests: TestFunctionsExecLowering in test_codex_event_stream_contract.py
pins per-fixture lowering, repeated/out-of-order call_id pairing against
the production action_pairs SQL, structured-vs-prose outcome handling,
and asserts session_content_hash differs between the lowered projection
and an outer-only projection of the same session. test_query_expression
and test_tool_aliases gain coverage for the new child action names.
Compatibility/migration notes: this adds new tool_use/tool_result blocks
to existing Codex sessions that use functions.exec/exec with nested Code
Mode calls. Session content hashes for those sessions will change (this
is asserted directly by
TestFunctionsExecLowering.test_lowered_blocks_change_semantic_content_hash),
so the next `polylogued run` / reprocess will re-parse and re-materialize
affected sessions. No source.db/user.db migration, no index.db schema
version bump: action_pairs (polylogue/storage/sqlite/action_pairs.py) is
unmodified and already pairs tool_use/tool_result rows per (session_id,
tool_id), so the new deterministic child tool_id scheme is paired by the
existing view-backed relation with no new DDL.
Verification:
- devtools test tests/unit/sources/test_codex_event_stream_contract.py \
tests/unit/sources/test_tool_aliases.py \
tests/unit/devtools/test_codex_exec_child_census.py \
tests/unit/cli/test_query_expression.py
-> 458 passed, 1 skipped
- python -m devtools.codex_exec_child_census tests/data/codex_event_stream/functions_exec_{single,multiple}.jsonl
-> transport_actions=2, typed_child_actions=11, paired_child_results=11,
child_actions_with_path=3, child_results_with_structured_outcome=3
- devtools verify --quick -> exit 0 (ruff format, ruff check, mypy --strict, render all --check)
- devtools render all --check -> no drift
- Anti-vacuity: temporarily forcing _code_mode_exec_envelopes() to return
{} (disabling child lowering) fails all 9 lowering-dependent tests,
including the content-hash and census tests; reverted after
confirming the failure.
Ref polylogue-j2zz
Co-Authored-By: Claude <[email protected]>
170ce42 to
71402f8
Compare
Summary
Modern Codex Code Mode wraps nested tool operations (
exec_command,apply_patch,write_stdin,update_plan,wait, web search, image,MCP resource calls) inside a JavaScript envelope that is itself the
argument to an outer
exec/functions.execfunction_call. Polyloguepreviously only saw the outer transport call, so a session full of
nested Code Mode calls produced zero normalized file paths and zero
structured outcomes on the child operations even when the child results
carried real structured outcomes.
Problem
In a 100-session live sample cited on the tracking bead, every session
had nested
tools.*calls: 14,004 envelopes held child operations and19,180 results yielded zero structured paths/outcomes, although 1,444 of
those result texts textually contained
exit_code— Polylogue had noway to see any of that structure because it only parsed the outer
transport call.
Solution
polylogue/sources/parsers/codex.py: a conservative JS-literal scanner(
_JsLiteralParser+_scan_code_mode_child_calls) walkstools.*/functions.*member-call syntax in the Code Mode sourcestring without ever evaluating JavaScript. It recognizes a typed
registry of child kinds (
exec_command,apply_patch,write_stdin,update_plan,wait,web,image,mcp,unknown). Unparseable ordynamic arguments are retained as raw evidence with
parse_state="malformed"rather than guessed. Each child call/resultis lowered into an ordinary
tool_use/tool_resultblock pair with adeterministic
tool_id(<transport_tool_id>::polylogue-child::<n>),transport-linked via a
_polylogueprovenance object ontool_input.Outcome fields (
is_error/exit_code) are populated only fromstructural JSON fields (top-level or nested under
metadata/result/output) — free text containing"exit_code=N"isnever promoted to a structural outcome. Repeated calls sharing one
transport
tool_idpair deterministically by occurrence rank (Nth useto Nth result), including when a result record precedes its call in
the stream — no recovery/guessing is invented.
polylogue/archive/viewport/tools.py: addsapply_patchtoFILE_EDITandwaitto the Codex agent-tool alias set so the newchild tool names classify correctly on query/facet surfaces.
devtools/codex_exec_child_census.py(new): a reporting-only scriptthat counts transport vs. typed-child actions, paired/orphaned
results, path and structured-outcome coverage, plus an explicit
outer-transport-only counterfactual baseline, over one or more Codex
session files.
tests/data/codex_event_stream/functions_exec_{single,multiple}.jsonl:the
multiplefixture spans every registry type plus one unknown andone malformed call, and includes two results whose free text contains
"exit_code=7"/"exit_code=9"that must not be promoted.tests/unit/sources/test_codex_event_stream_contract.py(
TestFunctionsExecLowering): pins per-fixture lowering, repeated/out-of-order
call_idpairing (exercised against the productionaction_pairsSQL, not a test-local reimplementation), structured-vs-prose outcome handling, and asserts
session_content_hashdiffersbetween the lowered projection and an outer-only projection of the
same parsed session.
tests/unit/cli/test_query_expression.pyandtests/unit/sources/test_tool_aliases.pygain coverage for the newchild action names/categories.
Compatibility / migration notes
This adds new
tool_use/tool_resultblocks to existing Codex sessionsthat use
functions.exec/execwith nested Code Mode calls. Sessioncontent hashes for those sessions will change — this is asserted
directly by
TestFunctionsExecLowering.test_lowered_blocks_change_semantic_content_hash—so the next
polylogued run/ reprocess will re-parse and re-materializeaffected sessions (expected, not a regression).
No
source.db/user.dbmigration and noindex.dbschema versionbump:
polylogue/storage/sqlite/action_pairs.pyis unmodified by thisPR — it already pairs
tool_use/tool_resultrows per(session_id, tool_id)viaROW_NUMBER(), so the new deterministicchild
tool_idscheme (<transport>::polylogue-child::<n>) is pairedby the existing relation with zero new DDL.
Verification
Anti-vacuity: temporarily forcing
_code_mode_exec_envelopes()to return{}(disabling child lowering entirely, i.e. the historical outer-onlybehavior) makes all 9 lowering-dependent tests fail, including the
content-hash test and the census test — confirming the tests actually
exercise the new lowering path rather than passing vacuously. Reverted
after confirming the failure; suite is green again.
Ref polylogue-j2zz