Skip to content

fix(agents): tolerate null optional fields in codex structured output - #24

Merged
niranjan94 merged 2 commits into
release/v2from
fix/codex-null-optional-output
Jun 15, 2026
Merged

niranjan94 merged 2 commits into
release/v2from
fix/codex-null-optional-output

Conversation

@niranjan94

Copy link
Copy Markdown
Owner

Problem

With Codex past the sandbox and actually inspecting diffs, the compliance and security review lenses failed with agent_invalid_output:

codex finalResponse failed schema validation:
  path: ["comments", 0, "start_line"]  expected number, received null
  path: ["comments", 0, "start_side"]  expected 'LEFT' | 'RIGHT', received null

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 returns null for the ones it omitted (here a ReviewComment's start_line / start_side). Zod .optional() accepts undefined, not null, 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 Codex null reads 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

  • Patch version bumped to 2.0.4; dist/index.cjs rebuilt.
  • Tags left untouched (released separately).
  • Added two adapter tests: null optionals treated as absent, and a meaningful nullable+default null preserved. Full suite: 284 passing.

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@niranjan94
niranjan94 merged commit 17ea098 into release/v2 Jun 15, 2026
6 checks passed
@niranjan94
niranjan94 deleted the fix/codex-null-optional-output branch June 15, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant