Skip to content

refactor(core): drop unused session_pending table and pin the history compaction bound - #59020

Open
kitlangton wants to merge 1 commit into
devfrom
perf/history-bound
Open

kitlangton wants to merge 1 commit into
devfrom
perf/history-bound

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What it does

Adds tests that keep each step's history load bounded at the latest completed compaction, and drops the unused session_pending table. No runtime code changes.

Why

The history load already filters in SQL (seq >= <latest completed compaction>, on the (session_id, seq) index), but no test covered that bound. If it regressed to reading everything and filtering in memory, the cost per step would grow with the whole session (in-memory SQLite, 20 rows after the compaction, mean of 20 loads):

Rows before compaction Today (bounded in SQL) If it regressed
1,000 0.15 ms, 21 rows read 2.1 ms, 1,021 rows decoded
10,000 0.08 ms, 21 rows read 13 ms, 10,021 rows decoded

session_pending has had no reader or writer since session_inbox replaced it in August.

How it works

  • Parity test: the model input from SessionHistory.load matches the full transcript cut at the latest completed compaction, for no compaction, one, several, and a failed compaction after a completed one.
  • Guard test: rows before the compaction (and before a summary's kept tail) are made undecodable. The load still returns the summary, its rebuilt recent text and the tail. With the bound removed, this test fails.
  • A generated migration drops session_pending and its three indexes (IF EXISTS).

Risk

Low. Dropping session_pending deletes stale rows left from before session_inbox; nothing reads them on dev or beta.

Proof

session-compaction.test.ts and database-migration.test.ts pass (48 tests). Core typecheck and oxlint are clean.

… compaction bound

History already reads session_message from the latest completed compaction (seq >= boundary) in SQL. Add a parity test against the full transcript cut at that compaction (none, one, several, failed) and a guard test that makes earlier rows undecodable, so a regression to reading them fails. Drop session_pending, which nothing reads or writes since session_inbox replaced it.

@opencode-agent opencode-agent 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.

No problems found; the change is sound. The migration tests and compaction tests pass (49 tests), and tsc -b on core is clean (the typecheck script needs a newer Bun than this environment has). With the seq >= compaction.seq bound removed from SessionHistory, the two new tests fail, so the bound is pinned as described. No code outside historical migrations references session_pending, and the IF EXISTS drops are safe for fresh databases, which no longer create the table.

Public API is unchanged: this only touches the internal SQLite schema and its drizzle snapshot.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant