Skip to content

refactor(openai-shim): extract transport lifecycle - #2071

Merged
kevincodex1 merged 5 commits into
Twigpine:mainfrom
jatmn:de-mono2-transport-lifecycle
Aug 7, 2026
Merged

kevincodex1 merged 5 commits into
Twigpine:mainfrom
jatmn:de-mono2-transport-lifecycle

Conversation

@jatmn

@jatmn jatmn commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • move response-header deadlines, abort-signal composition, response-body cleanup, and diagnostic redaction into paired openaiShim/transport.ts and transport.test.ts
  • keep the existing openaiShim.ts API while reducing the facade from 1,582 to 1,221 lines (10 additions, 371 deletions)
  • move associated API-timeout coverage beside the extracted module and add focused transport lifecycle tests
  • add the missing geminiStreamConversion.test.ts
  • move the architecture test beside openaiShim.ts and enforce same-basename source/test ownership for every production module under openaiShim/

Why

The merged OpenAI shim extractions left transport lifecycle and diagnostic logic in the facade. This isolates that cohesive responsibility without depending on any other follow-up extraction.

This branch is based directly on upstream main at b3735bed. The shared architecture relocation and Gemini pairing are byte-identical in all four drafts, and the conditional facade budget accounts for whichever extractions exist. All six branch pairs and all 24 four-PR merge orders were simulated successfully.

Impact

No intended user-facing or provider behavior change. Transport timeout, cancellation, proxy retry, redaction, and error-classification behavior remains wired through the same facade entrypoints. Future unpaired production modules under openaiShim/ fail the architecture guard.

Validation

  • focused architecture, transport, and Gemini suites: 10 pass
  • bun run typecheck
  • bun run build
  • bun run smoke
  • bun run deadcode
  • bun run check (environment-limited: 7,792 pass, 2 skip, 45 unrelated sandbox/filesystem/loopback failures)

Contributor checklist

  • Reviewed CONTRIBUTING.md and AGENTS.md.
  • No linked issue; this is focused post-extraction architecture housekeeping.
  • Provider behavior is unchanged; focused OpenAI-compatible transport paths were tested.
  • No UI changes or screenshots required.

Summary by CodeRabbit

  • New Features

    • Improved OpenAI-compatible connections with configurable header timeouts, cancellation support, proxy retries, safer diagnostic URL redaction, and clearer network error handling.
    • Improved Gemini streaming for text, tool calls, usage reporting, completion states, and aborted streams.
  • Tests

    • Expanded coverage for timeout settings, cancellation, diagnostics, response deadlines, transport behavior, and Gemini stream conversion.
    • Added architecture checks to support reliable service structure and test coverage.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The OpenAI shim now delegates transport behavior to openaiShim/transport.ts. Tests cover transport deadlines, cancellation, redaction, error classification, architecture constraints, and Gemini stream conversion.

Changes

OpenAI transport extraction

Layer / File(s) Summary
Timeout and abort lifecycle
src/services/api/openaiShim/transport.ts, src/services/api/openaiShim/transport.test.ts
Adds bounded timeout parsing, header deadlines, caller-abort preservation, response-body cleanup, and request-local environment tests.
Fetch execution and classified diagnostics
src/services/api/openaiShim/transport.ts, src/services/api/openaiShim/transport.test.ts
Adds proxy retries, URL and secret redaction, response cancellation, and classified transport errors.
Shim integration and architecture validation
src/services/api/openaiShim.ts, src/services/api/openaiShim.test.ts, src/services/api/openaiShim.architecture.test.ts
Moves transport implementations out of the shim, preserves getApiTimeoutMs through re-export, updates extraction accounting, and moves parser coverage to transport tests.

Gemini stream validation

Layer / File(s) Summary
Gemini event and abort coverage
src/services/api/openaiShim/geminiStreamConversion.test.ts
Adds SSE-based tests for text, function-call, usage, finish-state, and already-aborted stream handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: kevincodex1, 0xfandom, chioarub

🚥 Pre-merge checks | ✅ 7
✅ Passed checks (7 passed)
Check name Status Explanation
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.
Risk Surface Disclosed ✅ Passed The PR identifies transport timeout, cancellation, proxy retry, redaction, and error classification risks, and states that no user-facing behavior change or blocker is intended.
No Hidden Policy Change ✅ Passed The PR only relocates existing timeout, abort, retry, redaction, and error code; facade call sites and routing/auth wiring remain unchanged, with added tests and architecture checks.
Title check ✅ Passed The title is concise, scoped to the OpenAI shim, and accurately describes the transport lifecycle extraction.
Description check ✅ Passed The description covers the change, rationale, impact, testing, and notes, although it uses Validation instead of the template's Testing heading.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@jatmn
jatmn force-pushed the de-mono2-transport-lifecycle branch from d8f3967 to a3b939e Compare July 31, 2026 14:04

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/api/openaiShim/transport.test.ts`:
- Around line 54-104: Add focused coverage for cancellation during response-body
handling in fetchWithHeadersDeadline, verifying the caller-signal listener is
cleaned up after cancellation. Update the existing
disarms-the-deadline-on-headers-arrive test to use fake timers or a sufficiently
wide timing margin instead of the fixed 30 ms delay, while preserving its
response-body assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 80b21786-ba92-4230-b68c-31f660bae683

📥 Commits

Reviewing files that changed from the base of the PR and between d8f3967 and a3b939e.

📒 Files selected for processing (5)
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
  • src/services/api/openaiShim/transport.ts
💤 Files with no reviewable changes (1)
  • src/services/api/openaiShim.test.ts
📜 Review details
⚠️ CI failures not shown inline (6)

GitHub Actions: PR Checks / web: refactor(openai-shim): extract transport lifecycle

Conclusion: failure

View job details

##[group]Run bun run --cwd web build
 �[36;1mbun run --cwd web build�[0m
 shell: /usr/bin/bash -e {0}
 ##[endgroup]
 $ astro check && astro build && bun scripts/verify-dist.ts
 �[2m14:04:29�[22m �[34m[types]�[39m Generated �[2m49ms�[22m
 �[2m14:04:29�[22m �[34m[check]�[39m Getting diagnostics for Astro files in /home/runner/work/openclaude/openclaude/web...
 Result (35 files):
 - 0 errors
 - 0 warnings
 - 0 hints
 �[2m14:04:34�[22m �[34m[types]�[39m Generated �[2m50ms�[22m
 �[2m14:04:34�[22m �[34m[build]�[39m output: �[34m"static"�[39m
 �[2m14:04:34�[22m �[34m[build]�[39m mode: �[34m"static"�[39m
 �[2m14:04:34�[22m �[34m[build]�[39m directory: �[34m/home/runner/work/openclaude/openclaude/web/dist/�[39m
 �[2m14:04:34�[22m �[34m[build]�[39m Collecting build info...
 �[2m14:04:34�[22m �[34m[build]�[39m �[32m✓ Completed in 80ms.�[39m
 �[2m14:04:34�[22m �[34m[build]�[39m Building static entrypoints...
 �[2m14:04:35�[22m �[34m[vite]�[39m �[32m✓ built in 1.36s�[39m
 �[2m14:04:35�[22m �[34m[vite]�[39m �[32m✓ built in 21ms�[39m
 �[2m14:04:35�[22m �[34m[build]�[39m Rearranging server assets...
 �[42m�[30m generating static routes �[39m�[49m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/404.html�[22m �[2m(+12ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/buddy/index.html�[22m �[2m(+6ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/changelog/index.html�[22m �[2m(+4ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/cli-reference/index.html�[22m �[2m(+6ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/configuration/index.html�[22m �[2m(+6ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/installation/index.html�[22m �[2m(+3ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/keybindings/index.html�[22m �[2m(+6ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/providers/index.html�[22m �[2m(+5ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/quickstart/index.html�[22m �[2m(+4ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/skills/index.html�[22m �[2m(+4ms)�[22m
 �[2m14...

GitHub Actions: PR Checks / 2_web.txt: refactor(openai-shim): extract transport lifecycle

Conclusion: failure

View job details

##[group]Run bun run --cwd web build
 �[36;1mbun run --cwd web build�[0m
 shell: /usr/bin/bash -e {0}
 ##[endgroup]
 $ astro check && astro build && bun scripts/verify-dist.ts
 �[2m14:04:29�[22m �[34m[types]�[39m Generated �[2m49ms�[22m
 �[2m14:04:29�[22m �[34m[check]�[39m Getting diagnostics for Astro files in /home/runner/work/openclaude/openclaude/web...
 Result (35 files):
 - 0 errors
 - 0 warnings
 - 0 hints
 �[2m14:04:34�[22m �[34m[types]�[39m Generated �[2m50ms�[22m
 �[2m14:04:34�[22m �[34m[build]�[39m output: �[34m"static"�[39m
 �[2m14:04:34�[22m �[34m[build]�[39m mode: �[34m"static"�[39m
 �[2m14:04:34�[22m �[34m[build]�[39m directory: �[34m/home/runner/work/openclaude/openclaude/web/dist/�[39m
 �[2m14:04:34�[22m �[34m[build]�[39m Collecting build info...
 �[2m14:04:34�[22m �[34m[build]�[39m �[32m✓ Completed in 80ms.�[39m
 �[2m14:04:34�[22m �[34m[build]�[39m Building static entrypoints...
 �[2m14:04:35�[22m �[34m[vite]�[39m �[32m✓ built in 1.36s�[39m
 �[2m14:04:35�[22m �[34m[vite]�[39m �[32m✓ built in 21ms�[39m
 �[2m14:04:35�[22m �[34m[build]�[39m Rearranging server assets...
 �[42m�[30m generating static routes �[39m�[49m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/404.html�[22m �[2m(+12ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/buddy/index.html�[22m �[2m(+6ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/changelog/index.html�[22m �[2m(+4ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/cli-reference/index.html�[22m �[2m(+6ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/configuration/index.html�[22m �[2m(+6ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/installation/index.html�[22m �[2m(+3ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/keybindings/index.html�[22m �[2m(+6ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/providers/index.html�[22m �[2m(+5ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/quickstart/index.html�[22m �[2m(+4ms)�[22m
 �[2m14:04:35�[22m   �[34m├─�[39m �[2m/docs/skills/index.html�[22m �[2m(+4ms)�[22m
 �[2m14...

GitHub Actions: PR Checks / smoke-and-tests (22): refactor(openai-shim): extract transport lifecycle

Conclusion: failure

View job details

and caller overrides
 ##[endgroup]
 ##[group]src/components/PromptInput/PromptInputFooterLeftSide.test.ts:
 (pass) applyHistorySearchActiveState > closes help before activating history search
 (pass) applyHistorySearchActiveState > does not change help when history search ends
 (pass) resolveFooterOverlay > lets history search replace help and inline suggestions
 (pass) resolveFooterOverlay > shows suggestions before help outside history search
 (pass) resolveTransientFooterMessage > shows transient feedback outside history search
 (pass) resolveTransientFooterMessage > lets history search replace pending transient feedback
 (pass) resolveTransientFooterMessage > prioritizes exit feedback when paste feedback is also active
 (pass) resolveRegularFooterActive > requires both parent visibility and no transient message
 ##[endgroup]
 ##[group]src/components/TrustDialog/utils.test.ts:
 (pass) getRelativeSettingsFilePathForSource returns the canonical .openclaude/ paths
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > reports canonical paths when hooks present in both sources [1.00ms]
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > reports only project when local has no hooks [1.00ms]
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > empty hooks object does not count as having hooks
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > hooks with empty matcher arrays do not count [1.00ms]
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > fileSuggestion alone counts as a hook source
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > disableAllHooks suppresses even when hooks are configured [1.00ms]
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > null settings produce no sources [1.00ms]
 (pass) TrustDialog utils — canonical paths...

GitHub Actions: PR Checks / 1_smoke-and-tests (24.11.x).txt: refactor(openai-shim): extract transport lifecycle

Conclusion: failure

View job details

s) classifies a FastAPI validation rejection at its normal 422 status
 (pass) classifies a root structured tool_stream unsupported message
 (pass) classifies a root tool_stream extra-field rejection alongside tool validation details
 (pass) does not classify a generic 400 as tool_stream_unsupported
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Tool "tool_stream" is unsupported
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Function 'tool_stream' is invalid
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Tool: tool_stream is unsupported
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Function: tool_stream is invalid
 (pass) does not classify a tool name error as a tool_stream parameter rejection: tool_stream is unsupported as a function
 (pass) does not classify a tool name error as a tool_stream parameter rejection: tool_stream is unsupported as a tool
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Additional properties are not allowed in function tool_stream
 (pass) does not classify a tool name error as a tool_stream parameter rejection: The tool named "tool_stream" is unsupported
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Function name tool_stream is invalid
 (pass) does not classify an invalid schema for a tool named tool_stream as a parameter rejection
 (pass) does not classify a raw tool-schema property error as a parameter rejection [1.00ms]
 (pass) does not classify a tool-schema error whose location follows the parameter name
 (pass) does not classify a generic schema diagnostic as a parameter rejection: Invalid schema: param=tool_stream
 (pass) does not classify a generic schema diagnostic as a parameter rejection: Malformed tool schema: unexpected property tool_stream
 (pass) does not classify a generic schema diagnostic as a parameter rejecti...

GitHub Actions: PR Checks / smoke-and-tests (24.11.x): refactor(openai-shim): extract transport lifecycle

Conclusion: failure

View job details

ortcutsHint > always suppresses during ctrl-r search and caller overrides
 ##[endgroup]
 ##[group]src/components/PromptInput/PromptInputFooterLeftSide.test.ts:
 (pass) applyHistorySearchActiveState > closes help before activating history search [1.00ms]
 (pass) applyHistorySearchActiveState > does not change help when history search ends
 (pass) resolveFooterOverlay > lets history search replace help and inline suggestions
 (pass) resolveFooterOverlay > shows suggestions before help outside history search
 (pass) resolveTransientFooterMessage > shows transient feedback outside history search
 (pass) resolveTransientFooterMessage > lets history search replace pending transient feedback
 (pass) resolveTransientFooterMessage > prioritizes exit feedback when paste feedback is also active
 (pass) resolveRegularFooterActive > requires both parent visibility and no transient message
 ##[endgroup]
 ##[group]src/components/TrustDialog/utils.test.ts:
 (pass) getRelativeSettingsFilePathForSource returns the canonical .openclaude/ paths
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > reports canonical paths when hooks present in both sources [1.00ms]
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > reports only project when local has no hooks [1.00ms]
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > empty hooks object does not count as having hooks
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > hooks with empty matcher arrays do not count [1.00ms]
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > fileSuggestion alone counts as a hook source [1.00ms]
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > disableAllHooks suppresses even when hooks are configured
 (pass) TrustDialog utils — canonical paths from source-of-truth > getHooksSources > null settings produce n...

GitHub Actions: PR Checks / 3_smoke-and-tests (22).txt: refactor(openai-shim): extract transport lifecycle

Conclusion: failure

View job details

t its normal 422 status [1.00ms]
 (pass) classifies a root structured tool_stream unsupported message
 (pass) classifies a root tool_stream extra-field rejection alongside tool validation details
 (pass) does not classify a generic 400 as tool_stream_unsupported
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Tool "tool_stream" is unsupported
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Function 'tool_stream' is invalid
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Tool: tool_stream is unsupported
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Function: tool_stream is invalid
 (pass) does not classify a tool name error as a tool_stream parameter rejection: tool_stream is unsupported as a function
 (pass) does not classify a tool name error as a tool_stream parameter rejection: tool_stream is unsupported as a tool
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Additional properties are not allowed in function tool_stream
 (pass) does not classify a tool name error as a tool_stream parameter rejection: The tool named "tool_stream" is unsupported
 (pass) does not classify a tool name error as a tool_stream parameter rejection: Function name tool_stream is invalid
 (pass) does not classify an invalid schema for a tool named tool_stream as a parameter rejection
 (pass) does not classify a raw tool-schema property error as a parameter rejection
 (pass) does not classify a tool-schema error whose location follows the parameter name
 (pass) does not classify a generic schema diagnostic as a parameter rejection: Invalid schema: param=tool_stream
 (pass) does not classify a generic schema diagnostic as a parameter rejection: Malformed tool schema: unexpected property tool_stream
 (pass) does not classify a generic schema diagnostic as a parameter rejection: Additional properties are not allowed: too...
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

TypeScript code in this repository must use strict mode and ESM imports.

**/*.{ts,tsx}: Add or update tests when a TypeScript or TSX change affects behavior.
Run the relevant TypeScript validation checks for changed code, including bun run typecheck and, when applicable, bun run typecheck:type-tests.

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts
**/*

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*: Preserve existing repository patterns unless intentionally refactoring them.
Keep changes small, readable, and focused; avoid broad rewrites or unrelated cleanup.
Do not reformat unrelated files, and keep comments useful and concise.
Update documentation when setup, commands, or user-facing behavior changes.
Review AI-generated changes for correctness, style consistency, unnecessary noise, and adherence to project architecture before submitting them.
Provider changes must follow the documented integration patterns in docs/integrations/overview.md and the focused guides under docs/integrations/how-to/.
When changing provider behavior, avoid breaking third-party providers and test the exact provider/model path changed when possible.
Provider pull requests must explicitly identify affected providers, limitations, and follow-up work.
Run the narrowest meaningful validation command for the touched area, and ensure relevant CI checks pass before merging.
Use bun install to install dependencies and the repository's Bun scripts for building, testing, smoke testing, and development.
Dependency changes require a concrete project benefit such as a bug fix, security issue, or approved feature; preference alone is insufficient.
Do not change the project's language, core runtime, or dependency stack, or introduce a new runtime, without prior maintainer agreement.
Keep each pull request focused on one issue or clearly scoped improvement and avoid bundling unrelated fixes, features, or refactors.

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/services/api/openaiShim/transport.test.ts
  • src/services/api/openaiShim.architecture.test.ts
🔇 Additional comments (10)
src/services/api/openaiShim/transport.ts (7)

22-65: LGTM!


67-120: LGTM!


122-177: LGTM!


245-302: LGTM!


304-338: LGTM!


340-383: LGTM!


238-242: 🩺 Stability & Availability

No change required.

All in-repository callers pass options.signal as both init.signal and callerSignal. No current call path supplies only init.signal.

			> Likely an incorrect or invalid review comment.
src/services/api/openaiShim/transport.test.ts (1)

9-52: LGTM!

src/services/api/openaiShim.architecture.test.ts (1)

5-25: LGTM!

src/services/api/openaiShim.ts (1)

98-107: 🗄️ Data Integrity & Integration

Preserve the current shim facade exports.

Only getApiTimeoutMs was exported by src/services/api/openaiShim.ts; the other transport symbols were private. The extraction does not change the shim export surface.

			> Likely an incorrect or invalid review comment.

Comment thread src/services/api/openaiShim/transport.test.ts
@jatmn
jatmn force-pushed the de-mono2-transport-lifecycle branch from a3b939e to 4093316 Compare July 31, 2026 14:36
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 31, 2026
jatmn added 2 commits August 6, 2026 08:19
Rebase onto current main and clean up the transport extraction follow-ups:
drop stale facade imports left after the move and restore the full API
timeout parser negative-case coverage in transport.test.ts.
@jatmn
jatmn force-pushed the de-mono2-transport-lifecycle branch from 7bb26e0 to 3519eda Compare August 6, 2026 15:23
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai 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.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/api/openaiShim.architecture.test.ts`:
- Around line 5-6: Update the path construction in the test around facadePath
and moduleDirectory to import and use node:path.join for transport and related
module paths. Remove manually appended separators, relying on path.join to
normalize separators across platforms while preserving the existing target
paths.
- Line 19: Update the existence check in openaiShim.architecture.test so the
upstream mandatory slice includes transport.ts by raising the count used for the
initial extractionDeltas slice. Keep the later optional-accounting logic
unchanged, but make sure the assertion loop now covers transport.ts via the same
symbol names used there (upstreamExtractionCount and extractionDeltas) so the
new module is required to exist.

