Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/plugins/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"plugins": [
{
"name": "billion-context",
"version": "0.1.213",
"version": "0.1.214",
"source": {
"source": "local",
"path": "./plugins/codex"
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"name": "billion-context",
"source": "./",
"description": "Context-compression plugin for Claude Code · month-long single sessions (billions of tokens) · high compression quality even in small context windows (100K is enough) · 5× fewer tokens",
"version": "0.1.213",
"version": "0.1.214",
"author": {
"name": "ranxianglei"
},
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "billion-context",
"version": "0.1.213",
"version": "0.1.214",
"description": "Context-compression plugin for Claude Code · month-long single sessions (billions of tokens) · high compression quality even in small context windows (100K is enough) · 5× fewer tokens",
"author": {
"name": "ranxianglei"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "billion-context",
"version": "0.1.213",
"version": "0.1.214",
"description": "A context-compression plugin \u2014 small context windows (a 100K context is enough), 5x fewer tokens, month-long single sessions (billions of tokens), and compression quality \u2014 for all agents: pi, OpenCode, Codex, Claude Code, and more. billion-context is all you need.",
"type": "module",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion plugins/codex/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "billion-context",
"version": "0.1.213",
"version": "0.1.214",
"description": "Context-compression plugin for Codex — small context windows (100K is enough), 5x fewer tokens, month-long single sessions (billions of tokens), and high compression quality.",
"author": {
"name": "ranxianglei"
Expand Down
3 changes: 3 additions & 0 deletions scripts/live-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const LIVE_FILES = [
// both spawn the corrupt-index-child helper (unified-store cold-load
// corruption probes, #4216/#4249 follow-ups); append-only per the note above
"tests/storage-engine-proofs.test.ts",
// lock-holder CHILD process parks on a hermetic mkdtemp index.db (#2195
// release-gate pin); binds no ports — zone slot is a formality
"tests/storage-open-busy-lock.test.ts",
"tests/web-storage-banner.test.ts",
// #4434 (split-brain surface): spawns bili CLI children against a throwaway
// origin; own probe server is listen(0) so only the zone band matters
Expand Down
71 changes: 70 additions & 1 deletion src/storage/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,21 @@ export class StorageSecondWriterError extends Error {
}
}

/**
* #2195 release-gate fix (e2e-fake-codex failure, 2026-11-13_release-v0.1.214):
* true when the SQLite file header already declares WAL (header bytes 18-19
* == 0x02). A plain file read — no database lock, so it is always safe,
* unlike asking the engine via `PRAGMA journal_mode`.
*/
function dbFileIsAlreadyWal(dbPath: string): boolean {
try {
const head = readFileSync(dbPath);
return head.length >= 100 && head[18] === 0x00 && head[19] === 0x02;
} catch {
return false; // file absent/unreadable → not WAL → let the pragma decide
}
}

export class UnifiedStore {
readonly engine: SqliteEngineName;
/** Where the engine came from (#2833): builtin / host / self-downloaded — logged at enable so field diagnosis can tell which acquisition path a lane ran on. */
Expand Down Expand Up @@ -496,6 +511,23 @@ export class UnifiedStore {
): UnifiedStore {
mkdirSync(dirname(path), { recursive: true });
const { db, engine: used, source } = openSqliteDatabase(path, engine);
// The pre-migration quick_check below runs BEFORE the storagePragmas
// loop installs the connection's busy handler — on a bare handle the
// first statement throws raw SQLITE_BUSY the instant a concurrent
// writer holds the lock. That is a real, reachable shape, not a lab
// artifact: the launcher kills its proxy fire-and-forget on exit
// (stopProxy is a bare SIGTERM, no wait-for-exit), so the NEXT launch's
// opener routinely starts while the previous instance is still
// draining its graceful flush against the SAME shared sessions dir
// (one index.db per machine is the supported topology, #5082). The
// e2e #2195 gate hit exactly this: the fresh proxy parked on the
// startup-failure page ("database is locked") and the launcher burned
// its 60 s health budget on a child whose only problem was a missing
// busy handler. busy_timeout is a connection-level pragma that never
// touches the file, so it is safe to install before the corruption
// classification below; storagePragmas reapplies the same value
// idempotently for the remaining opens.
db.exec("PRAGMA busy_timeout = 5000");
// #4175/#4609: integrity self-check, verdict-cached and size-gated.
// An unchanged file set (index.db + -wal stats + schema version) skips
// the rescan; a small store checks synchronously BEFORE migrations (a
Expand Down Expand Up @@ -604,7 +636,44 @@ export class UnifiedStore {
}
try {
const limit = opts?.walJournalSizeLimitBytes ?? WAL_JOURNAL_SIZE_LIMIT;
for (const pragma of storagePragmas(limit)) db.exec(pragma);
for (const pragma of storagePragmas(limit)) {
if (pragma === "PRAGMA journal_mode = WAL") {
// The #2195 trap: `PRAGMA journal_mode` needs exclusive
// access and BYPASSES the connection's busy handler — it
// throws raw SQLITE_BUSY instantly while a peer holds a
// write transaction (repro: holder BEGIN IMMEDIATE +
// insert, fresh handle with busy_timeout=5000 installed →
// journal_mode throws at 0 ms, quick_check is fine).
// That peer is the normal one: stopProxy is fire-and-
// forget, so the previous proxy may still be draining its
// final flush on this same machine-global file when the
// next launch opens it (#5082). Two cases:
if (dbFileIsAlreadyWal(path)) {
// The store is ALREADY WAL (created WAL, never
// switched back) — skipping the pragma is a strict
// no-op and saves the exclusive acquisition entirely.
continue;
}
try {
db.exec(pragma);
} catch (err) {
const msg = String((err as { message?: unknown })?.message ?? err);
if (!msg.includes("SQLITE_BUSY") && !msg.includes("database is locked")) throw err;
// The file is still in its legacy journal mode and a
// peer holds the write transaction, so the switch
// cannot run right now. #5082 owner decision
// 2026-10-31: a live foreign writer never blocks
// startup — defer the switch to the next open (the
// previous open already moved the file to WAL in the
// normal case) and continue in the current journal
// mode, which is safe multi-process, just less
// concurrent.
loggerLog("warn", `[storage] journal_mode=WAL deferred for ${path} — a peer holds the write lock (#5082); continuing in the current journal mode, switch retries on the next open`);
continue;
}
}
db.exec(pragma);
}
migrateSchema(db);
} catch (err) {
// The handle we just opened must not leak when the file turns out
Expand Down
17 changes: 15 additions & 2 deletions tests/e2e/e2e-advisory-rollback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ async function readPkgVersion(dir: string): Promise<string> {
return (JSON.parse(await fs.promises.readFile(path.join(dir, "package.json"), "utf8")) as { version: string }).version;
}

// The updater's uninstall→reinstall half-deletes the install dir (npm drops
// package.json before the directory): readPkgVersion ENOENTs inside that
// window. waitFor probes must treat "gone for a moment" as "not there yet",
// not crash — anything other than ENOENT still throws.
async function pkgVersionOrAbsent(dir: string): Promise<string | null> {
try {
return await readPkgVersion(dir);
} catch (err) {
if ((err as NodeJS.ErrnoException).code === "ENOENT") return null;
throw err;
}
}

function packTarball(stage: string, packs: string, home: string): string {
const listing = npmRunSync(["pack", "--silent", "--pack-destination", packs], { cwd: stage, env: { PATH: process.env.PATH ?? "", ...npmHomeEnv(home) } })
.trim()
Expand Down Expand Up @@ -262,14 +275,14 @@ test("e2e: rollback-form advisory (#1588) — forced rollback, no ping-pong, per
await waitFor(
`disk ${START} → ${LATEST} via normal self-update`,
90_000,
async () => (await readPkgVersion(installDir)) === LATEST && installedRe.test(readLog()),
async () => (await pkgVersionOrAbsent(installDir)) === LATEST && installedRe.test(readLog()),
);
assert.match(readLog(), installedRe);
});

await t.test("rollback-form advisory lands: forced install of the older target + persistent restart banner", async () => {
await reg.publish(await makeAdvisoryTarball(work));
await waitFor(`disk ${LATEST} → ${TARGET} via forced advisory install`, 60_000, async () => (await readPkgVersion(installDir)) === TARGET);
await waitFor(`disk ${LATEST} → ${TARGET} via forced advisory install`, 60_000, async () => (await pkgVersionOrAbsent(installDir)) === TARGET);
const log = readLog();
assert.match(log, new RegExp(`forcing update to ${escapeRe(TARGET)}`));
// #1588-B: disk left the range but the RUNNING process is still on the
Expand Down
Loading
Loading