Skip to content

fix(analytics): accurate log/cost reporting and always-on cost display - #530

Open
8nevil8 wants to merge 4 commits into
mainfrom
fix/analytics-log-accuracy-and-cost-display
Open

fix(analytics): accurate log/cost reporting and always-on cost display#530
8nevil8 wants to merge 4 commits into
mainfrom
fix/analytics-log-accuracy-and-cost-display

Conversation

@8nevil8

@8nevil8 8nevil8 commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes three accuracy gaps in codemie analytics around which sessions count as having a usable native log, session duration, and cost visibility — plus a leaked test artifact cleanup.

Changes

  • hadLog correctness: loadAgentSessionFile now verifies the correlated/native transcript path still exists on disk before treating a session as hadLog=true. A coding agent's own retention (e.g. Claude Code's default 30-day cleanup) can rotate a transcript away after the session ran while the correlation record still names it — 122 of 291 real Claude sessions in one report were misreported this way.
  • Ownership marker scan window: hasOwnershipMarker's legacy-session scan widened from a 4KB/10-line budget to a 256KB byte-bounded scan. A SessionStart hook can inject a large hookAdditionalContext blob (CLAUDE.md, memory files, ...) as an early transcript line — observed up to ~100KB — pushing the ownership marker past the old limits and misclassifying 153 CodeMie-owned Claude sessions as native-external.
  • Active duration + always-on cost: sessions now surface CodeMie's own tracked activeDurationMs alongside the existing wall-clock duration (which counts idle/overnight gaps). Cost enrichment now always runs for the plain console command, not just --report, so Est. Cost and per-session Cost: lines are populated on every invocation. Also relabels the HTML report's "Files touched" stat to "File operations" to distinguish it from the report's unique-files-changed columns.
  • Test cleanup: the skills-setup integration test's Global scope installs into the real ~/.claude/skills/ (outside the temp CODEMIE_HOME the suite otherwise uses) and never cleaned that up — now removed in afterAll.

Testing

  • Unit/integration tests added for each fix (cost-enricher hadLog cases, native-loader scan-window cases)
  • npm run typecheck, lint, and secrets scan passed via pre-commit hooks on each commit

Checklist

  • Code follows project standards
  • CI is green (npm run ci)
  • No merge conflicts with main

8nevil8 and others added 4 commits September 3, 2026 19:33
…Log=true

The cost enricher's loadAgentSessionFile trusted a correlation record's
agentSessionFile path without checking it still exists. A coding agent's own
retention (e.g. Claude Code's default 30-day cleanup) can rotate a transcript
away long after the session ran; the correlation record still names it. 122 of
291 real Claude sessions in one report claimed hadLog=true against a deleted
file, misrepresenting the Coverage table's "Native log" count.

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
Claude-Session: https://claude.ai/code/session_0146TJLVz6A1KcRoGRMn3MJx
…tart payloads

hasOwnershipMarker's bounded transcript scan for legacy sessions without a
sidecar marker used a 4KB byte budget capped to the first 10 lines. A
SessionStart hook can inject a large hookAdditionalContext blob (CLAUDE.md,
memory files, ...) as one of the transcript's first lines — observed up to
~100KB on real sessions — pushing codemie_session_start past both limits.
153 CodeMie-owned Claude sessions were misreported as native-external for
exactly this reason. Scan is now 256KB, bounded by bytes read rather than
line count, since one large early line can consume most of a small budget
by itself.

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
Claude-Session: https://claude.ai/code/session_0146TJLVz6A1KcRoGRMn3MJx
Two related gaps in the plain console command (not --report):

- Session duration only showed the wall-clock span (endTime - startTime),
  which counts idle/overnight gaps and can overstate active work by an
  order of magnitude for a resumed session. Now also surfaces CodeMie's own
  tracked activeDurationMs when the session JSON carries it, labeled
  separately from the wall-clock span.
- Cost enrichment previously only ran when --report was passed, so the
  plain console command — the one most invocations use — never computed or
  displayed cost at all. It now always enriches from correlated logs when
  no source (OTEL) cost is present, and both `Est. Cost` and each session's
  `Cost:` line are populated on every path; --report reuses the same result
  rather than re-enriching.

Also relabels the HTML report's "Files touched" stat to "File operations"
to distinguish it from the report's separate unique-files-changed columns.

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
Claude-Session: https://claude.ai/code/session_0146TJLVz6A1KcRoGRMn3MJx
…tion test

The "setup skills" wizard's Global scope installs into the real
~/.claude/skills/ (claude-skill-generator.ts hardcodes os.homedir() there,
since .claude/ is Claude Code's own directory, not something CODEMIE_HOME
redirection reaches). That install escapes the temp CODEMIE_HOME used
elsewhere in this suite and was never cleaned up, leaking a skill dir into
the real user environment on every run. Removes it in afterAll by matching
the on-disk slug prefix (`${skillName}-${project}-global`) rather than
duplicating the exact slug algorithm.

Generated with AI

Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
Claude-Session: https://claude.ai/code/session_0146TJLVz6A1KcRoGRMn3MJx
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