In `@src/services/api/openaiShim/geminiStreamConversion.test.ts`:
- Around line 29-45: Extend the Gemini conversion tests around the existing
“converts Gemini text, tool calls, usage, and finish state” case with separate
no-tool responses that verify STOP maps to end_turn and, when supported by the
converter, MAX_TOKENS maps to max_tokens. Keep the existing tool-call coverage
intact, but ensure finish-reason assertions run without functionCall parts so
they validate the finish mapping directly.
- Around line 77-88: Extend the test “rejects an already-aborted Gemini stream
without yielding events” to use a custom ReadableStream or cancellation spy,
then assert that the stream reader’s cancel operation is invoked when the
AbortSignal is already aborted. Preserve the existing AbortError rejection
assertion and keep the coverage focused on cleanup during initial abort
handling.
- Around line 35-68: Strengthen the test around geminiSseToAnthropic by
asserting the Read tool input includes file_path: 'a.ts', and verify the emitted
events occur in order: content-block start, tool input, content-block stop,
message_delta, then message_stop. Preserve the existing message_start and text
assertions while adding these user-visible tool-event checks.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b6433eaa-0910-48de-84e5-15965f8228a5

📥 Commits

Reviewing files that changed from the base of the PR and between b0cbfe1 and 3519eda.

📒 Files selected for processing (7)
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/architecture.test.ts
  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim/transport.test.ts
  • src/services/api/openaiShim/transport.ts
