🐛 fix(kavach): a failed record scan logs a scan-failed row and allows the write, 0.8.9
Under work item #43. This is option B, as Alok chose it in chat on 2026-11-25 ("B, refuse now"), recorded on #363: https://github.com/veda-hq/veda/issues/363#issuecomment-7159865990. Approved with a 👍 on https://github.com/veda-hq/veda/issues/588#issuecomment-7159936664.
Rule other-sessions-worktree used to read a failed scan of the desktop app's session records as "no owner", silently, in both modes. So a quiet trial log could not tell "no fires" from "scan broken". Now the failure is visible, and it still never refuses.
What changes:
boundary.worktree_ownersreturns anOwnerScan:ownersisNonewhen the whole scan fails, withfailuresaying why: a missing or symlinked records folder, or any error.skippedcounts the records that could name the worktree but are overRECORD_LIMIT, or cannot be read, parsed or resolved, such as one the app is part way through writing. One bad record is skipped on its own: the owner comparison sits in the per-recordtry, so it never fails the whole scan.- A record whose head or text shows it cannot name the worktree is never parsed, so it is not counted, even when oversized. A symlinked record is still skipped on purpose, and is not counted either.
- It still never raises.
worktree_guard.other_sessions_worktreereturns anOtherSessionsFinding: the message as before, plus what went wrong in the scan.judge_other_sessions_worktreelogs one row for a failed or partial scan, in either mode. The row hasruleother-sessions-worktreeandmodescan-failed, a third value besidewarnandrefuse. The reason says only what this rule decided, since a later check in the guard can still refuse the call. It reads "…record scan failed (…), so it found no owner; this rule let the call through." or "…could not read N session records, which name no owner; this rule refused the call." (or "let the call through").- The call is then judged by the owners the scan did find:
- A failed scan finds none, so it allows the call under
refusetoo. - A partial skip with a live owner left still warns under
warnand refuses underrefuse. Its row then says "this rule refused the call". - An error in the check itself keeps today's handling: it allows and logs while warning, and refuses once the rule refuses.
- A failed scan finds none, so it allows the call under
- The README rule row and the refusal log's docstring describe the row.
- kavach and sarathi move to 0.8.9, and sarathi's
VERSIONinsrc/version.tsfollows. That is the next legal version afterv0.8.8, which released agnipariksha.
Tests (OtherSessionsWorktreeTest):
- A symlinked records folder: this session's own record still reads through it, and the owners' scan fails. The call is allowed and logs a
scan-failedrow, underwarnand underrefuse. - A cut-off record that names the worktree is logged while the live owner still warns, then refuses. With the owner gone, it alone allows.
worktree_owners:- a glob error is
failure="RuntimeError", and a missing folder is said as such; - a cut-off record counts 1, and an oversized one that could name the worktree counts. An oversized one whose head names another folder, one that cannot name the worktree, and a symlinked one do not count;
- a
cwdthat cannot be resolved, in the head or past it, skips that record and not the scan; judge_other_sessions_worktreetakes a failed scan as no error underrefuse.
- a glob error is
- The silent cases log no row at all.
- Each per-record check is pinned in
worktree_ownersby a record that sorts before the live owner's, so acontinueturned intobreakloses that owner. The cases are a non-object, a malformed id, archived, a relative or non-stringcwd, another worktree or a later name past the head,isArchived1 or missing (still owners), and a record exactly at the limit (read). other_sessions_worktreesays 0, 1 and 2 skipped records and a failed scan. The judge's scan row is checked for warn, refuse with a fire, and refuse with none, each with and without a scan problem.- The judge logs the scan row in each branch, and the singular or plural is a lookup. Both rewrites remove comparisons whose mutants no reachable value tells apart.
- The 14 mutants the CI gate named, plus
if scan→if not scan, were each applied in turn to a copy, andOtherSessionsWorktreeTestfailed for every one. pnpm --filter @veda-hq/kavach test:python: 941 tests pass.
Checked against the real records on this Mac: this branch's final worktree_owners, run over the desktop app's 1,156 records, skipped none and did not fail. The largest record is 325 KB; the limit is 8 MB. So the new row will not flood the log.
Next under this slice (each with a State, as #381 was):
- Tag
v0.8.9after this merges. Open #586, pariksha, also sets 0.8.9: one tag releases both if it comes after both merge, or the later one moves to 0.8.10. - veda's pin bump to sarathi and kavach 0.8.9.
.claude/kavach.jsonsets"rules": { "other-sessions-worktree": "refuse" }.
athya_mono and niyam each need their own pin bump and rules entry; they are not part of this slice.
🤖 Generated with Claude Code