Skip to content

fix(adapters): retain late chat tool-call index aliases - #3673

Closed
devswha wants to merge 1 commit into
lidge-jun:devfrom
devswha:codex/fix-chat-tool-index-alias-260905
Closed

fix(adapters): retain late chat tool-call index aliases#3673
devswha wants to merge 1 commit into
lidge-jun:devfrom
devswha:codex/fix-chat-tool-index-alias-260905

Conversation

@devswha

@devswha devswha commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Keep a streamed Chat tool call intact when the provider introduces it by ID, later sends that ID with an index, and then continues with index-only argument fragments. Previously the final fragment created a second unnamed call, split the JSON arguments, and failed the response.
  • Retain the observed index as an alias of the existing pending call while preserving its stable translator-budget key. Interleaved calls, existing index precedence, ID fallback, and byte limits keep their existing behavior.
  • Extend the existing stream-assembly regression and document the supported sequence in the adapter reference.

Verification

  • The original fixture failed through both the adapter and the Responses JSON bridge; an index-present-first control completed successfully.
  • bun test tests/adapters/openai/openai-chat-parallel-stream.test.ts tests/adapters/openai/openai-chat-hardening.test.ts tests/adapters/openai/openai-chat-eof.test.ts — 124 passed, 0 failed. Coverage includes interleaved calls, ambiguous missing associations, existing ID/index collision behavior, stable budget ownership, and byte-limit boundaries.
  • bun run typecheck — passed on the final head.
  • cd docs-site && bun run build — passed, 425 pages.
  • bun run privacy:scan — passed.
  • bun run test:changed on final head c8240c51d — 6,152 passed, 4 skipped, 0 failed across 334 files.
  • CodeRabbit manual review completed with no actionable comments.
  • Draft remains pending the full local-CI readiness gate and maintainer approval to run fork CI.
  • A separate full-suite review baseline completed with 19,250 passed, 16 skipped, 9 default-timeout failures, and 1 related asynchronous error. This branch does not claim a green full-suite run.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. No authentication, credential, or destination behavior changes.

Review readiness

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 74d03833-0b24-4b61-8034-af11a173db7a

📥 Commits

Reviewing files that changed from the base of the PR and between 6585e6a and c8240c5.

📒 Files selected for processing (3)
  • docs-site/src/content/docs/reference/adapters.md
  • src/adapters/openai-chat.ts
  • tests/adapters/openai/openai-chat-parallel-stream.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The OpenAI Chat adapter now retains index aliases for streamed tool calls. Tests cover late indexes, index-only fragments, conflicting or duplicate IDs, and argument-budget limits. Documentation describes the identity-preservation behavior.

Changes

OpenAI Chat tool-call identity

Layer / File(s) Summary
Resolve streamed tool-call identities
src/adapters/openai-chat.ts
parseStream stores the first observed index alias and uses it to match later fragments without changing the key that owns the argument budget.
Validate identity and budget behavior
tests/adapters/openai/openai-chat-parallel-stream.test.ts, docs-site/src/content/docs/reference/adapters.md
Tests cover late indexes, ambiguous index-only fragments, conflicting and duplicate IDs, alias retention, and argument-byte limits. Documentation describes the streaming behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to c8240

The OpenAI Chat adapter now correctly assembles streamed tool calls when IDs and indexes arrive in different fragments, with regression coverage for parallel calls and budget limits. No merge-blocking risk is identified.

Suggested reviewers: lidge-j

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: retaining late index aliases for streamed chat tool calls in the adapters.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (2/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 2/4).

Review readiness checklist

  • ⬜ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

2/4 boxes ticked.

This PR stays in draft until every box above is ticked.

Hygiene

Deterministic PR hygiene checks passed.

@devswha

devswha commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lidge-jun

Copy link
Copy Markdown
Owner

리뷰 · 우선순위 68 / 80

이 PR은 Chat Completions 스트림에서 도구 호출이 먼저 ID만, 다음에 ID+index, 그다음 index만 있는 argument 조각으로 이어질 때, 마지막 조각이 이름 없는 두 번째 호출을 만들어 JSON이 쪼개지던 버그를 고칩니다. src/adapters/openai-chat.tsPendingToolCallindexKey 별칭을 두고, 예산(budget) 소유 키는 처음 연 키를 유지한 채 나중에 관측된 index만 붙입니다. 이미 다른 index가 묶인 ID를 다시 다른 index로 옮기지는 않습니다. 병렬 호출·기존 index 우선·ID fallback·바이트 한도는 테스트로 고정했습니다.

지금 dev의 조립 로직은 rawIndex가 있으면 무조건 i:N 키로 새 슬롯을 찾기 때문에, ID-only로 시작된 호출과 이후 index-only 조각이 만나지 못합니다. OpenRouter 등 일부 공급자 스트림이 이 순서를 씁니다. 문서 reference/adapters.md에 지원 시퀀스를 한 단락 추가한 것도 운영자에게 도움이 됩니다. Draft이고 test:changed는 rebase 후 기록 예정이라고 본문에 있습니다.

테스트가 “index만으로 서로 다른 unindexed 두 호출을 추측하지 않는다”, “충돌 ID에서 index가 이긴다”, “중복 ID first-match”, “늦은 index에서도 argument byte limit”까지 넓혀서, 별칭 추가가 예전의 보수적 실패 모드를 무너뜨리지 않는지 잘 막아 두었습니다. types/config 분할과 무관합니다.

src/adapters/openai-chat.ts PendingToolCall.indexKey - ID-first 호출에 늦은 index 별칭; budget key 불변
같은 파일 find 경로 - indexKey로 재검색; 첫 index만 bind
openai-chat-parallel-stream.test.ts - T9b 확장·interleave·no-guess·limit 9/10
docs adapters.md - ID→index→index-only 조립 설명
Draft - ready 전 test:changed 결과 기입 필요

메인테이너의 판단이 필요한 지점

  • 이 별칭 동작을 openai-chat 공통 계약으로 바로 받을지
  • Draft 해제 조건으로 parallel-stream + hardening + eof 그린만으로 충분한지

너의 추천
스트림 도구 호출 실실패 수정으로 merge 쪽. 테스트 그린 확인 후 Draft 해제·merge.

이 댓글은 grok-bot이 작성했습니다

@lidge-jun

Copy link
Copy Markdown
Owner

Integrated into dev through #3702 (merge eeca697), preserving the original Hako-authored change and adding index/identity validation fixes. Exact-head Linux and macOS CI passed; the pinned remote macOS full suite passed 19,551 tests with 15 skips. Closing the original after verifying dev ancestry.

@lidge-jun lidge-jun closed this Sep 5, 2026
@lidge-jun lidge-jun added the landed-via-maintainer Original PR closed after landing via a maintainer merge train label Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working landed-via-maintainer Original PR closed after landing via a maintainer merge train

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants