Skip to content

fix: resolve tool getter double-invocation, dedup getMergedTools, fix openaiShim errors#1473

Closed
skyhighbg22-jpg wants to merge 1 commit into
Gitlawb:mainfrom
skyhighbg22-jpg:fix/bug-fixes-and-optimizations
Closed

fix: resolve tool getter double-invocation, dedup getMergedTools, fix openaiShim errors#1473
skyhighbg22-jpg wants to merge 1 commit into
Gitlawb:mainfrom
skyhighbg22-jpg:fix/bug-fixes-and-optimizations

Conversation

@skyhighbg22-jpg

Copy link
Copy Markdown
Contributor

Summary

Fixes 5 bugs and adds 2 performance optimizations to existing code. No new features or tools.

Bug Fixes

File Fix
src/tools.ts:214,217,230 Cache lazy require() getter results to avoid double-invocation (getSendMessageTool, getPowerShellTool)
src/tools.ts:380-386 getMergedTools() now uses uniqBy to deduplicate, matching assembleToolPool() behavior
src/services/api/openaiShim.ts:1471 Error status defaults to 500 instead of 200 (`response.status
src/services/api/openaiShim.ts:236,238 Redaction fallback returns [redacted] instead of unredacted URL when redactSecretValueForDisplay fails
src/main.tsx:270 Debugger detection writes error message to stderr before process.exit(1)

Optimizations

File Fix
src/query.ts:1734-1751 Tool result lookup uses Map<tool_use_id, result> for O(N+M) instead of O(N×M×K) nested find()
src/services/api/openaiShim.ts:2733 Non-streaming path reads body once and recreates Response instead of response.clone() which doubles memory
src/services/api/openaiShim.ts:2682 Provider detection uses new URL().hostname parsing instead of fragile baseUrl.includes() substring matching

Testing

  • Build passes: bun run build
  • Smoke test: node dist/cli.mjs --version0.15.0

… fix openaiShim errors

Bug fixes:
- Cache lazy require() getter results in tools.ts to avoid double-invocation
- getMergedTools() now uses uniqBy to deduplicate like assembleToolPool()
- openaiShim error status defaults to 500 instead of 200
- Redaction fallback returns [redacted] instead of unredacted URL
- Provider detection uses hostname parsing instead of fragile URL substring matching
- Debugger detection now writes error message before exit

Optimizations:
- Replace O(N*M*K) tool result lookup with Map-based O(N+M) in query.ts
- Eliminate response.clone() memory doubling in openaiShim non-streaming path
@skyhighbg22-jpg

Copy link
Copy Markdown
Contributor Author

@jatmn I have created multiple PRs as I was asked to.

@jatmn

jatmn commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

@jatmn I have created multiple PRs as I was asked to.

thank you!

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I found an issue that should be addressed before this is ready.

Findings

  • [P3] Preserve the response body when usage parsing fails
    src/services/api/openaiShim.ts:2739
    This now consumes every successful non-streaming response with await response.text() before the normal response conversion path gets to read it, but the response is only recreated after JSON.parse(bodyText) succeeds. If a provider returns a 2xx non-JSON body, or malformed JSON, the parse throws, the catch swallows it, and callers later see an already-consumed body. For example, the existing non-JSON fallback at src/services/api/openaiShim.ts:1923 can no longer include the provider's response text in the "unexpected response" error, whereas the old response.clone().json() path left the original body readable. Please recreate the Response after reading bodyText even when usage parsing fails, or keep using a clone for this diagnostic-only parse.

  • [P3] Split or reconcile the overlapping bundled fixes
    src/services/api/openaiShim.ts:2739
    This PR bundles several unrelated fixes and optimizations, but at least some of the same changes are also present in sibling PRs from this branch set: #1478 covers the response-clone optimization and lazy tool getter caching, #1476 covers the getMergedTools() dedupe, and #1479 covers the debugger stderr message. That makes it hard to tell which review path should be authoritative, and it raises the risk that a partial merge will either duplicate work or bring in an older version of a change that has been revised elsewhere. Please either narrow this PR to the changes that are not covered by the sibling PRs, or explicitly close/supersede the overlapping PRs so the implementation, PR description, and review target all line up.

@skyhighbg22-jpg

Copy link
Copy Markdown
Contributor Author

Superseded by focused PRs #1476 (bug fixes), #1477 (security), #1478 (performance), #1479 (DX), #1487 (type safety).

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