Skip to content

Cap usage.jsonl in scopes that never report #788

Description

@SaulMoro

Parent

#752 (item 3)

What to build

usage.jsonl stops growing in scopes that never report: http sources, usageReport: false, or a remote that rejects every push. Dropping events when they are written would empty teamai stats for those scopes, since the local file is their only source. So pull caps the file instead, keeping the newest 5,000 events.

Where the cap runs is the whole design. The report deletes the first N lines, N being how many events it read. A cap applied in between would shift those lines, and the report would delete events it never sent (the #750 failure):

pull, scope S, holding S's sync lock
  events = read usage.jsonl
  report(events)?          ← only for scopes that report
  truncate first N lines   ← N = events reported
  cap to newest 5,000      ← after the truncate, never between read and truncate

A hook never compacts. pull runs at every session start, including for the scopes that never report, so the cap reaches them all.

Acceptance criteria

  • An http scope and a usageReport: false scope with more than 5,000 events hold 5,000 after a pull, and teamai stats still shows their newest usage.
  • A reporting scope over the cap loses no unreported event: everything written after the report's read is still there after the pull.
  • Below the cap, the file is not rewritten.
  • Verified with the real CLI (Claude, git provider); usage guide section on usage reporting (both languages) and CHANGELOG updated.

Blocked by

None (can start immediately).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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