Skip to content

fix: metrics wait for their session row instead of racing it to a 409 (GIT-73) - #42

Merged
2 commits merged into
mainfrom
bugfix/GIT-73-metrics-fk-race
Sep 22, 2026
Merged

2 commits merged into
mainfrom
bugfix/GIT-73-metrics-fk-race

Conversation

@nTEG-dev

Copy link
Copy Markdown
Member

What

Metrics writes wait for their session row instead of racing it to a 409 (GIT-73).

  • session_start registers its fire-and-forget session insert with registerPendingSessionRow().
  • recordMetrics waits for that insert, bounded at 15 s, before writing any row that references the session. That covers session_start's own metrics and anything recorded right after it, e.g. recall.
  • If the session row didn't land, or didn't within the budget, the metrics row is written with session_id: null and keeps the id in metadata.session_id. That's where session_close already looks for it (GIT-109), so the row is kept instead of lost to a 409.
  • Sessions this process didn't create (resumed, or another process's) are written immediately, as before.
  • session_start itself still doesn't wait: the session insert stays fire-and-forget, and only the metrics write is sequenced after it.

Why

gitmem_query_metrics.session_id references gitmem_sessions(id). session_start sent the session insert and its metrics insert at the same moment, so whichever reached the store first decided whether the metrics insert failed with 409 (FK violation).

How to test

Venue (v1.8.0 setup.sql, vujndhcumgroztfkkdus; production not touched). GIT-73 is removed from the driver's EXPECTED_FAILURES, so any 409 now fails the run. Ten flow runs each:

origin/main 1.10.0 This branch
Runs with a 409 on gitmem_query_metrics 7 / 10 (exit 1) 0 / 10 (exit 0)
409s total 7 0
for i in $(seq 10); do VENUE_ENV=<env> node tests/e2e/blank-supabase.mjs flow --label git73-r$i --out <dir>; done

Unit tests: 1279/1279 pass (+5, metrics-session-fk.test.ts):

  • the write is held until the session row lands, then keeps the FK;
  • a row that didn't land → session_id: null, id in metadata.session_id;
  • creation threw → treated as not landed;
  • later writes reuse the settled answer;
  • an unregistered session is written immediately.

No existing test encoded the old behaviour.

Checklist

  • npm run test:unit passes (1279)
  • New tests added
  • No schema change; verified on a v1.8.0 store, 10 runs
  • Docs: n/a

Breaking changes

None.

🤖 Generated with Claude Code

Claude and others added 2 commits September 21, 2026 20:41
… (GIT-73)

session_start created its session row fire-and-forget and recorded its
metrics at the same moment. gitmem_query_metrics.session_id references
gitmem_sessions(id), so whichever request reached the store first decided
whether the metrics insert failed with 409 (FK). recall right after
session_start raced the same way.

- session_start registers the pending session insert; recordMetrics waits for
  it (bounded at 15 s) before writing a row that references that session.
- If the session row did not land, the metrics row is written without the FK
  and keeps the id in metadata.session_id, where session_close already reads
  it (GIT-109), instead of being lost.
- Sessions this process did not create (resumed, another process's) are
  written immediately, as before.

+5 tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A 409 from gitmem_query_metrics now fails the run. 10 flow runs on the v1.8.0
schema with the fix: 0 409s.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@nTEG-dev nTEG-dev closed this pull request by merging all changes into main in f93c3a3 Sep 22, 2026
neoneye pushed a commit to agent-memory-atlas-archive/gitmem-dev--gitmem that referenced this pull request Sep 22, 2026
Conflicts (blank-supabase.mjs):
- EXPECTED_FAILURES: gitmem-dev#42 removed GIT-73 and gitmem-dev#44 removed GIT-105; both
  removals kept, so the list is empty.
- all result fields and all checks kept.
tsc clean.
@nTEG-dev
nTEG-dev deleted the bugfix/GIT-73-metrics-fk-race branch September 23, 2026 05:49
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.

1 participant