-
Notifications
You must be signed in to change notification settings - Fork 91
fix: recover stale context limits after model switches #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coleleavitt
wants to merge
8
commits into
cortexkit:master
Choose a base branch
from
coleleavitt:fix/context-limit-first-sample
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fdc66ff
fix(plugin): trust successful context usage samples
coleleavitt 7eff875
fix(plugin): preserve tokenless response timing
coleleavitt ce09be2
fix(plugin): keep prompt bounds out of cache geometry
coleleavitt 2d610d5
fix(plugin): preserve overflow state across model switches
coleleavitt f4f6b55
fix(plugin): preserve legacy usage timestamps
coleleavitt 6a5e30d
fix(plugin): guard legacy usage backfill
coleleavitt af22bd4
test(plugin): support stacked schema fences
coleleavitt 8549d11
fix(plugin): restore usage before tokenless refresh
coleleavitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
79 changes: 79 additions & 0 deletions
79
packages/plugin/src/features/magic-context/migrations-v80.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /// <reference types="bun-types" /> | ||
|
|
||
| import { describe, expect, test } from "bun:test"; | ||
| import { Database } from "../../shared/sqlite"; | ||
| import { closeQuietly } from "../../shared/sqlite-helpers"; | ||
| import { LATEST_MIGRATION_VERSION, runMigrations } from "./migrations"; | ||
| import { initializeDatabase, LATEST_SUPPORTED_VERSION } from "./storage-db"; | ||
|
|
||
| function seedAppliedVersion(db: Database, version: number): void { | ||
| db.exec(` | ||
| CREATE TABLE schema_migrations ( | ||
| version INTEGER PRIMARY KEY, | ||
| description TEXT NOT NULL, | ||
| applied_at INTEGER NOT NULL | ||
| ); | ||
| `); | ||
| const insert = db.prepare( | ||
| "INSERT INTO schema_migrations (version, description, applied_at) VALUES (?, ?, ?)", | ||
| ); | ||
| for (let current = 1; current <= version; current += 1) { | ||
| insert.run(current, `seed v${current}`, Date.now()); | ||
| } | ||
| } | ||
|
|
||
| function columnNames(db: Database, table: string): string[] { | ||
| return (db.prepare(`PRAGMA table_info(${table})`).all() as Array<{ name: string }>).map( | ||
| (column) => column.name, | ||
| ); | ||
| } | ||
|
|
||
| describe("migration v80: tokenless usage observation timestamp", () => { | ||
| test("fresh databases include the timestamp and align the schema fence", () => { | ||
| const db = new Database(":memory:"); | ||
| try { | ||
| initializeDatabase(db); | ||
| runMigrations(db); | ||
|
|
||
| expect(columnNames(db, "session_meta")).toContain("last_usage_observed_at"); | ||
| expect(LATEST_SUPPORTED_VERSION).toBe(80); | ||
| expect(LATEST_SUPPORTED_VERSION).toBe(LATEST_MIGRATION_VERSION); | ||
| } finally { | ||
| closeQuietly(db); | ||
| } | ||
| }); | ||
|
|
||
| test("replaying from v79 preserves the observation time for legacy token usage", () => { | ||
| const db = new Database(":memory:"); | ||
| try { | ||
| seedAppliedVersion(db, 79); | ||
| db.exec(` | ||
| CREATE TABLE session_meta ( | ||
| session_id TEXT PRIMARY KEY, | ||
| last_context_percentage REAL DEFAULT 0, | ||
| last_input_tokens INTEGER DEFAULT 0, | ||
| last_response_time INTEGER | ||
| ); | ||
| INSERT INTO session_meta ( | ||
| session_id, last_context_percentage, last_input_tokens, last_response_time | ||
| ) VALUES ('ses-legacy', 50, 50000, 123); | ||
| `); | ||
|
|
||
| runMigrations(db); | ||
| runMigrations(db); | ||
|
|
||
| expect( | ||
| db | ||
| .prepare("SELECT last_usage_observed_at FROM session_meta WHERE session_id = ?") | ||
| .get("ses-legacy"), | ||
| ).toEqual({ last_usage_observed_at: 123 }); | ||
| expect( | ||
| db | ||
| .prepare("SELECT COUNT(*) AS count FROM schema_migrations WHERE version = 80") | ||
| .get(), | ||
| ).toEqual({ count: 1 }); | ||
| } finally { | ||
| closeQuietly(db); | ||
| } | ||
| }); | ||
| }); |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: When this PR is applied before PR #340, v80 becomes the high-water mark and the later v79 migration is skipped permanently. Land v79 first, or change migration selection to support out-of-order pending versions.
Prompt for AI agents