Skip to content

refactor(protocols): restore Chat/Responses ToolChoice separation invariant - #1314

Merged
slin1237 merged 1 commit into
mainfrom
refactor/audit-c2-followup
Apr 22, 2026
Merged

slin1237 merged 1 commit into
mainfrom
refactor/audit-c2-followup

Conversation

@slin1237

@slin1237 slin1237 commented Apr 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #1310. Restores an architectural invariant that was over-pruned in that PR: the `NOTE` explaining that `ResponsesToolChoice` must remain separate from `common::ToolChoice` because Chat Completions has different `Function` wire shape and does not accept Responses-specific variants (`Types`/`Mcp`/`Custom`/`ApplyPatch`/`Shell`).

gemini-code-assist raised this as a medium-priority concern on #1310 after that PR was already merged, flagging that losing this context could let future refactors merge the two enums and silently accept spec-invalid payloads on `/v1/chat/completions`.

Why

The original paragraph in #1310 was dropped as "deliberately" / "PR-body-in-source" prose. But it also carried a real invariant a future reader would miss. Per C2's own PRUNE rule ("shorten without deleting"), the correct outcome is a condensed NOTE that keeps the invariant and drops the audit framing.

What

One 5-line `NOTE:` block added above the `ResponsesToolChoice` derives:

```rust
/// NOTE: kept separate from `common::ToolChoice`. Chat Completions uses
/// a different `Function` wire shape (nested `{"function": {"name": ...}}`)
/// and does not accept the `Types` / `Mcp` / `Custom` / `ApplyPatch` /
/// `Shell` variants; sharing one enum would let `/v1/chat/completions`
/// silently accept spec-invalid payloads.
```

Acceptance

  • cargo check -p openai-protocol --lib --tests: green
  • cargo clippy -p openai-protocol --lib --tests -- -D warnings: green
  • cargo test -p openai-protocol --lib --tests: all pass (18 lib + 41 integration + 94 on responses)
  • No semantic changes. Doc comment only.

Refs: #1310

Summary by CodeRabbit

  • Documentation
    • Updated internal documentation to clarify design rationale for API response structures.

Note: This release contains no user-visible changes or functional updates.

…ariant

Gemini code-assist reviewer flagged that the original over-prune lost a
real architectural invariant on `ResponsesToolChoice`: that it must NOT
share common.rs with Chat Completions's `ToolChoice`, because Chat uses
a different `Function` wire shape and does not accept
`Types`/`Mcp`/`Custom`/`ApplyPatch`/`Shell`. Merging the two would let
`/v1/chat/completions` silently accept Responses-only variants.

Restores this as a concise `NOTE:` paragraph (5 lines vs. the original
6), per the task's PRUNE rule ("shorten without deleting"). The
audit-process narrative ("deliberately does NOT live in common.rs") is
still out; only the invariant remains.

No semantic changes. Tests still pass (94/94).

Addresses: PR #1310 gemini-code-assist review comment at responses.rs:176
Signed-off-by: Simo Lin <linsimo.mark@gmail.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 86f13284-cec3-422a-824f-df1ae2209ca4

📥 Commits

Reviewing files that changed from the base of the PR and between 3f36c80 and 8e9fd79.

📒 Files selected for processing (1)
  • crates/protocols/src/responses.rs

📝 Walkthrough

Walkthrough

A documentation note was added to ResponsesToolChoice clarifying why it is intentionally kept separate from common::ToolChoice. The note explains that Chat Completions uses a different nested Function wire shape and does not accept certain ResponsesToolChoice variants, preventing spec-invalid payloads.

Changes

Cohort / File(s) Summary
Documentation Note
crates/protocols/src/responses.rs
Added clarification documentation to ResponsesToolChoice explaining the intentional separation from common::ToolChoice due to different wire shapes and accepted variant differences in Chat Completions API.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Suggested labels

protocols

Suggested reviewers

  • CatherineSue
  • key4ng

Poem

🐰 A note, so clear, now marks the way,
Why variants part, they'll always stay,
No wire shapes mixed, no specs defied,
Just careful words to be our guide!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: restoring a documentation note that clarifies the architectural invariant requiring Chat/Responses ToolChoice separation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/audit-c2-followup

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the protocols Protocols crate changes label Apr 22, 2026

@claude claude Bot 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.

Documentation-only change: adds a well-written NOTE explaining why ResponsesToolChoice is kept separate from common::ToolChoice. Verified the claims are accurate against both enums. No issues found.

@slin1237
slin1237 merged commit fd494e0 into main Apr 22, 2026
38 checks passed
@slin1237
slin1237 deleted the refactor/audit-c2-followup branch April 22, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

protocols Protocols crate changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant