Skip to content

[codex] Fix hook flush overhead#26

Merged
jverre merged 1 commit into
mainfrom
codex/hook-performance-cleanup
Jun 12, 2026
Merged

[codex] Fix hook flush overhead#26
jverre merged 1 commit into
mainfrom
codex/hook-performance-cleanup

Conversation

@jverre

@jverre jverre commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Skip synchronous context snapshot construction when a flush batch contains only tool spans, avoiding full-transcript and filesystem scans that cannot be attached to any LLM usage span.
  • Reuse the already-read turn transcript when computing close-out edit metrics, removing one duplicate transcript pass on Stop/SessionEnd.
  • Treat non-2xx count_tokens responses as errors so the detached measurement pass does not cache zero-token anchors from auth/rate-limit/error payloads.

Review notes

Recent changes added useful billing and attribution detail, but the hook hot path had one avoidable cost: flush always called buildContextSnapshot, even for tool-only batches. That helper reads the full transcript and hits memory/agent/skill/tool extractors; doing that during ordinary tool hook flushes slows Claude Code without adding metadata because only spans with usage receive the snapshot.

I did not include the local bin/opik-logger-darwin-arm64 modification in this PR; it was already dirty before the source edits and looks like a local build artifact.

Validation

  • go test ./...
  • go vet ./...
  • git diff --check

@jverre jverre marked this pull request as ready for review June 12, 2026 12:06
@jverre jverre merged commit 1d95c60 into main Jun 12, 2026
1 check passed
@jverre jverre deleted the codex/hook-performance-cleanup branch June 12, 2026 21:15
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