Skip to content

[Rust port] relayburn-analyze: overhead attribution (1e-9 USD precision gate) #276

@willwashburn

Description

@willwashburn

Parent: #244
Depends on: #242, #266 (foundation)

Context

Overhead attribution is the surface added in #236: it answers "how much of this session's spend went to system overhead (CLAUDE.md / AGENTS.md context loaded into every prompt) vs actual user-asked work?" Small in source LoC (~122) but it's the fresh divergence-risk surface called out in #244's acceptance: per-file, per-section USD totals must match TS within 1e-9 USD.

This is a leaf module — it doesn't compose other detectors — so it can land independently of the other sub-issues, in parallel with the detector PRs.

Scope

overhead.rs (port of overhead.ts, ~122 LoC)

  • Port OverheadFileKind (claude-md | agents-md), OverheadHarness (claude-code | codex | opencode).
  • Port the full attribution type tree:
    • OverheadFile, ParsedOverheadFile, OverheadFileAttribution, OverheadAttribution, AttributeOverheadInput (already enumerated in [Rust port] relayburn-analyze: pricing, hotspots, overhead #244's scope).
    • OverheadResult, OverheadSection, OverheadFileSummary, OverheadPerFileEntry, OverheadAttributionDetail, OverheadSectionCost, OverheadTrimResult, OverheadTrimRecommendation.
  • Port findOverheadFiles(projectPath) — discovers CLAUDE.md and AGENTS.md files across the project tree, including parent directories and .claude/ / .codex/ subdirs.
  • Port loadOverheadFile(file) — reads + parses a single overhead file via the shared markdown parser (reuse parseClaudeMd from [Rust port] relayburn-analyze: subagent-tree + claude-md attribution #272's claude_md.rs).
  • Port attributeOverhead(input) — the 1e-9-precision-sensitive core. Computes per-section USD attribution by weighting input-token cost by section token share.
  • Port describeAppliesTo(applies_to) — returns the human-readable label ("Claude Code only", "Codex + OpenCode", etc.).
  • Port overheadTrim() if exported (check index.ts re-exports — surface lives in this module per the parent issue scope).

Precision contract

The 1e-9 USD gate is the headline acceptance criterion of #244. Concretely:

  • Use f64 arithmetic, same operation order as TS (token-share × per-token rate, summed in section-iteration order).
  • Section iteration must be deterministic: order by (file_path, section_index) ascending — match TS sort key exactly.
  • Avoid intermediate rounding. Round only at the serialization boundary if the consumer requests a fixed precision; the in-memory f64 carries the full double precision.
  • A regression test computes overhead for a multi-file fixture corpus and asserts (rust_total_usd - ts_total_usd).abs() < 1e-9 per (file, section) pair.

Conformance gate

  • packages/analyze/src/overhead.test.ts (230 lines).

Acceptance

  • cargo test -p relayburn-analyze green for overhead.
  • Public surface: attributeOverhead, describeAppliesTo, findOverheadFiles, loadOverheadFile, plus the full attribution type tree listed above.
  • 1e-9 USD precision gate verified against the TS fixture corpus (per-file, per-section).
  • findOverheadFiles traversal order deterministic and matches TS (BFS by directory depth, alphabetical within depth).

Files

  • packages/analyze/src/overhead.ts + overhead.test.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions