Skip to content

Configurable local retention, shorter for session events - #2478

Open
cbsmith wants to merge 4 commits into
git-ai-project:mainfrom
crexi:crexi/metrics-retention
Open

cbsmith wants to merge 4 commits into
git-ai-project:mainfrom
crexi:crexi/metrics-retention

Conversation

@cbsmith

@cbsmith cbsmith commented Nov 8, 2026 •

Copy link
Copy Markdown

Problem

The local metrics database (~/.git-ai/internal/metrics-db) keeps every event for a hard-coded 365 days (METRICS_RETENTION_SECS). When no API key or login is configured nothing is ever uploaded, so the outbox only grows. Streamed transcript lines (SessionEvent, event id 5) dominate: on our machines they are 70–80 % of the bytes. One workstation reached 23 GB; another grew 4.6 GB in seven weeks.

The daemon only reads SessionEvent rows within SESSION_EVENT_RECOVERY_WINDOW_NS (3 s) of a file's mtime at commit time, plus the "latest event for a tool" fallback, and the transcript sweep itself looks back transcript_streaming_lookback_days (7). Keeping those rows for a year serves nothing locally. telemetry_oss off does not help: it only disables Sentry/PostHog.

Related: #1678 (closed) proposed a 512 MB file cap that would also stop checkpoint and commit events from being recorded; #1765; #2244.

Change

Two settings, both consumed by the existing daily prune_old_metrics_if_due:

key default scope
metrics_retention_days 365 every event kind
session_event_retention_days metrics_retention_days SessionEvent rows only; clamped so it never exceeds the general value
  • Env overrides GIT_AI_METRICS_RETENTION_DAYS / GIT_AI_SESSION_EVENT_RETENTION_DAYS, git-ai config set|unset|<key>, test config patch, config --help, and the restart notice.
  • 0 or unparsable values fall back to the default with a warning (unlike transcript_streaming_lookback_days, where 0 means unlimited, deleting everything is never a sensible reading of 0 here).
  • The prune now selects event_kind and applies the per-kind cutoff; rows with no kind use the general cutoff.
  • git-ai usage --help reports the effective values.
  • Defaults leave current behaviour unchanged.

Not included: VACUUM. Freed pages are reused, so the file stops growing at the new steady state but does not shrink until a manual VACUUM.

Tests

  • config: defaults, env override, clamp (session ≤ general), zero falls back.
  • metrics::db: prune_old_metrics_with_cutoffs removes only SessionEvent rows past the session cutoff while keeping same-age rows of other kinds, and records metrics_last_prune_ts.
  • Existing prune tests unchanged and green. cargo fmt, cargo clippy --all-targets -D warnings clean.
  • Running on two workstations since 2026-11-07 with session_event_retention_days 7: the daily prune removed only SessionEvent rows older than the cutoff and left every other kind in place.

Devin Review

@CLAassistant

CLAassistant commented Nov 8, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

Devin Review

Comment thread src/metrics/db.rs Resolved
Comment thread src/commands/config.rs Resolved
cbsmith and others added 4 commits November 8, 2026 17:19
…event rows

Red step. Adds failing tests for two new settings:
- metrics_retention_days (default 365, 0 falls back to the default)
- session_event_retention_days (defaults to metrics_retention_days and can
  never exceed it)
and for a prune entry point that takes explicit per-kind cutoffs so the
daemon's daily prune can age SessionEvent rows faster than other kinds.

Co-Authored-By: Claude <[email protected]>
The local metrics database kept every event for a hard-coded 365 days.
With no API key or login nothing is ever uploaded, so streamed transcript
lines (SessionEvent rows) accumulate for a year even though the daemon only
consults them within seconds of a file's mtime at commit time and the
transcript sweep looks back 7 days. One machine here reached 23 GB.

Adds two settings, both read by the existing daily prune:

- metrics_retention_days (default 365): retention for every event kind.
- session_event_retention_days (default: metrics_retention_days): retention
  for SessionEvent rows only, clamped so it never exceeds the general value.

Both accept GIT_AI_METRICS_RETENTION_DAYS / GIT_AI_SESSION_EVENT_RETENTION_DAYS
env overrides, `git-ai config set/unset/get`, and the test config patch.
Zero or unparsable values fall back to the default with a warning. Defaults
leave current behaviour unchanged.

Verified with `task format:check lint doc` and the config/metrics prune
tests. Committed with --no-verify because lefthook's hook needs `task` on
PATH and the dev shell's git wrapper does not run on NixOS.

Co-Authored-By: Claude <[email protected]>
…ion CLI

- prune: a SessionEvent row with no cached event_kind must still use the
  session cutoff
- config unset must print the daemon restart notice for both retention keys
- TestRepo coverage for metrics_retention_days and
  session_event_retention_days: defaults, set/get, clamp, env override,
  rejected values, show-all, unset; the coverage fixture populates both
  fields so the get/unset guards include them

Co-Authored-By: Claude <[email protected]>
…notice on unset

Rows written before the cached metadata columns existed have no
event_kind until the backfill reaches them, so the prune now reads the
kind from the JSON for those rows, sharing the extractor with the
metadata backfill. config unset prints the daemon restart notice for
both retention keys, matching set.

Co-Authored-By: Claude <[email protected]>
@cbsmith
cbsmith force-pushed the crexi/metrics-retention branch from cc5c391 to d44a32e Compare November 9, 2026 07:21

This branch has not been deployed

No deployments
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.

2 participants