Skip to content

Fix: write trace domain snapshots even outside a git work tree - #16

Merged
collincunn merged 1 commit into
mainfrom
collinc/post-trace-metrics-decouple-from-git
Jun 8, 2026
Merged

Fix: write trace domain snapshots even outside a git work tree#16
collincunn merged 1 commit into
mainfrom
collinc/post-trace-metrics-decouple-from-git

Conversation

@collincunn

Copy link
Copy Markdown
Contributor

Summary

postTraceMetrics writes the trace-level cc.<domain> blocks (skills, tools, memory, thinking, tool_results, user_prompts, file_attachments, prior_assistant, assistant_text) for every closing trace. It also writes a cc.git block when the current working directory is a git work tree. Today the function bails out entirely if cwd is not a git work tree, dropping all nine domain snapshots even though none of them touch git.

Repro

Launch Claude Code from a non-repo parent directory (e.g. `~/code` used as a holder for many sibling repos). Send any prompt with tracing enabled. The resulting Opik trace shows:

  • ✅ `cc.identity` (written by `identity.applyToTrace` at trace creation)
  • ✅ per-span `cc.llm_call` (written in the span loop)
  • ❌ `cc.skills`, `cc.tools`, `cc.memory`, … (missing — `postTraceMetrics` returned at the git check)

Debug log signature: `postTraceMetrics: is not a git work tree`

Fix

Move the git work-tree check inline so it gates only the git block. Domain snapshots always run; the final PATCH is skipped only when both produced nothing.

Test plan

  • Verified locally: ran CC from `/Users/collinc/code` (non-git), confirmed the closing trace now carries `cc.skills` and `cc.tools` alongside `cc.identity` — git block correctly absent
  • `go vet ./src` clean
  • Existing unit tests pass (`go test ./src/...`)
  • Sanity-check inside a real repo to confirm git block still writes when available

🤖 Generated with Claude Code

Move the git work-tree check from the function entry to gating just the
git block. Domain snapshots (skills, tools, memory, thinking,
tool_results, user_prompts, file_attachments, prior_assistant,
assistant_text) read transcript entries and filesystem state — never git
— so dropping them whenever cwd isn't a git work tree was an over-broad
bail.

Concrete symptom this fixes: launching CC from a non-repo parent
directory (e.g. ~/code as a holder for many repos) produced traces with
cc.identity and per-span cc.llm_call only — every cc.<domain> on the
trace was missing because postTraceMetrics returned at the git check
before reaching the domain loop.

After: git block writes when available, domains always write, and the
final PATCH is skipped only when both produced nothing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@collincunn
collincunn merged commit ef5db98 into main Jun 8, 2026
1 check passed
@jverre
jverre deleted the collinc/post-trace-metrics-decouple-from-git 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