Skip to content

traces: turn-level local spans — model calls (tokens/cache/errors) + tool calls, per-session JSONL - #106

Open
Rchari1 wants to merge 1 commit into
mainfrom
rchari/traces
Open

traces: turn-level local spans — model calls (tokens/cache/errors) + tool calls, per-session JSONL#106
Rchari1 wants to merge 1 commit into
mainfrom
rchari/traces

Conversation

@Rchari1

@Rchari1 Rchari1 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Turn-level traces, local-first (writer half; pairs with harmoniqs/opencode rchari/traces — the reader endpoint).

What

The amicode plugin now records every model call (provider/model, duration, tokens incl. cache read/write, error) and every tool call (name, args, duration, output size) as OTel-shaped spans, one JSONL per session in ~/.amico/amicode/traces/. Sources: the plugin event hook (assistant message.updated, deduped, emitted once on completion), chat.message (turn opens), and the tool.execute.before/after pair (real durations via callID pairing).

Privacy & safety

Local-only by design (chats are research IP). Secrets scrubbed at record time (same SECRET_RE discipline as the onboarding stream), attrs bounded (2KB strings, 32-entry collections), tool output stored as a length, not content. AMICODE_TRACES=0 kill switch; AMICODE_TRACE_DIR seam for tests. Recording is fully best-effort — telemetry can never break a session.

Envelope (the cross-repo contract — reader mirrors it)

{v:1, ts, session, span:"model"|"tool"|"turn", id, name, dur_ms|null, attrs, error|null} — append-only; readers skip malformed lines.

Day-zero finding (from the live verification)

One "hi" to the pulse-designer = 3 model calls (5.2s + 3.2s + 1.5s) + 2 tool calls — including a tool call named invalid (the model attempted a malformed call). Also corrected our own perf diagnosis: the zen DeepSeek tier DOES prompt-cache — call 1 pays the ~26k prefill, calls 2–3 read ~26k each from cache. The slow feel is first-call prefill × 3 round-trips × free-tier pace, not "no caching ever." This is exactly the class of insight the feature exists for.

Verification

7 new tests (writer, scrub, message-event mapping incl. the error-carrying case, tool pairing); full suite 443 green; live-verified end-to-end (chat turn → spans on disk → served by the fork endpoint).

🤖 Generated with Claude Code

…ery model call (tokens/cache/duration/error) and tool call (name/args/duration, secret-scrubbed, bounded) as OTel-shaped spans in ~/.amico/amicode/traces/<session>.jsonl; AMICODE_TRACES=0 kill switch, AMICODE_TRACE_DIR test seam + tests

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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