Repository navigation
Conversation
…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
force-pushed
the
crexi/metrics-retention
branch
from
November 9, 2026 07:21
cc5c391 to
d44a32e
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SessionEventrows withinSESSION_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 backtranscript_streaming_lookback_days(7). Keeping those rows for a year serves nothing locally.telemetry_oss offdoes 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:metrics_retention_dayssession_event_retention_daysmetrics_retention_daysSessionEventrows only; clamped so it never exceeds the general valueGIT_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.0or unparsable values fall back to the default with a warning (unliketranscript_streaming_lookback_days, where 0 means unlimited, deleting everything is never a sensible reading of 0 here).event_kindand applies the per-kind cutoff; rows with no kind use the general cutoff.git-ai usage --helpreports the effective values.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_cutoffsremoves onlySessionEventrows past the session cutoff while keeping same-age rows of other kinds, and recordsmetrics_last_prune_ts.cargo fmt,cargo clippy --all-targets -D warningsclean.session_event_retention_days 7: the daily prune removed onlySessionEventrows older than the cutoff and left every other kind in place.