Repository navigation
fix(tier3): decode inline and Promise.allSettled Codex wrappers (#235) - #325
Conversation
…IA#235) Extend the bounded static Codex exec grammar to decode the wrappers that Codex 0.161.0 emits: inline text(await tools.NAME(...)), text((await tools.NAME(...)).output), single-quoted string literals, tools.apply_patch string arguments, a missing final semicolon, and literal Promise.allSettled batches rendered by an indexed for, indexed forEach, or forEach(text). A multi-call wrapper decodes only when each call owns its own JSON record of the outer output. Dynamic arguments, shadowed bindings, unsupported renderers, and missing, extra, reordered, changed, or truncated records remain unsupported. The extended grammar was validated in the Apache-2.0 skill-ci project (commit 60c92130). Refs: NVIDIA#235 Signed-off-by: Amine Marzouki <[email protected]>
Wrap normalized_tool_call_error_flag so extracted tool calls carry is_error for rejected Promise.allSettled records. A call's own record status now wins over the outer tool_result_is_error flag, so a fulfilled record is not reported as failed just because the outer script exited non-zero. Add extractor and flag regression tests for fulfilled and rejected records, including an outer-failure observation. Signed-off-by: Amine Marzouki <[email protected]>
…mmar Signed-off-by: Amine Marzouki <[email protected]> # Conflicts: # CHANGELOG.md
chrisknvidia
left a comment
There was a problem hiding this comment.
Reviewed head 6dee63f4840cbf7782c2ffaf847c88b956fed5c9 against current main 847bdb41885c804949355e2a937a0da6d0aad752 and issue #235. Requesting changes for the three inline findings: fulfilled tool failures are converted to success, rejected records can still receive clean error-recovery scores, and duplicate JSON keys bypass record-ownership/outcome validation.
Independent verification: 436 normalization tests and 3,085 affected-consumer tests passed. Real native command outputs were replayed through Harbor 0.24.0 and both host and bundled verifier scoring paths; the nonzero-exit scoring defect reproduced. Rejected-result and malformed-record findings were reproduced with targeted fixtures. This was not a fresh Codex 0.161.0 model-driven Harbor workload, and I did not independently rerun the full 18,830-test suite.
Please correct these cases, add scoring-level regressions, resolve the CHANGELOG conflict with current main, and rerun validation on the updated head.
Signed-off-by: Amine Marzouki <[email protected]>
Fail nonzero exit_code and rejected records; reject duplicate JSON keys. Signed-off-by: Amine Marzouki <[email protected]>
|
Thanks @chrisknvidia, all three are fixed, and main is merged so the CHANGELOG conflict is gone. Each fix has regressions that run through check_error_recovery and check_activation, on both the host and bundled paths. Duplicate keys, including nested ones, leave the wrapper unsupported. A record with no exit code stays unknown. One addition you didn't ask for: once nonzero exits counted as failures, a no-match grep exiting 1 inside a batch scored 0.0. check_error_recovery now reads the output field of a whole record, so that stays clean while a probe with a real diagnostic still fails. It touches the shared scorer, so please look at it closely. Full suite: 22,041 passed, 0 failed. I left out the Docker environment, chmod-fallback and Ctrl-C tests, which also fail on unmodified main on my machine. I haven't run a fresh Codex 0.161.0 workload, so a replay on the new head would help. |
rng1995
left a comment
There was a problem hiding this comment.
Reviewed head 2c8cd16e against main 0ae3fdbf.
The three findings from the earlier review are fixed for the newly decoded forms. Rejected records and records with a nonzero exit_code now fail check_error_recovery and check_activation on both the host and bundled paths, and duplicate keys leave the wrapper unsupported. Locally, the 490 normalizer tests and 1,249 consumer tests pass (error recovery, activation, security, plugin signals, shared ATIF staging).
I've left two P2s inline:
- Grading still depends on how Codex spelled the wrapper, because the record rules only run where the old grammar gave up.
- A U+2028 or U+2029 on the
// @exec:line hides code from the decoder.
The three P3s cover the lone-call record path, lexing differences between Python and JavaScript, and the quiet-probe field name.
The branch conflicts with current main again (8a851c6b). The conflict is only in the checks.py imports (import json against import bisect); keep both.
chrisknvidia
left a comment
There was a problem hiding this comment.
@shetsecure follow-up review on the current head. The three points from my earlier review are addressed, so I resolved those threads. Narendran's five open threads still apply; I left inline notes on each, with a reproduction for the quiet-probe field name. The branch also conflicts with main and needs main merged in.
Signed-off-by: Amine Marzouki <[email protected]>
A failed call now grades the same whether it is single- or double-quoted. Signed-off-by: Amine Marzouki <[email protected]>
JavaScript ends a // comment there, so code after either one still runs. Signed-off-by: Amine Marzouki <[email protected]>
A successful record now decides the grade, as it does for several calls. Signed-off-by: Amine Marzouki <[email protected]>
Reject what JavaScript rejects: odd whitespace, non-ASCII names, line breaks before => or ++, 1e400. Signed-off-by: Amine Marzouki <[email protected]>
The probe exemption no longer depends on the field name in text({i, NAME: r}).
Signed-off-by: Amine Marzouki <[email protected]>
Reject r² as a name while valid ones like résultat still decode. Signed-off-by: Amine Marzouki <[email protected]>
A truncated or duplicate-key record no longer scores as a clean run. Signed-off-by: Amine Marzouki <[email protected]>
U+001C-U+001F and U+0085 are whitespace in Python but not in JavaScript. Signed-off-by: Amine Marzouki <[email protected]>
Signed-off-by: Amine Marzouki <[email protected]>
JavaScript serializes 1e400, NaN and Infinity as null, so decoding them to inf or nan was wrong. Signed-off-by: Amine Marzouki <[email protected]>
|
@rng1995 @chrisknvidia thanks, all five are fixed and main is merged, so the conflict is gone.
Each one has a regression test. Full suite: 25,165 passed, 31 failed, and the same 31 fail on unmodified main on my machine (Docker environment and chmod tests). |
rng1995
left a comment
There was a problem hiding this comment.
Automated review: 2 findings (0 P1, 0 P2, 2 P3); 2 posted inline.
Re-reviewed at 28e776c. Status of the earlier comments, each re-checked with a probe:
- My P2 (record outcome applied only where the old grammar gave up): fixed. The extended grammar runs first, and every spelling of a failed call grades the same.
- My P2 (U+2028/U+2029 on the
// @exec:line): fixed; it now fails closed. - My P3 (lone call ignoring an exit-0 record / outer-flag precedence): fixed.
- My P3 (Python vs JS lexing): the four points raised are fixed and covered by tests.
- My P3 (quiet-probe output found only via value/result): fixed except for a settled field named
output; see the new inline comment at checks.py:4635. - chrisknvidia's P1 (fulfilled promise loses the tool outcome) and P2s (rejected records, duplicate keys): fixed.
A differential fuzz of about 86.5k single-character mutations across head, main and Node found no new mis-accepts or wrong rejections. The 620 normalizer tests and 919 consumer tests pass, and ruff is clean. The branch conflicts with main again, in CHANGELOG.md only, after #371.
chrisknvidia
left a comment
There was a problem hiding this comment.
Re-reviewed at 28e776c. My three earlier findings are still fixed, and so are rng1995's earlier findings; his two newer P3s still apply (replies inline on those threads).
Checked locally in both the host and the bundled extractors:
- U+2028/U+2029 on the
// @exec:line now fails closed (security 0.5, not passed) for the inline andconstforms. - The wrappers JavaScript rejects (
\x1c/\x85as whitespace,r², a line break before=>/++,1e400) stay unsupported. - A lone call's record decides its outcome, including for the
constform the old grammar already accepted: an exit-2 record now scores error recovery 0.0 (main gives 1.0). - Quiet probes keep the exit-1 exemption under the
result,outcomeandsettledfield names, but notoutput(inline). tests/tier3passes (9952 passed, 10 skipped).
Nothing blocking from me beyond those two P3s.
Resolve the CHANGELOG.md conflict by keeping main's entries and this PR's entry. Signed-off-by: Christopher Kevin <[email protected]>
Signed-off-by: Amine Marzouki <[email protected]>
… field Start past leading whitespace, and keep descending when a settled field is itself named output. Signed-off-by: Amine Marzouki <[email protected]>
|
@rng1995 @chrisknvidia both new P3s are fixed, and main is merged again with the CHANGELOG conflict resolved. A record after leading whitespace now decodes, and a settled field named |
rng1995
left a comment
There was a problem hiding this comment.
Re-checked all seven earlier comments at 7295301 on both the host and bundled-verifier paths, and each one is addressed: the extended program parser runs first with a fallback, the pragma regex stops at Unicode line separators, a lone exit-0 record with a traceback is graded from its record, malformed wrappers fail closed, _record_output follows a nested object-valued output, and leading whitespace no longer breaks the lone-call decoder. The two merges only resolve CHANGELOG. Approving.
The main merge moved exit-status matching to _EXIT_STATUS_RE, but the new JSON quiet-probe helper still referenced the removed local name. Reuse the module-level matcher so Codex records can be scored on the host and bundled-verifier paths. Signed-off-by: Narendran Raghavan <[email protected]>
The requested fulfilled/rejected outcome handling and duplicate-key protections are fixed, their threads were resolved by the reviewer, and the reviewer subsequently acknowledged those fixes. The changelog conflict is also resolved. Verified current head 0d11179 with 1,464 focused tests; dismissing this superseded changes request after review of the fixes.
rng1995
left a comment
There was a problem hiding this comment.
Thank you @shetsecure for your contribution and for your patience throughout the review process. All seven remaining review findings are addressed, including fail-closed parsing and quiet-probe behavior on the host and bundled-verifier paths. Fixed the merge-introduced regex reference in 0d11179 and verified 1,464 focused tests plus full source/test Ruff checks. The PR merges cleanly with main. Approved; auto-merge remains subject to required CI checks.
Summary
Codex 0.161.0 emits native
execwrappers that the bounded static grammar currently classifies asunsupported_native_codex_exec_wrapper. Those wrappers then score security, skill execution, and parts of behavior at the neutral fallback and compress measured lift.This PR extends the static grammar without evaluating JavaScript. It decodes:
text(await tools.NAME(...))text((await tools.NAME(...)).output)tools.apply_patch('...')string argumentsPromise.allSettled([...])batches rendered by an indexedfor, indexedforEach, orforEach(text)Multi-call batches are decoded only when each call owns its own JSON record of the outer output. Dynamic arguments, shadowed or duplicate bindings, computed keys, spreads, template literals, unsupported renderers, and missing, extra, reordered, changed, or truncated records remain unsupported.
Error status
A call's own record decides whether it failed, and the outer script's exit status does not override it:
Promise.allSettledrecord marks its call failed and adds astatus=failedline to the call's observation.exit_codemarks its call failed and adds theexit_code=Nline the scorers already parse. A fulfilled promise only proves the tool returned, not that the command succeeded.exit_code(a running process,write_stdin,apply_patch) leaves the outcome unknown, sois_erroris not set and scoring falls back to the observation text.normalized_tool_call_error_flagis wrapped soextract_tool_calls_as_dictscarriesis_errorfor these calls. Duplicate JSON keys anywhere in a record, such as a repeatedi,statusorvalue, leave the whole wrapper unsupported, since the last duplicate would otherwise decide ownership or outcome.The extended grammar now runs first for every
execwrapper, so a failed call grades the same whether it is double- or single-quoted, bound or inline. A lone call is graded by its own record when the record states an outcome. When the outer output has the exec header and a body that opens like a record but does not parse (truncated, trailing text, duplicate key), a lone call is left unsupported, so cut-off evidence cannot score as a clean run. Plain-text results such asapply_patchkeep their whole output.To fail closed where JavaScript would not run the script, the
// @exec:pragma line ends at U+2028/U+2029, names are checked withstr.isidentifier()(sor²is rejected andrésultatstill decodes), and wrappers using U+001C–U+001F or U+0085 as whitespace are unsupported. Both grammars reject a non-finite number such as1e400,NaNorInfinity, which JavaScript serializes asnull, and the new grammar also rejects a line break before=>or++.check_error_recoveryalso reads theoutputfield of a whole JSON record, whatever the settled field is called, so a no-matchgrep/rgthat exits 1 keeps its quiet-probe exemption inside a batch. It ignores a record followed by extra text and no longer raises on deeply nested input.Verification
ruff check src tests— passespython -m build— builds the sdist and wheeluv run pytest tests/tier3/test_codex_tool_call_normalization.py -q— 642 passeduv run pytest -q— 26,480 passed, 39 skipped, 31 failedThe 31 failures are 29 in
tests/test_harbor_secure_docker_environment.pyand 2 chmod-fallback tests intests/test_harbor_secure_copy.py. The same 31 fail on unmodifiedmainin my environment (I compared the test IDs), and CI covers them on a clean machine. Three tests that hang here were deselected: the two Ctrl-C tests intests/ci/test_run_tier1.pyandtest_windows_transfer_repeated_cancellation_reaps_process_and_removes_partial_output.New tests cover inline/single-quoted/
apply_patchforms, everyallSettledrenderer and record shape, rejected records (Error object, empty and string reasons), fulfilled records with a nonzero exit code, lone calls with complete, truncated and duplicate-key records, record-versus-outer-failure precedence, duplicate index/status/value/nested keys, the pragma line terminators, JavaScript names and whitespace, whitespace before a lone record, the quiet-probe field name (including a field calledoutput), dynamic fail-closed cases, and security scanning. The error-recovery and skill-activation cases run through both the host and bundled-verifier paths.Prior art
The extended grammar follows the downstream Apache-2.0
skill-ciworkaround for this issue (commit60c92130by @dirien), which reports 148 real calls decode. That workaround is a downstream patch, not an upstream fix; this PR upstreams the capability with tests and fail-closed coverage. Thanks to @dirien for the reference implementation.Refs #235.
Signed-off-by: Amine Marzouki [email protected]