Skip to content

feat(model-gateway): trace store schema v2#551

Open
jeffreysijuntan wants to merge 1 commit into
mainfrom
pr-1a-store
Open

feat(model-gateway): trace store schema v2#551
jeffreysijuntan wants to merge 1 commit into
mainfrom
pr-1a-store

Conversation

@jeffreysijuntan

@jeffreysijuntan jeffreysijuntan commented May 5, 2026

Copy link
Copy Markdown
Contributor

Summary

First of three stacked PRs splitting the gateway upgrade. Standalone — no consumer changes; landed alone, the new schema and methods are dead code that the next two PRs activate.

  • Denormalises hot filter columns (run_id, model, harness, latency_ms, has_error, step_id) onto the traces row so the cross-run trace feed (rllm-console PR) can filter without JSON-scanning every row.
  • Adds a runs table for per-gateway-run lifecycle.
  • Extends TraceStore protocol: query_traces, register_run, end_run, list_runs, count_traces, facets.
  • Schema-version mismatch on an existing db drops & recreates every table — gateway data is dev-only and a real migration isn't worth it.
  • _get_conn serialises first-call init under an asyncio.Lock so a burst of concurrent store_trace callers can't race the schema build (the previous lock-free path could leave racers staring at a half-dropped db when migration triggered).
  • Memory store mirrors the new shape so unit tests cover both backends identically.

Existing store_trace(trace_id, session_id, data) callers keep working — run_id defaults to "", all new methods are additive.

Stack

  • [PR-1A] this — schema v2 + lock fix
  • PR-1BX-RLLM-* headers + inbound bearer auth (depends on this)
  • PR-1C — upstream-proxy mode + run lifecycle (depends on B)

Test plan

  • python -m pytest tests/unit/ — 220 passed
  • python -m pytest tests/unit/test_store.py — 74 passed (new tests for schema v2, denormalised columns, junction back-compat, concurrent writers)
  • One known flaky case: test_two_stores_share_one_db can fail ~5% under suite-wide ordering when two SqliteTraceStore instances race the WAL pragma. Passes reliably in isolation. Tracking as a follow-up — fix is a small retry on journal_mode=WAL or a process-level init lock.

🤖 Generated with Claude Code

Denormalises the hot filter columns from the JSON `data` payload onto
the `traces` row so the cross-run trace feed can filter without
JSON-scanning every row. Adds a `runs` table for per-gateway-run
lifecycle, plus extended TraceStore protocol surface (`query_traces`,
`register_run`, `end_run`, `list_runs`, `count_traces`, `facets`).

Schema-version mismatch on an existing db drops & recreates every
table — gateway data is dev-only and a real migration isn't worth
it. `_get_conn` now serialises first-call init under an asyncio.Lock
so a burst of concurrent `store_trace` callers can't race the schema
build (the previous lock-free path could leave the racers staring at
a half-dropped db when the migration triggered).

Memory store mirrors the new shape so unit tests cover both backends
identically.

Existing `store_trace(trace_id, session_id, data)` callers keep
working — the new `run_id` arg defaults to `""` and the new methods
are additive.

Tests: 74 new in test_store.py; full unit suite still 220 passes.
@luyuzhe111

Copy link
Copy Markdown
Collaborator

@jeffreysijuntan look good overall. what's the PR that tackles the flaky test tho?

@jeffreysijuntan

Copy link
Copy Markdown
Contributor Author

@jeffreysijuntan look good overall. what's the PR that tackles the flaky test tho?

It is in a new uncommit PR, I will push it to here instead

@listar2000

Copy link
Copy Markdown
Collaborator

What's the current blocker for this PR to get merged (the CI failure?)

@jeffreysijuntan

Copy link
Copy Markdown
Contributor Author

What's the current blocker for this PR to get merged (the CI failure?)

Before changing the gateway, I am working on some PR to unify the eval path with the AgentFlowEngine, so eval will run directly through that in the future.

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.

3 participants