Skip to content

feat(db): persist r_compression and c_norm on distillations (schema v12)#116

Merged
BYK merged 1 commit intomainfrom
feat/distillation-metrics-db
May 2, 2026
Merged

feat(db): persist r_compression and c_norm on distillations (schema v12)#116
BYK merged 1 commit intomainfrom
feat/distillation-metrics-db

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 2, 2026

Summary

Persist r_compression and c_norm context health metrics directly in the distillations table, replacing the LORE_DEBUG=1-gated log lines that were invisible by default.

Why

The diagnostic logging added in #113 used log.info() which is suppressed unless LORE_DEBUG=1 — making the diagnostics effectively invisible in normal operation. Storing metrics in the DB makes them queryable retroactively without env vars or log parsing.

Changes

  • Schema v12: Two nullable REAL columns (r_compression, c_norm) on distillations
  • storeDistillation(): Accepts optional rCompression and cNorm params, writes to new columns
  • distillSegment(): Computes metrics before storeDistillation() (was after), passes them in
  • loadForSession() + loadGen0(): SQL and row types updated to include new columns
  • Distillation type: r_compression: number | null and c_norm: number | null
  • Tests: 3 new tests verifying NULL for legacy rows, correct values for new rows, mixed results
  • opencode test helper: restoreDistillationTables() updated for schema parity

Verification

  • 586 tests pass, 0 fail
  • Build clean across all 3 packages
  • Existing rows get NULL (no backfill needed)
  • Migration is two ALTER TABLE ADD COLUMN statements (idempotent for new DBs, safe for existing)

Store context health metrics directly in the distillations table so they
can be queried retroactively without LORE_DEBUG=1 log parsing.

- Migration v12: adds nullable r_compression REAL and c_norm REAL columns
- storeDistillation() accepts and persists both metrics
- distillSegment() computes metrics before storing (moved from post-store)
- loadForSession() and loadGen0() return the new fields
- Distillation type updated with nullable r_compression and c_norm
- Tests verify NULL for legacy rows, correct values for new rows
- opencode test helper restoreDistillationTables() updated for schema parity

586 tests pass, 0 fail. Build clean across all 3 packages.
@BYK BYK enabled auto-merge (squash) May 2, 2026 09:24
@BYK BYK merged commit 84df672 into main May 2, 2026
1 check passed
@BYK BYK deleted the feat/distillation-metrics-db branch May 2, 2026 09:24
@craft-deployer craft-deployer Bot mentioned this pull request May 2, 2026
5 tasks
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