✨ feat(veda): veda's own mutation gate, one tap lane per package

Merged
AT
8d ago
+1758-41

Slice #272 under #238. Alok settled questions 1 and 2 on 2026-11-19: the gate uses the tap runner on node:test as the suites are written, and small lanes are judged at pre-push.

Where it stands (2026-11-22). Nothing waits on Alok now:

  1. #324, the cli.test.ts fix (below), is on main through #412 (8bc1428).
  2. Alok committed the pre-push stage to this branch as de661e8. That is the three changes under "For Alok", and they match the copies tested in scripts/githooks.test.mjs byte for byte.
  3. Alok approved the pull request as code owner, since eslint.config.js is a code-owner path.
  4. niyam's Guard needs a guard file named in its slice, so #272 now has a Guards: line naming .githooks/pre-push and .dvara.json. Alok approved #238 again after that edit.
  5. aa7cefb makes every lane skip Stryker's tsconfig rewrite. See "Found: a hoisted TypeScript 7 crashes every lane" below.

Auto-merge is on. aa7cefb was checked in a worktree that has the stale TypeScript link, and the lane ran there with no crash.

The cut-off

maxLines is 1,500, with 1,000 for sarathi and 400 for pariksha. It was timed on 2026-11-20 on Alok's Mac, an 18-core M5 Max: load was 1.9 and 2.9 before the two batches, and 2.95 of 4 GiB of swap was in use. A linked session was pushing a fix during the pariksha run. The samples are CI's from #238.

The aim was about 3 minutes per lane, below the 5 minutes recorded on #238. I set it lower so that a push still finishes when the Mac is busy, which made the pariksha pair 3.6 times slower. The number is Alok's to change.

LaneLinesMutantsTimes/lineBlocking (CI's)
kavach69360926 s0.0410 (10)
shuddhi35033016 s0.0552 (no CI sample)
agnipariksha, cli.ts left out5847187 s0.0143
dvara51447656 s0.1155 (54)
sarathi31138557 s0.1878 (78)
pariksha7391,0496.6 min0.54128 (128)
  • Verdicts. Every lane CI also sampled blocked on the same count as CI, except dvara, which blocked on one more.
  • Retries. Retrying timed-out mutants is much of the slow lanes' time:
    • kavach, shuddhi and agnipariksha retried none;
    • dvara retried 9, in about 22 s;
    • sarathi retried 3, one of them 41 of its 57 s, so its 1,000 rests on that one mutant;
    • pariksha retried 25, in 2.7 of its 6.6 minutes. It ended with 2 timeouts, the same as CI with 4 runners, so 17 runners here probably caused the other 23.
  • The cut-off in a real run. --files <the pariksha pair>,packages/kavach/src/rule-checks/spawn.ts --tracked-only judged kavach's file. It left pariksha's 739 lines to CI with over its cut-off of 400, and exited 0.
  • pariksha mostly goes to CI. Its cli.ts alone is 1,264 lines.

Found: agnipariksha's own lane can't judge its cli.ts. With cli.ts among the targets, the run is refused because its temp directory vanished.

  • The cause. cli.test.ts:529, "a run whose temp directory vanished refuses", has a child process delete process.env.TMPDIR. A mutant that drops the scratch variables from spawnStryker's child environment makes that child delete the gate's own scratch directory instead. The guard did its job, since under the shared temp directory that mutant would have removed other processes' files.
  • The fix is in the test. It should set TMPDIR to a directory it owns before calling spawnStryker. Then that mutant deletes only the test's directory, and the test still kills it.
  • It must land before the hook line. With the hook on, any push touching packages/agnipariksha/src/cli.ts is refused, and #273's agnipariksha job would refuse the same way. A fix inside cli.ts itself couldn't pass the hook, which is another reason the fix belongs in the test. That fix is #324, which #412 merged on 2026-11-22.
  • After #324. The #324 session ran --lane agnipariksha --files packages/agnipariksha/src/cli.ts on a merge of this branch. There was no temp-directory refusal, and the scratch-environment mutants were killed. The run counted 398 killed of 467: 54 Survived and 15 NoCoverage, mostly lines 444 to 451, so once the hook is on, the next push touching cli.ts meets 69 old blocking mutants (#411 touches it). Under load 17 to 22, its timeout retries also passed their 15-minute budget, and it was refused for that.

Found: a hoisted TypeScript 7 crashes every lane. To rewrite a lane's tsconfig.json for the sandbox, Stryker runs import('typescript'), and it declares no dependency on typescript.

  • Who has the link. The main checkout and eight worktrees have a hidden hoist link, node_modules/.pnpm/node_modules/typescript, to TypeScript 7.0.2, all dated Nov 14.
  • Why it crashes. TypeScript 7.0.2 has no parseConfigFileTextToJson, so Stryker fails before its first mutant with ts.parseConfigFileTextToJson is not a function.
  • Not every checkout. A worktree installed later, like this one, has no such link and never sees the crash.
  • Why it matters. With the hook on, it would refuse every push from those checkouts that touches a lane source.
  • The fix, aa7cefb. stryker/lane.mjs sets tsconfigFile to a file that never exists, so the rewrite is skipped.
  • Why nothing is lost. No lane needs the rewrite: the suites run on node:test, which reads no tsconfig, and none reads its package's tsconfig.json. shuddhi has no tsconfig.json, so the rewrite never ran there.
  • The link itself goes only with a clean reinstall. pnpm install --force keeps it, and that's Alok's to do, since agents can't touch node_modules/.

What changes

  • Pins. The root pins @stryker-mutator/core and @stryker-mutator/tap-runner at 10.1.1, and @veda-hq/agnipariksha at 0.7.9, the release with the cut-off (#278).

  • agnipariksha.json:

    • Lanes. One per TypeScript package: agnipariksha, dvara, shuddhi, kavach (its TypeScript only; #271 times a Python tool for the rest), pariksha and sarathi. packages/needs-you is a plugin, not a workspace package: it has no src/, and its tests sit in tests/, not beside the sources. So it gets no lane.
    • What each lane mutates. Its src/, leaving out tests, .d.ts files and fixtures. shuddhi's sources are .js, so its lane takes .js and .ts.
    • Environment. unsetEnv removes the GIT_DIR family from every Stryker run, because a hook exports it (docs/lessons/stryker.md).
    • Reuse. reuse is off for now.
  • stryker/lane.mjs is the config every lane uses:

    • the tap runner, with perTest coverage;
    • the owning suites agnipariksha passes as {suites}, with the package's prefix cut off;
    • the json reporter only, since agnipariksha prints each blocking mutant itself.

    Each package's stryker.config.mjs is one line calling it.

  • Ignores. reports/ and .stryker-tmp/ are ignored by git and by eslint. git also ignores packages/*/reports/, which a Stryker run straight from a package writes. The eslint ignore is the one line in eslint.config.js, a code-owner path.

  • Docs. docs/lessons/stryker.md says how to run one lane by hand. pnpm-workspace.yaml's comment no longer says veda never runs Stryker.

  • agnipariksha's smoke test. It now runs --lane smoke-no-such-lane. It used to expect no agnipariksha.json at the root, and veda now has one. It now requires the unknown-lane refusal, which lists veda's lanes, so it checks that the built CLI loads veda's config. The package's version is unchanged, since nothing a consumer runs changes.

What the gate doesn't judge

agnipariksha judges a changed file only when a <stem>.test.ts (or .test.tsx) sits beside it, and says so for any it skips. #274 should count these as unreviewed once Cubic stops reading tests:

  • Sources with no owning suite:
    • dvara: head.ts, records/rules.ts, records/types.ts, and supervisor.fixture.ts, a test helper main added with #383
    • pariksha: git.ts, load-vitest-config.ts, repo-rules-memory.ts
    • sarathi: bin.ts, page/protocol.ts, worktree/hook.ts
    • shuddhi: index.js, error-handling/index.js
  • The scripts. scripts/*.mjs are tested by scripts/*.test.mjs, which agnipariksha doesn't recognise as an owner, so they get no lane. That needs an agnipariksha change first.

For Alok: the pre-push stage

Done: Alok committed these three changes as de661e8. .githooks/pre-push and .dvara.json are kavach's protected paths, and the test copies both. They still fit main's hook as of the 2026-11-22 merge: the guards stage still comes before niyam's, and .dvara.json still lists ["records", "frozen", "guards", "niyam"].

1. .githooks/pre-push, after the guards stage:

dvara_stage mutation
"$root/node_modules/.bin/agnipariksha" --tracked-only --base "$base" || exit 1
  • --base "$base" keeps the hook's own fallback to HEAD when origin/main is missing.
  • --tracked-only leaves out untracked files, since a push carries none.
  • Lanes over maxLines are left to CI (#273), because the run names no lane.
  • The pin is already checked. The hook runs released-pins.mjs first, and that checks every @veda-hq/* pin, this one included.
  • Old survivors refuse pushes. Stryker mutates a touched file whole, so once the hook is on, a push touching a file that already has surviving mutants is refused for mutants it didn't add. kavach's args.ts has 4 such mutants and dvara's quiet.ts 3, and the lanes timed above blocked on 10 to 128 each. Either kill a file's survivors first, or expect its next change to.

2. .dvara.json, where pre-push's stages gain mutation:

"pre-push": ["records", "frozen", "guards", "mutation", "niyam"]

3. scripts/githooks.test.mjs. The fixture copies .githooks and veda's stage list, so the hook would fail there for want of an agnipariksha.

In the fixture setup, beside the niyam stand-in:

writeFileSync(join(repo, 'node_modules', '.bin', 'agnipariksha'), '#!/bin/sh\necho "agnipariksha $*" >> "$AGNIPARIKSHA_CALLS"\n[ -z "${AGNIPARIKSHA_REFUSE:-}" ]\n');
chmodSync(join(repo, 'node_modules', '.bin', 'agnipariksha'), 0o755);

In the env, AGNIPARIKSHA_CALLS: join(scratch, 'agnipariksha-calls').

In the clean-push test:

assert.match(readFileSync(join(scratch, 'agnipariksha-calls'), 'utf8'), /^agnipariksha --tracked-only --base (origin\/main|HEAD)\n$/);

That's HEAD on the fixture's first push, before origin/main exists. Pin it to whichever the test shows.

Then add a test where AGNIPARIKSHA_REFUSE=1 refuses the push.

Checked

  • The wiring. pnpm exec agnipariksha --lane pariksha --files packages/pariksha/src/semver-range.ts,packages/pariksha/src/codec-registry.ts --no-reuse ran on this Mac with other sessions working:
    • The dry run passed on the two owning suites alone.
    • The mutants. Stryker instrumented 1,049, the same count as #238's CI run 44507830088, and found the same 3 NoCoverage.
    • The blocking set. The gate blocked on 111 mutants, and every one of them is blocking in CI's report too (matched by file, line and mutator). CI blocked on 17 more. Those are most likely mutants that timed out here and were never retried.
  • Side effects. git status was clean after the run, and core.bare is still false.
  • The repository check. pnpm check passes.
  • After merging main (2026-11-22, cca8953). Only pnpm-lock.yaml conflicted. It is now main's lockfile, with pnpm install adding this branch's three root pins. Then:
    • pnpm check, pnpm lint and pnpm guards pass.
    • The hook's own command, pnpm exec agnipariksha --tracked-only --base origin/main, finds nothing to judge in any lane and exits 0. This branch changes no lane source.
    • --lane dvara --files packages/dvara/src/liveness.ts --no-reuse runs on a source main added (#383). The tap dry run passed on its suite, and the run took 28 s. It ended 155 killed of 162, with 7 survivors blocking. Those survivors are in main's code, so they show the old-survivors effect above. Once the hook is on, the next push touching liveness.ts meets them.
    • git status was clean after that run.
  • After aa7cefb. The same dvara run on a clean install gives the same verdict, 155 killed of 162, and dvara's tsconfig.json extends a file outside its package. The run in a checkout that has the stale link is below.
  • The hook itself. scripts/githooks.test.mjs runs the hook in a fixture repository, and passes with de661e8: 14 of 14. Its two new tests fail against the old hook. This worktree's own pushes ran the main checkout's .githooks, because its config.worktree sets an absolute core.hooksPath, so they never exercised the new stage.

Load is the open problem

The wiring check's pair run took 24 minutes on a busy Mac and was refused: its timeout retries passed their 15-minute budget, with 17 test runners. pariksha's limit of 400 now sends that pair to CI. But a lane under its limit can still slow the same way when the Mac is busy.

On the quiet Mac the same pair took 6.6 minutes, so load made it 3.6 times slower. Other sessions working is the normal state when an agent pushes, so the cut-off alone won't keep a push quick when the Mac is busy. No concurrency cap was tried: the Mac went back to load 17 before the run. pariksha's 23 retries suggest a cap would help. Try one with concurrency: 8 in stryker/lane.mjs on the pair, then re-derive pariksha's 400. If pushes stall, the next levers are a lower maxLines, or a cap in stryker/lane.mjs.

Pushes also queue. agnipariksha allows one run per machine, across every worktree: a second run waits, and refuses after 30 minutes. With the hook on, sessions' pushes wait behind each other. Behind a 24-minute run, the next push has 6 minutes before it is refused.

Slice: #272

🤖 Generated with Claude Code