diff --git a/.agents/plugins/marketplace.json b/.agents/plugins/marketplace.json index 9265730d36..3f154f1164 100644 --- a/.agents/plugins/marketplace.json +++ b/.agents/plugins/marketplace.json @@ -6,7 +6,7 @@ "plugins": [ { "name": "billion-context", - "version": "0.1.214", + "version": "0.1.215", "source": { "source": "local", "path": "./plugins/codex" diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 147f989fb5..51c33c6f5d 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -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.214", + "version": "0.1.215", "author": { "name": "ranxianglei" }, diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index dbeb07d567..aee93aa7ab 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "billion-context", - "version": "0.1.214", + "version": "0.1.215", "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" diff --git a/package-lock.json b/package-lock.json index e0603e3124..d8f8888b77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "billion-context", - "version": "0.1.214", + "version": "0.1.215", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "billion-context", - "version": "0.1.214", + "version": "0.1.215", "license": "MIT", "dependencies": { "mysql2": "^3.15.3", diff --git a/package.json b/package.json index ee35baf823..160f8eba56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "billion-context", - "version": "0.1.214", + "version": "0.1.215", "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", diff --git a/plugins/codex/.codex-plugin/plugin.json b/plugins/codex/.codex-plugin/plugin.json index c15589b1e5..111320e19a 100644 --- a/plugins/codex/.codex-plugin/plugin.json +++ b/plugins/codex/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "billion-context", - "version": "0.1.214", + "version": "0.1.215", "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" diff --git a/src/paths.ts b/src/paths.ts index f37cb24a84..de613d3099 100644 --- a/src/paths.ts +++ b/src/paths.ts @@ -1,4 +1,4 @@ -import { existsSync, readdirSync } from "node:fs"; +import { existsSync, readdirSync, statSync } from "node:fs"; import { homedir } from "node:os"; import path from "node:path"; @@ -30,12 +30,13 @@ export function configDir(): string { } /** Resolve a config ref (BILI_CONFIG_FILE / -c/--config value): a path - * (contains a separator, or names an existing file in CWD) stays a path; + * (contains a separator, or names an existing FILE in CWD — a directory is + * never a valid config file) stays a path; * a bare NAME selects /NAME.json — "billion-context" is the * default file itself, so per-purpose siblings ("dsh-test", "ework-qq") * switch the whole config without touching env vars. */ export function resolveConfigFileRef(ref: string): string { - if (ref.includes("/") || ref.includes("\\") || existsSync(ref)) return path.resolve(ref); + if (ref.includes("/") || ref.includes("\\") || statSync(ref, { throwIfNoEntry: false })?.isFile()) return path.resolve(ref); return path.join(configDir(), `${ref}.json`); } @@ -43,11 +44,14 @@ export function resolveConfigFileRef(ref: string): string { * a bare NAME (no separator, no CWD file) whose /NAME.json is * missing is an error — the message names the resolved path plus every * available sibling so a typo can't silently start the proxy on an empty - * config. Explicit PATHS (and refs naming an existing CWD file) keep their + * config. Explicit PATHS (and refs naming an existing CWD FILE — statSync: + * a directory is NOT a file, so a CWD directory named like a bare config + * name falls through to named resolution and fails fast instead of booting + * with a default config via EISDIR) keep their * historical missing→empty behavior and return null. */ export function checkNamedConfigRef(ref: string): string | null { if (!ref || ref.trim().length === 0) return null; - if (ref.includes("/") || ref.includes("\\") || existsSync(ref)) return null; + if (ref.includes("/") || ref.includes("\\") || statSync(ref, { throwIfNoEntry: false })?.isFile()) return null; const dir = configDir(); if (existsSync(path.join(dir, `${ref}.json`))) return null; let names: string[] = []; diff --git a/src/persist.ts b/src/persist.ts index ed0762b211..2746ad49f4 100644 --- a/src/persist.ts +++ b/src/persist.ts @@ -3296,7 +3296,13 @@ export class SessionStore { // anything (the content-store re-key happens inside and must land in // the same write). Cold-load alignment retired: see loadSync note. this.consumePendingLedgerAlign(session); - if (!this.saveContentStore(session)) return; + if (!this.saveContentStore(session)) { + // #6793-review: this save will not run — drop the #6780 arm so it + // cannot pin this session's lastMessages + metadata fingerprint + // in memory forever (leak on eviction). + this.durabilityArms.delete(session.id); + return; + } if (this.writerOffActive() || this.envelopeFrozen(session.id)) { if (this.envelopeFrozen(session.id)) this.noteFrozenSkip(session.id, "scheduled"); // Phase 3 (#2960): index-only persistence — the builder closure @@ -3381,6 +3387,12 @@ export class SessionStore { }); return; } + // #6793-review: the durability arm is only consulted by the writer-off + // coalesced run above. The debounced path always builds the full record + // and never reads the arm — clear it here, otherwise an armed-but- + // debounced save (JSON-writer process) leaks one arm (pinning + // lastMessages + a metadata snapshot) per evicted session. + this.durabilityArms.delete(session.id); if (!this.enabled) return; this.tryRecoverSidecar(); // #5188: dirty activity is the "still wanted" signal for a lost sidecar const id = session.id; @@ -3577,7 +3589,12 @@ export class SessionStore { * either. Do NOT regress this by eager-snapshotting the record here. */ async writeNow(session: Session): Promise { this.consumePendingLedgerAlign(session); // #5608-D: before any serialization - if (!this.saveContentStore(session)) throw new Error(`Originals were not saved for ${session.id}`); + if (!this.saveContentStore(session)) { + // #6793-review: see scheduleSave — the arm is useless without a + // writer-off coalesced run; clear it before propagating. + this.durabilityArms.delete(session.id); + throw new Error(`Originals were not saved for ${session.id}`); + } if (this.writerOffActive() || this.envelopeFrozen(session.id)) { if (this.envelopeFrozen(session.id)) this.noteFrozenSkip(session.id, "writeNow"); // #3133: drop the armed microtask (token mismatch below) — this @@ -3595,6 +3612,9 @@ export class SessionStore { this.dropResidentContentStore(session); return; } + // #6793-review: full-build path (store.writeNow) never consults the + // durability arm — clear it so it cannot pin state after eviction. + this.durabilityArms.delete(session.id); const proofRevision = session.revisionEpoch; // #4788 D2: capture BEFORE the chain builds this.saveWritesInFlight.add(session.id); const rec: { v: PersistedSession | null } = { v: null }; diff --git a/tests/config-named-ref.test.ts b/tests/config-named-ref.test.ts index 18212a1527..0417a4f571 100644 --- a/tests/config-named-ref.test.ts +++ b/tests/config-named-ref.test.ts @@ -81,6 +81,27 @@ test("checkNamedConfigRef: missing name fails with the sibling list (gate off)", assert.ok(!(err as string).includes("summary-credentials"), "auxiliary *.json.*.json sidecars are not named configs"); }); +test("a CWD DIRECTORY named like a bare ref is not a config file (PR#6793 review M1)", () => { + // A directory in the CWD with the same name as a bare ref must not shadow + // named-config resolution: existsSync(dir)===true used to keep the ref a + // "path", and readFileSync(dir) then threw EISDIR, so the proxy booted on + // the DEFAULT config, silently defeating the fail-fast gate. + const cwdDir = path.join(process.cwd(), "dsh-test"); + fs.mkdirSync(cwdDir, { recursive: true }); + try { + assert.equal(resolveConfigFileRef("dsh-test"), path.join(configDir, "dsh-test.json")); + assert.equal(checkNamedConfigRef("dsh-test"), null, "real named config in configDir still passes"); + fs.rmSync(path.join(configDir, "dsh-test.json"), { force: true }); + try { + assert.ok(checkNamedConfigRef("dsh-test"), "a shadowing directory must not satisfy the gate"); + } finally { + fs.writeFileSync(path.join(configDir, "dsh-test.json"), "{}"); + } + } finally { + fs.rmdirSync(cwdDir); + } +}); + test("checkNamedConfigRef: paths and empty refs keep historical behavior (null)", () => { assert.equal(checkNamedConfigRef(""), null); assert.equal(checkNamedConfigRef(" "), null);