Skip to content

perf: accept optional storage in getUsableFallbackAccounts to avoid redundant disk reads#15

Closed
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:fix/pi-convert-guards
Closed

perf: accept optional storage in getUsableFallbackAccounts to avoid redundant disk reads#15
iceteaSA wants to merge 1 commit into
cortexkit:mainfrom
iceteaSA:fix/pi-convert-guards

Conversation

@iceteaSA
Copy link
Copy Markdown

Summary

Adds an optional existingStorage parameter to FallbackAccountManager.getUsableFallbackAccounts(). Callers that already have storage loaded (e.g., the fetch handler which loads it at the start of every request) can pass it through to skip a redundant readFile + JSON.parse.

In the hot request path, loadAccounts() currently fires up to 3 times per request:

  1. In the main fetch handler
  2. Inside tryFallbackAccounts()
  3. Inside getUsableFallbackAccounts()

This change eliminates #3 when the caller provides storage.

API Change

// Before
async getUsableFallbackAccounts(): Promise<OAuthAccount[]>

// After (non-breaking)
async getUsableFallbackAccounts(existingStorage?: AccountStorage | null): Promise<OAuthAccount[]>

Uses !== undefined check (not falsy) because null is a valid "no storage file" state.

Testing

All existing tests pass. No behavior change — only avoids redundant disk I/O.

…tool IDs

- Add sanitizeToolId() to strip chars outside [a-zA-Z0-9_-] from
  tool-call IDs, preventing Anthropic 400 errors from cross-provider
  ID incompatibility
- Guard empty base64 image data to prevent invalid payloads
- Inject fallback content for is_error=true tool_results with empty
  content, which Anthropic rejects
@iceteaSA
Copy link
Copy Markdown
Author

Closing — wrong branch mapping, will resubmit.

@iceteaSA iceteaSA closed this May 17, 2026
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.

1 participant