💤 Files with no reviewable changes (2)
  • src/services/api/openaiShim/architecture.test.ts
  • src/services/api/openaiShim.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: smoke-and-tests (24.11.x)
  • GitHub Check: smoke-and-tests (22)
  • GitHub Check: typecheck
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript with strict mode and ESM imports.
Use React and Ink for terminal UI components.
Prefer existing service, provider, settings, permission, and UI patterns over introducing new abstractions.
Use chalk for terminal color, commander for CLI argument parsing, and execa for child processes where those concerns are needed.

Files:

  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
src/services/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Place API, MCP, OAuth, wiki, voice, and other service integrations under src/services/.

Files:

  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
**/*.{ts,tsx,json,md}

📄 CodeRabbit inference engine (AGENTS.md)

Do not silently change provider tags; maintainers control them during review.

Files:

  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.{js,jsx,ts,tsx}: Follow the existing code style in touched JavaScript and TypeScript source files.
Keep comments useful and concise in JavaScript and TypeScript source files.

Files:

  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim/transport.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/transport.test.ts
🔇 Additional comments (9)
src/services/api/openaiShim.ts (1)

98-106: LGTM!

src/services/api/openaiShim.architecture.test.ts (1)

42-50: LGTM!

src/services/api/openaiShim/transport.test.ts (2)

86-104: Add a post-header cancellation regression test.

The mocked fetch ignores init.signal. An active deadline can abort after headers without changing response.text(). This test cannot verify that the deadline is disarmed.

Capture the request signal and assert that it remains un-aborted after the deadline interval. Also exercise early body cancellation through the fallback signal-composition path. After cancellation, abort the caller signal and verify that the captured combined signal does not abort.

As per path instructions, add focused tests for transport lifecycle, timeout, and cancellation behavior.

Source: Path instructions


1-84: LGTM!

src/services/api/openaiShim/transport.ts (4)

1-65: LGTM!


67-177: LGTM!


179-243: LGTM!


245-383: LGTM!

src/services/api/openaiShim/geminiStreamConversion.test.ts (1)

1-27: LGTM!

Comment thread src/services/api/openaiShim.architecture.test.ts
Comment thread src/services/api/openaiShim.architecture.test.ts
Comment thread src/services/api/openaiShim/geminiStreamConversion.test.ts Outdated
Comment thread src/services/api/openaiShim/geminiStreamConversion.test.ts Outdated
Comment thread src/services/api/openaiShim/geminiStreamConversion.test.ts
Use path.join in the architecture guard, require transport.ts in the
mandatory extraction slice, strengthen Gemini stream conversion coverage,
and add transport deadline/cancellation regression tests with fake timers.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/api/openaiShim/transport.test.ts`:
- Around line 115-141: Update the test around fetchWithHeadersDeadline so that
after response.body.cancel() completes cleanupAfterBody, a later caller.abort()
does not abort capturedSignal or propagate its reason. Keep the timeout
assertion intact and change the final expectations to verify the cleaned-up
combined request signal remains un aborted.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 47107cb4-2595-4a84-aed2-eb9fd346ccd8

📥 Commits

Reviewing files that changed from the base of the PR and between 3519eda and 83131b5.

📒 Files selected for processing (3)
  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim/transport.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: smoke-and-tests (22)
  • GitHub Check: typecheck
  • GitHub Check: smoke-and-tests (24.11.x)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript with strict mode and ESM imports.
Use React and Ink for terminal UI components.
Prefer existing service, provider, settings, permission, and UI patterns over introducing new abstractions.
Use chalk for terminal color, commander for CLI argument parsing, and execa for child processes where those concerns are needed.

Files:

  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim/transport.test.ts
src/services/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Place API, MCP, OAuth, wiki, voice, and other service integrations under src/services/.

Files:

  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim/transport.test.ts
**/*.{ts,tsx,json,md}

📄 CodeRabbit inference engine (AGENTS.md)

Do not silently change provider tags; maintainers control them during review.

Files:

  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim/transport.test.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.{js,jsx,ts,tsx}: Follow the existing code style in touched JavaScript and TypeScript source files.
Keep comments useful and concise in JavaScript and TypeScript source files.

Files:

  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim/transport.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim/transport.test.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim/transport.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/services/api/openaiShim.architecture.test.ts
  • src/services/api/openaiShim/geminiStreamConversion.test.ts
  • src/services/api/openaiShim/transport.test.ts
🔇 Additional comments (6)
src/services/api/openaiShim/transport.test.ts (1)

1-19: LGTM!

Also applies to: 88-113

src/services/api/openaiShim.architecture.test.ts (1)

2-2: LGTM!

Also applies to: 26-34

src/services/api/openaiShim/geminiStreamConversion.test.ts (4)

29-43: LGTM!


45-94: LGTM!


96-124: LGTM!


126-144: LGTM!

Comment thread src/services/api/openaiShim/transport.test.ts Outdated
Exercise the combineRequestSignals fallback without AbortSignal.any so
early body cancellation removes caller listeners and a later caller.abort
does not abort the combined fetch signal.
@jatmn

jatmn commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed the remaining transport.test.ts review: the early body-cancel case now disables AbortSignal.any and asserts the manual combineRequestSignals fallback removes caller listeners after cleanupAfterBody, so a later caller.abort() does not abort the captured combined signal. Pushed in b3c06ce.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/api/openaiShim/transport.test.ts`:
- Around line 117-124: Update the AbortSignal.any cleanup in the test’s finally
block to distinguish an originally absent property from an originally defined
one: restore the saved descriptor when originalAbortSignalAny exists, otherwise
delete the temporary AbortSignal.any property. Ensure each test leaves the
global AbortSignal state exactly as it was before the test.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 88faf541-d1de-4141-adf0-fee602a89dfc

📥 Commits

Reviewing files that changed from the base of the PR and between 83131b5 and b3c06ce.

📒 Files selected for processing (1)
  • src/services/api/openaiShim/transport.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: web
  • GitHub Check: typecheck
  • GitHub Check: smoke-and-tests (24.11.x)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript with strict mode and ESM imports.
Use React and Ink for terminal UI components.
Prefer existing service, provider, settings, permission, and UI patterns over introducing new abstractions.
Use chalk for terminal color, commander for CLI argument parsing, and execa for child processes where those concerns are needed.

Files:

  • src/services/api/openaiShim/transport.test.ts
src/services/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Place API, MCP, OAuth, wiki, voice, and other service integrations under src/services/.

Files:

  • src/services/api/openaiShim/transport.test.ts
**/*.{ts,tsx,json,md}

📄 CodeRabbit inference engine (AGENTS.md)

Do not silently change provider tags; maintainers control them during review.

Files:

  • src/services/api/openaiShim/transport.test.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

**/*.{js,jsx,ts,tsx}: Follow the existing code style in touched JavaScript and TypeScript source files.
Keep comments useful and concise in JavaScript and TypeScript source files.

Files:

  • src/services/api/openaiShim/transport.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/services/api/openaiShim/transport.test.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/services/api/openaiShim/transport.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/services/api/openaiShim/transport.test.ts

Comment thread src/services/api/openaiShim/transport.test.ts
Delete the temporary AbortSignal.any override when the runtime did not
define an own property, so transport and facade signal-cleanup tests leave
global AbortSignal state unchanged for later cases.
@jatmn
jatmn marked this pull request as ready for review August 6, 2026 17:55

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@kevincodex1
kevincodex1 merged commit bac012f into Twigpine:main Aug 7, 2026
5 of 9 checks passed
@jatmn
jatmn deleted the de-mono2-transport-lifecycle branch August 7, 2026 01:58
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.

2 participants