Skip to content

ci: refuse lossy RBS comment rewrites - #620

Merged
jbeckwith-oai merged 1 commit into
mainfrom
codex/autoimprove-20260904-7-rbs-comments
Sep 4, 2026
Merged

ci: refuse lossy RBS comment rewrites#620
jbeckwith-oai merged 1 commit into
mainfrom
codex/autoimprove-20260904-7-rbs-comments

Conversation

@jbeckwith-oai

Copy link
Copy Markdown
Contributor

Problem

The repository RBS formatter can silently drop trailing comments that its underlying formatter does not preserve. A formatting run could therefore rewrite an RBS file and lose human-authored context without reporting an error.

Change

  • Compare the ordered comment-token sequence from the original source with the final post-alias-restoration formatter output.
  • Use RBS::Parser.lex(...).value so only real RBS comments participate; # inside strings and annotations remains ordinary syntax.
  • Ignore only trailing space/tab and CRLF normalization that formatting legitimately changes.
  • Raise a concise content-free error before format returns, so both check and write modes refuse a lossy result before a file can be written.

Reproduction and verification

Before this change, the offline synthetic reproduction wrote away trailing comments on a type declaration, constant, and method without error. With this change, those same cases raise RBS formatter cannot safely preserve comments; format manually, and the source tempfile remains byte-for-byte unchanged. Standalone comments plus literal/annotation # controls continue to succeed.

Tests and checks run with Ruby 4.0.6:

  • bundle exec ruby -Itest test/scripts/rbs_format_comment_loss_test.rb — 4 runs, 22 assertions
  • bundle exec ruby -Itest test/scripts/rbs_format_test.rb — 17 runs, 52 assertions
  • bundle exec ruby -Itest test/scripts/formatting_policy_test.rb — 11 runs, 208 assertions
  • Offline verify_rbs_comment_loss.rb red/green reproduction — lossy cases now fail before writes; controls pass
  • Read-only sig/**/*.rbs scan — 1,279 files, 0 proposed changes, 0 guard errors
  • bundle exec rake lint — RuboCop 2,874 files, typecheck clean, 1,279 RBS files validated
  • TEST_API_BASE_URL=http://127.0.0.1:49137 bundle exec rake test — 1,634 runs, 14,513 assertions, 0 failures, 0 errors, 1 skip
  • Trusted current-main public custom-code check on committed candidate — 3,363 / 4,000 lines, 637 headroom

Scope and compatibility

This is deliberately a fail-safe output guard, not a new comment-placement implementation or formatter rewrite. It changes only scripts/rbs_format.rb and a focused handwritten test. Existing record formatting, class/module alias restoration, parse errors, deterministic path ordering, ordinary check/write behavior, and idempotence remain intact.

Review

Adversarial review used fresh independent correctness and architecture reviewers. After correcting narrow whitespace and CRLF normalization findings, two consecutive rounds were clean. A bounded security review found no credential, network, dependency, deserialization, workflow, or logging surface change; the new error intentionally contains no source or comment text.

Requesting @openai/sdks-team review for this build-tooling behavior.

@jbeckwith-oai
jbeckwith-oai requested a review from a team as a code owner September 4, 2026 17:58
@jbeckwith-oai jbeckwith-oai added codex-maintenance Low-risk maintenance changes created by Codex autoimprove Automated repository-health improvements labels Sep 4, 2026
@openai-sdks

openai-sdks Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

OkTest Summary

237/237 SDK tests passed in 8.118s for Ruby SDK PR #620.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 78ms
tests/chat-completions-create.test.ts ✅ Passed 180ms
tests/chat-completions-stream.test.ts ✅ Passed 96ms
tests/files-content-binary.test.ts ✅ Passed 104ms
tests/files-create-multipart.test.ts ✅ Passed 193ms
tests/files-list-pagination.test.ts ✅ Passed 214ms
tests/initialize-config.test.ts ✅ Passed 112ms
tests/instance-isolation.test.ts ✅ Passed 99ms
tests/models-list.test.ts ✅ Passed 132ms
tests/responses-background-lifecycle.test.ts ✅ Passed 137ms
tests/responses-body-method-errors.test.ts ✅ Passed 256ms
tests/responses-cancel-timeout.test.ts ✅ Passed 191ms
tests/responses-cancel.test.ts ✅ Passed 168ms
tests/responses-compact-retries.test.ts ✅ Passed 146ms
tests/responses-compact.test.ts ✅ Passed 155ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 111ms
tests/responses-create-advanced.test.ts ✅ Passed 140ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.038s
tests/responses-create-errors.test.ts ✅ Passed 213ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 105ms
tests/responses-create-retries.test.ts ✅ Passed 226ms
tests/responses-create-stream-failures.test.ts ✅ Passed 98ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 174ms
tests/responses-create-stream-wire.test.ts ✅ Passed 2.138s
tests/responses-create-stream.test.ts ✅ Passed 91ms
tests/responses-create-terminal-states.test.ts ✅ Passed 110ms
tests/responses-create-timeout.test.ts ✅ Passed 186ms
tests/responses-create.test.ts ✅ Passed 171ms
tests/responses-delete.test.ts ✅ Passed 136ms
tests/responses-input-items-errors.test.ts ✅ Passed 136ms
tests/responses-input-items-list.test.ts ✅ Passed 206ms
tests/responses-input-items-options.test.ts ✅ Passed 99ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 205ms
tests/responses-input-tokens-count.test.ts ✅ Passed 150ms
tests/responses-malformed-inputs.test.ts ✅ Passed 1.89s
tests/responses-not-found-errors.test.ts ✅ Passed 200ms
tests/responses-parse.test.ts ✅ Passed 121ms
tests/responses-retrieve-retries.test.ts ✅ Passed 251ms
tests/responses-retrieve.test.ts ✅ Passed 174ms
tests/responses-stored-method-errors.test.ts ✅ Passed 734ms
tests/retry-behavior.test.ts ✅ Passed 3.132s
tests/sdk-error-shape.test.ts ✅ Passed 211ms

View OkTest run #33903380110

SDK merge (2e55e24a8193) · head (7faace239fea) · base (4322e076e57b) · OkTest (2b1bdfd25e98)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T18:00:41.650141Z 7faace2 PR opened
🔒 Security Review Completed 2026-09-04T18:00:13.592209Z 7faace2 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.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Castiron custom code

✅ No new custom-code files detected.

47 mixed files remain; 0 existing customizations changed.

Compared eabba56b90a97faace239fea. Generated baselines verified.

47 existing customizations unchanged
  • lib/openai.rb
  • lib/openai/client.rb
  • lib/openai/models/chat/chat_completion_message.rb
  • lib/openai/models/chat/chat_completion_message_function_tool_call.rb
  • lib/openai/models/chat/completion_create_params.rb
  • lib/openai/models/response_format_json_schema.rb
  • lib/openai/models/responses/function_tool.rb
  • lib/openai/models/responses/response.rb
  • lib/openai/models/responses/response_create_params.rb
  • lib/openai/models/responses/response_format_text_config.rb
  • lib/openai/models/responses/response_format_text_json_schema_config.rb
  • lib/openai/models/responses/response_function_tool_call.rb
  • lib/openai/models/responses/response_function_web_search.rb
  • lib/openai/models/responses/response_output_text.rb
  • lib/openai/models/responses/tool.rb
  • lib/openai/resources/beta/threads.rb
  • lib/openai/resources/chat/completions.rb
  • lib/openai/resources/files.rb
  • lib/openai/resources/responses.rb
  • lib/openai/resources/vector_stores/file_batches.rb
  • lib/openai/resources/vector_stores/files.rb
  • lib/openai/resources/webhooks.rb
  • rbi/openai/client.rbi
  • rbi/openai/models/chat/chat_completion_message.rbi
  • rbi/openai/models/chat/chat_completion_message_function_tool_call.rbi
  • rbi/openai/models/chat/completion_create_params.rbi
  • rbi/openai/models/response_format_json_schema.rbi
  • rbi/openai/models/responses/response.rbi
  • rbi/openai/models/responses/response_create_params.rbi
  • rbi/openai/models/responses/response_function_tool_call.rbi
  • rbi/openai/models/responses/response_function_web_search.rbi
  • rbi/openai/models/responses/response_output_text.rbi
  • rbi/openai/resources/chat/completions.rbi
  • rbi/openai/resources/files.rbi
  • rbi/openai/resources/responses.rbi
  • rbi/openai/resources/vector_stores/file_batches.rbi
  • rbi/openai/resources/vector_stores/files.rbi
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py

7 more in the full report.

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 33903404622 --repo openai/openai-ruby \
  --name castiron-custom-code-33903404622-1 --dir /tmp/castiron-custom-code-33903404622-1
git apply --stat /tmp/castiron-custom-code-33903404622-1/custom-code.patch
cat /tmp/castiron-custom-code-33903404622-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin 4322e076e57b769d619175006307763e3c630cfb 7faace239fea22cb7574ec99c5880bb97dd8e874
python3 scripts/castiron/custom_code_report.py report \
  --base 4322e076e57b769d619175006307763e3c630cfb \
  --head 7faace239fea22cb7574ec99c5880bb97dd8e874 --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-7faace239fea
cat /tmp/castiron-custom-code-7faace239fea/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using the RBS lexer rather than textual # matching is the right safety boundary: comments inside strings/annotations are excluded, while the ordered real-comment token sequence must survive formatting. Normalizing only trailing space/tab and CRLF noise keeps the guard narrow enough not to bless substantive rewrites. Failing before format returns also protects both check and write modes from partial loss.

@markstuart-oai markstuart-oai 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.

Reviewed the comment-preservation guard and its check/write paths. The lexer-based comparison runs after alias restoration and rejects lossy output before a file is written. The regression tests cover trailing-comment loss, preserved comments, literal hashes, CRLF, and idempotence. No substantive issues found. Existing native CI passed across Ruby 3.3, 3.4, and 4.0; local tests were not rerun.

@jbeckwith-oai
jbeckwith-oai added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit 7fddc48 Sep 4, 2026
20 checks passed
@jbeckwith-oai
jbeckwith-oai deleted the codex/autoimprove-20260904-7-rbs-comments branch September 4, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autoimprove Automated repository-health improvements codex-maintenance Low-risk maintenance changes created by Codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants