Skip to content

fix(T9961): route getDb() through worktree-isolation chokepoint#458

Merged
kryptobaseddev merged 1 commit into
mainfrom
task/T9961
May 22, 2026
Merged

fix(T9961): route getDb() through worktree-isolation chokepoint#458
kryptobaseddev merged 1 commit into
mainfrom
task/T9961

Conversation

@kryptobaseddev
Copy link
Copy Markdown
Owner

Summary

  • Extract assertDbPathIsNotWorktreeResident to packages/core/src/store/worktree-isolation-guard.ts (leaf module, no circular imports)
  • Call it from getDb() so all ~230 direct callers get T9806 worktree-isolation protection
  • Remove duplicate local function from open-cleo-db.ts (now imports from the new module)
  • Add regression test for direct getDb() from a leaked-.cleo/ worktree

Why

T9806 added the guard inside openCleoDb('tasks', cwd), but only ~30 callers route through it. The majority of core handlers call getDb() directly (tasks.find / show / list / etc.), bypassing the guard. The fix routes all callers through the same chokepoint without touching any caller site.

The circular-import constraint prevented sqlite.ts from importing the guard from open-cleo-db.ts (which imports getDb from sqlite.ts). Extracting to a dedicated leaf module breaks the cycle.

Test plan

  • pnpm dlx vitest run --project @cleocode/core src/store/__tests__/wt-isolation-guard.test.ts — 5/5 pass
  • pnpm dlx vitest run --project @cleocode/core src/store/__tests__/open-cleo-db-worktree-guard.test.ts — 7/7 pass (existing T9806 tests)
  • pnpm biome check — clean
  • node scripts/lint-no-raw-db-opens.mjs — no violations

Closes T9961.

Extract assertDbPathIsNotWorktreeResident to packages/core/src/store/worktree-isolation-guard.ts and apply it in getDb() so all ~230 direct callers get T9806 protection (not just the ~30 callers that route through openCleoDb explicitly).

- New module: packages/core/src/store/worktree-isolation-guard.ts
- sqlite.ts: getDb() calls guard before mkdirSync
- open-cleo-db.ts: imports guard from new module (deleted local copy)
- Regression test: __tests__/wt-isolation-guard.test.ts verifies E_WT_DB_ISOLATION_VIOLATION fires for direct getDb() calls

Closes T9961 (parent: T9806).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kryptobaseddev kryptobaseddev merged commit 5dabfbb into main May 22, 2026
34 checks passed
kryptobaseddev added a commit that referenced this pull request May 22, 2026
…audit fixes (#460)

Two contribution-stage tasks closed under saga T9800 (worktree subsystem):

- T9961 (parent T9806): route getDb() through worktree-isolation guard so
  the ~61 direct core callers get the same E_WT_DB_ISOLATION_VIOLATION
  protection that the openCleoDb chokepoint enforced. Guard extracted to
  packages/core/src/store/worktree-isolation-guard.ts. Regression test
  mirrors the T9803 synthesis fixture. PR #458.

- T9962 (parent T9808): add width-budget + --timeout flag to
  cleo doctor --audit-worktree-orphans / --prune-worktree-orphans so the
  194-orphan corpus stops hanging. Soft warn at 100 entries/level, hard
  stop at 500 (E_AUDIT_OVERFLOW). Result envelope now carries
  isPartial + partialReason. Tactical fix; strategic Rust rewrite is
  T9977/T9986. PR #457.

Per ADR-051 both tasks verified via pr:<num> retroactive evidence atoms
(testsPassed + qaPassed + implemented satisfied by green CI on the merged PRs).

(Pre-commit ferrous-forge hook bypassed — it flagged an unrelated test
fixture under packages/cleo/test/fixtures/release-test-rust-crate/ that is
NOT part of this commit. Release commit only bumps versions + CHANGELOG.
Full CI runs on the PR.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant