Repository navigation
fix(agents): tolerate null optional fields in codex structured output - #24
Merged
Merged
Conversation
OpenAI strict structured outputs cannot express an optional property: every field is required and an absent value comes back as explicit null. The zodToJsonSchema openAi target renders our .optional() fields as nullable, so Codex returns null for fields it omits (e.g. a review comment's start_line / start_side), and Zod .optional() rejects null -- failing the compliance and security lenses with agent_invalid_output. Recursively strip null-valued properties from the parsed Codex response before schema validation so they read as absent. Genuinely nullable fields in our schemas pair .nullable() with .default(null), so a stripped null round-trips back to null via the default and no information is lost.
Contributor
There was a problem hiding this comment.
Shopfloor agent review: clean across 4/4 reviewers.
- PR #24 follows all written repository conventions (CLAUDE.md is the only convention file): the dist bundle is rebuilt, files are placed in their documented locations, and no forbidden commands, package-manager, commit-style, or formatting rules are violated.
- The stripNullProperties fix correctly drops null-valued object properties so Codex's strict-output nulls read as absent for .optional() fields, and the only .nullable() fields (triage supplied_spec/supplied_plan) pair with .default(null) so their null round-trips losslessly — no logic bugs found.
- The diff only adds a recursive null-stripping helper for already-parsed Codex output before Zod validation, plus a version bump and tests — no exploitable security patterns.
- The diff adds a small, well-named recursive stripNullProperties helper (no duplication elsewhere) with a clear WHY comment and focused tests; no maintainability smells found.
Contributor
There was a problem hiding this comment.
Shopfloor agent review: clean across 4/4 reviewers.
- PR #24 follows all written conventions: dist bundle rebuilt and committed, version bumped consistently, tests placed in the prescribed test/ directory, and no forbidden patterns or formatting-rule violations.
- The recursive null-stripping fix is logically correct and its round-trip-safety claim holds against all five decision schemas (only triage's supplied_spec/supplied_plan are nullable, both with .default(null)); no logic bugs or missed edge cases found.
- The diff only adds a recursive null-stripping helper for Codex output parsing, a version bump, and tests — no exploitable security patterns.
- The change adds a well-named, single-purpose recursive helper with a justified comment plus focused tests; no maintainability smells found.
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
With Codex past the sandbox and actually inspecting diffs, the compliance and security review lenses failed with
agent_invalid_output:OpenAI strict structured outputs cannot express an optional property: every field is required, and an absent value is returned as explicit
null.zodToJsonSchema(target: "openAi")renders our.optional()fields as nullable, so Codex returnsnullfor the ones it omitted (here aReviewComment'sstart_line/start_side). Zod.optional()acceptsundefined, notnull, so the parse fails.This is not review-specific; it affects any optional field in any stage's decision schema under Codex.
Fix
In the Codex adapter, recursively strip null-valued properties from the parsed response before
decisionSchema.parse, so a Codexnullreads as "absent" for.optional().Round-trip safety: the only genuinely nullable fields in our schemas (triage
supplied_spec/supplied_plan) pair.nullable()with.default(null), so a stripped null re-defaults to null. No information is lost. The Claude adapter is untouched (the Anthropic SDK omits absent optionals, so it never sees this).Notes
2.0.4;dist/index.cjsrebuilt.