Skip to content

Fix concurrent first-use JSON coder initialization - #46

Merged
odrobnik merged 2 commits into
mainfrom
agent/issue-45
Dec 1, 2026
Merged

odrobnik merged 2 commits into
mainfrom
agent/issue-45

Conversation

@odrobnik

@odrobnik odrobnik commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Resolves #45.

Both JSON coders now initialize before concurrent requests begin, preserving their existing settings and customization support. Added tests for simultaneous first image requests and request encoding, and all local automated checks passed on macOS. The original intermittent crash was not reproduced; live services and other platforms were not verified locally. Please check the concurrent image batch in the next build and reply with the result.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T20:20:45.299280Z 6f9fca1 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@odrobnik odrobnik left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No findings.

The fix in API.swift turns encoder and decoder from lazy var into stored properties that are filled in as the object is created. That removes the unsynchronized lazy first access on this @unchecked Sendable class, which is the cause issue #45 identified for the crash. The public API stays the same (same types, still settable and configurable). Subclasses could not touch these properties before super.init in either version, and no production code replaces the coders after setup.

Tests:

  • The Mirror test reliably catches a return to lazy setup, because a lazy property starts empty.
  • The concurrent encoding test makes all requests wait and start together, with a 5 s timeout.
  • The image test does what the issue asks: it holds three stubbed HTTP responses and releases them together on a new shared provider, for both 200 and 400 replies.
  • The stub's wave and timeout handling looks correct. Old timers are ignored because each wave gets a new ID, and later tests in the serialized suite call script, which resets the state.

One pre-existing limit remains: assigning a new coder while requests are already running is still unsynchronized. The new comment documents this ("configure or replace them before starting requests"), and it is outside this issue's scope.

👍 No findings.

Reviewed by Claude · opus

@odrobnik
odrobnik merged commit 9137912 into main Dec 1, 2026
6 checks passed
@odrobnik
odrobnik deleted the agent/issue-45 branch December 1, 2026 20:50
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.

Concurrent first image requests can crash API's unsynchronized lazy JSON decoder

1 participant