Repository navigation
fix(#2195): provenance-first generation winner in codex overlay SQLite merge-back - #2207
Conversation
…e merge A WAL-only commit leaves the main db's bytes AND mtime untouched, and a file copy can carry the source mtime forward (measured on Windows), so the old main-mtime-only rule selected the STALE generation whenever the newer commit sat in an uncheckpointed WAL with equal main mtimes: sequential bili launches quarantined the new thread into .bili-conflict instead of merging it back. mergeSqliteSet now classifies each side against the copy-time origin snapshot (#1919): unmodified-vs-committed decides the winner outright; mtime stays in play only when both sides advanced independently (true #1917 divergence) or no usable snapshot exists (conservative). -shm is excluded from commit detection (rebuildable coordination file; merely opening the db creates a 0-byte -wal + -shm), so connection artifacts no longer read as commits. Whole-set movement, rollback and recoverable conflict groups are unchanged. runLaunch now releases the overlay lease AFTER the exit merge-backs, so a concurrent launch cannot acquire the overlay mid-finalize. Regression: deterministic unit tests (subprocess-created uncheckpointed WAL commits, pinned equal main mtimes; fail on pre-fix code) plus the real-codex two-sequential-launch e2e, now also running on a hosted Windows runner where the failure condition actually occurs.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2267-pr.2207.ac6e025This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2207.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #2207 审查结论(fix #2195:codex overlay SQLite merge-back 代际胜者选择) 我按 review 优先级走了五关:审原 issue → 回归审查 → 代码主关 → 测试有效性 → diff 整洁度,并在 head commit 1. 是什么问题 2. 什么原因导致的 3. 怎么修复的 4. 是否有回归问题 5. 是否破坏缓存 6. 是否改了设计方向 7. 是否引入了新的配置 测试有效性(质量关):单测用真实 diff 整洁度:恰好 4 个文件(launcher 修复 + 2 个测试 + 1 个 workflow),无锁文件 / 生成物 / 无关改动。唯一一处顺带小改:e2e 既有 #1965 用例紧邻处一行类型收窄 cast( CI:我在 head 判定:可合并(mergeable)。 根因定位准确、四个修复点全部落实、物理安全机制完整保留、单元 / 真机 e2e / Windows CI 三层有牙测试齐备、diff 干净、CI 全绿、无配置 / 线协议 / kernel 面变更、无数据丢失路径。合并动作按规则由你来执行,我不代合:#2207 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.56-master.f85ccfc # this exact build
npm install -g billion-context@master # always the newest merged build
|
What
On Windows, two sequential
bili codex execruns lost the second run's thread into.bili-conflictinstead of merging it back into the real home's activestate_5.sqlite. Root cause (verified againste5a0066de):mergeSqliteSetchose the winner by main-db mtime only (rMain.mtimeMs >= oMain.mtimeMs ? "real" : "overlay") and only afterwards checked the loser against the copy-time origin snapshot. But a WAL-only commit leaves the main db's bytes AND mtime untouched, and a file copy can carry the source mtime forward (issue measured identicalmtime_nson both sides) — so equal main mtimes deterministically selected the STALE generation, and the stale-check could only decide warn-vs-silent for the already-wrong loser.Fix (mechanism-level)
mergeSqliteSetnow classifies BOTH sides against the copy-time origin snapshot (sqliteSideVsOrigin, replacing the loser-onlysqliteLoserIsStaleCopy):.bili-conflictpreservation, main-mtime tiebreak (unchanged);-shm(rebuildable coordination file — merely OPENING a WAL-mode db creates a 0-byte-wal+-shm; verified empirically). A zero-byte newly-present-walis likewise treated as a connection artifact, not a commit. This removes a second spurious-conflict path in the same mechanism family: the old staleness check counted shm drift as "not stale" and produced conflict files for mere opens.runLaunchnow releases the overlay lease afterfinalizeGooseHome/finalizeCodexHomeinstead of before — the exit merge-back runs while this launch still holds the exclusive lease, closing the window where a concurrent launch could acquire the overlay mid-finalize (issue fix-point 4).Behavior changes (old → new)
real(was: whatever the mtimes said); end state is identical there (silent drop + re-copy).-shmbyte drift no longer blocks the silent drop (old code warned + quarantined on shm-only drift; reproduced: new unit test fails on pre-fix code for this reason too).distinct/divergesubstrings kept for existing consumers/tests).mergeSqliteSet: codex exit finalize AND startup fold, and the dsh startup fold (same mechanism, same direction of improvement).Config surface
None. No config field, env var, or CLI flag added/renamed/re-semantics'd.
Regression coverage
tests/launcher-sqlite-overlay.test.ts: 5 new deterministic tests using subprocess-created uncheckpointed WAL commits (no pre-merge db open, no manual making-the-winner-newer; both mains pinned to a fixed equal epoch per the issue's sanctioned approach): overlay-WAL-only wins silently through BOTH entry points (exit finalize + startup fold), mirror case, SHM-only drift ≠ commit, true both-sides divergence warns + preserves recoverable group (recovered exactly like the issue's manual step 6), missing-origin stays conservative. All runPRAGMA integrity_checkon the active db. Verified they fail on pre-fix code (tests 1–3 red one5a0066de, green after fix); all 30 file tests pass.tests/e2e/e2e-codex-fake.test.ts: new hermetic real-codex test — three sequentialbili codex execlaunches + nativecodex exec resume --last, asserting every thread lands in the real home's active db (delta +1 per launch), the NEXT active overlay carries all previous threads while in flight, zero.bili-conflictfiles, and native resume restores launch 3's history (the issue leftcodex resumerecovery unverified). Ran green locally with codex-cli 0.147.0 (same pin as CI):threadstable = 3 rows, no conflict files..github/workflows/ci-windows-codex.yml: new hosted-Windows job running the#2195|#1965lanes of that suite (codex pinned 0.147.0 likeci-e2e-fake.yml). The failure condition is Windows-specific (timestamp-preserving copies) and NOT reproducible on POSIX — this is the real-machine gate; the unit suite is its deterministic cross-platform twin.Local gates:
npm run typecheckclean; targeted suites green (launcher-sqlite-overlay30/30,launcher+codex-overlay-env+overlay-busy-lock295/295, e2e-fake#2195|#19652/2). Full regression delegated to CI per local-testing discipline.Hot-file note: base is current master (verified 0 behind at commit time). Open PRs touching
src/launcher.ts(#2194 dsh spawn retry, #2178 ACP_PORT pin) sit in disjoint regions (dsh lane / proxy port logic); if either lands first, resolve by union of intent and re-run the targeted suites.Closes #2195