offload-scan: caveat reconstructed invocation counts as a lower bound #18
Reference in New Issue
Block a user
Delete Branch "fix/issue-12-invocation-caveat"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes kotkan/claude-plugin-inference-arbitrage#12
Root cause
Investigated the filed hypothesis (sidechain/session-wide activity leaking into per-invocation figures) and ruled it out: turn attribution in
bin/offload-scan'sminecheck (L401-421) is correct — only turns whoseattributionPlugin/Agent/Skillmatch the target plugin enterturns. Hand-verified against a real 1385-turn transcript; all 31 attributedanxious:agent-wipturns areisSidechain:Falseand correctly tagged.The real, narrower defect is in
reconstruct_invocations()(L523-545, unchanged since Phase 3): it splits invocations only on group-change or a >10-minute wall-clock gap between already-attributed turns. It has no signal for unrelated intervening activity (which never entersturnsat all), so two genuinely separate same-skill calls that happen to land within the idle-gap window of each other get merged into one reported invocation. In the real sample, 31 turns (~3x the skill's expected step count) fell within max 4.3-minute gaps and were merged into a single reported invocation, consistent with 3 real calls being collapsed into 1.This inflates the headline "weighted_tokens per invocation" figure quoted in filed issue bodies, without affecting the correctly-computed group totals (
weighted_tokens,offload_value,share_of_audited_spend).Note: the other component that makes per-invocation figures look large —
cc-tokenscounting fullcache_read/cache_writeper turn — is intentional perdesign/spec.md§1.1/§5.2.1 and not a bug.Fix
Rather than add a new splitting heuristic (no ground-truth invocation-start marker exists in transcripts, so any heuristic risks new false splits/merges), this adds an explicit caveat to the emitted data so downstream consumers don't overstate confidence in the per-invocation figure:
bin/offload-scan:totals.invocation_caveatin the JSON output, naming the idle-gap threshold.bin/audit-snapshot: threadsinvocation_caveatthroughbuild_snapshot's totals and renders it as a note bullet in the per-run issue-body template (render_run).Tests
tests/scan.test.sh: assertstotals.invocation_caveatmentions "lower bound" and the configured idle-gap ("10 minutes").tests/snapshot.test.sh: asserts the caveat propagates from a scan doc into snapshot totals and renders into the audit page markdown.Full suite run:
for f in tests/*.test.sh; do bash "$f"; done— all suites pass (classify, filing, inventory, memory, scan, snapshot, stability).Version bumped 0.6.2 -> 0.6.3 (patch, per plugin-version convention).