Skip to content

refactor(backends): extract shared LLM call logging helper#833

Merged
aaight merged 1 commit intodevfrom
feature/shared-llm-call-logger
Mar 14, 2026
Merged

refactor(backends): extract shared LLM call logging helper#833
aaight merged 1 commit intodevfrom
feature/shared-llm-call-logger

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 14, 2026

Summary

  • Extracts the duplicated storeLlmCall wrapper pattern from all three native-tool engines (Claude Code, Codex, OpenCode) into a shared logLlmCall() helper at src/backends/shared/llmCallLogger.ts
  • The helper guards on runId (no-op when absent), fires storeLlmCall asynchronously, and catches/logs any storage errors using a per-engine label
  • Each engine now uses the shared helper instead of maintaining its own inline wrapper

Changes

  • src/backends/shared/llmCallLogger.ts (new): logLlmCall() helper accepting runId, callNumber, model, optional token counts, optional costUsd, optional response, and an engineLabel for error messages
  • src/backends/claude-code/index.ts: replaced inline logLlmCall() function with shared helper call; renamed local function to logClaudeCodeLlmCall to avoid naming collision
  • src/backends/codex/index.ts: replaced storeLlmCall call inside trackUsage() with shared helper; removed unused logger import
  • src/backends/opencode/index.ts: replaced async storeUsage() function with synchronous call to shared helper; cleaned up now-redundant .catch() at call site
  • tests/unit/backends/shared-llmCallLogger.test.ts (new): 9 unit tests covering guard-on-runId, fire-and-forget behaviour, and error-catch logging with engine label

Test plan

  • npm run typecheck passes (zero errors)
  • npm run lint passes (zero errors)
  • New unit tests pass (shared-llmCallLogger.test.ts — 9 tests)
  • Full backend unit test suite passes (554 tests across 27 files)

Trello card: https://trello.com/c/69b572d0893fa82bfa5c6dd8

🤖 Generated with Claude Code

🕵️ claude-code · claude-sonnet-4-6 · run details

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

LGTM - the shared logLlmCall() extraction preserves the existing storage contract and engine behavior while removing duplicated fire-and-forget error handling. I verified the new helper test, the affected backend unit suites, and npm run typecheck locally with no regressions.

🕵️ codex · gpt-5.4 · run details

@aaight aaight merged commit eaa7165 into dev Mar 14, 2026
6 checks passed
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