fix(viewer): retire work when the selected review changes
Changing a candidate or authentication token could keep the previous review draft active. A retired Open review failure could toast into the replacement, and an older Refresh response could overwrite a newer result containing a posted comment. Changing clash results left an earlier classification running and able to publish into the next review.
Key the layer review lifetime by candidate, ref and collab token. Keep single-flight ownership checks around registry writes and their error notices. Give review reads latest-wins tickets, invalidated when their owner retires, so older successes and failures cannot replace newer comments. Abort and reset clash classification when its result or chat model changes.
Switching the chat model mid-run cancels classification and discards its partial work. Tokens already spent on that cancelled run are lost.
The new regressions were confirmed failing before the fix. Mutation checks below were rerun against the final implementation.
Validation at 835ccef073b1a4033166034fce29483cd24750df on Pop!_OS (Node 24.22.0, pnpm 10.8.1). Every command below ran under an 8 GiB memory cap, zero swap and a two-CPU quota. Root typecheck:ci checks viewer and viewer-embed, including their test sources, against the prepared dependency artifacts. No Rust/WASM build was run.
| Command | Result |
|---|---|
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- env TEST_PATTERN='LayerReviewSection|ClashClassifyAll|ClashGroupReview|components/viewer/layers/|lib/assistant/clash-classify|lib/layers/registry-client' pnpm test --filter=@ifc-lite/viewer --only | 45 passed; 0 skipped |
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- env NODE_OPTIONS=--max-old-space-size=8192 TURBO_CONCURRENCY=1 pnpm typecheck:ci | Passed |
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- env AEE3_LINT_TSC_LOCK=/tmp/aee3-tsc-review.lock NODE_OPTIONS=--import=file:///tmp/aee3-serialize-tsc.mjs pnpm lint | Passed (including unused locals; compiler children serialized) |
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- node scripts/check-module-size.mjs | Passed |
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- node scripts/check-source-text-assertions.mjs | Passed |
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- node --test scripts/check-unused-locals-baseline.test.mjs | Passed |
systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 -p CPUQuota=200% -- node scripts/pre-handoff.mjs | Passed |
The final review gate used the lane rules’ direct 8 GiB fallback after its disk-refused queued request was cancelled and finalized; no benchmark or foreign job was interrupted.
Preparation: each TypeScript dependency build used the same scope, via pnpm build --filter=<package> --only, for @ifc-lite/{data,wasm-lifecycle,geometry,mutations,export,cache,clash,create,collab,cli,renderer}.
Pre-handoff skipped coverage: SKIPPED retained-free viewer: apps/viewer/dist absent; build the default viewer first.
The first sources lint attempt exceeded the 8 GiB scope because the two unused-locals compiler children overlapped. Its failed receipt is preserved; the review gate was stopped before repeating that profile. The final complete gates serialize only those compiler children with the following private preload; all existing lint checks, compiler arguments, and baselines are unchanged. A three-process fixture confirmed the lock covers each compiler’s full lifetime.
Lint compiler serialization preload
import { openSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
// Bound the existing lint worker pool's compiler overlap without changing diagnostics.
if (process.argv[1]?.endsWith('/typescript/bin/tsc')) {
const path = process.env.AEE3_LINT_TSC_LOCK;
if (!path) throw new Error('AEE3_LINT_TSC_LOCK is required for serialized lint');
const descriptor = openSync(path, 'a', 0o600);
const result = spawnSync('flock', ['--exclusive', '3'], {
stdio: ['ignore', 'ignore', 'pipe', descriptor],
});
if (result.error || result.status !== 0) {
throw new Error(`Cannot acquire TypeScript lint lock: ${result.error?.message ?? result.stderr}`);
}
// Keep this descriptor open: Linux flock follows the shared open description
// after the flock child exits, and the compiler's exit releases it.
}
Mutation command, one restored mutation at a time: systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0 pnpm test --filter=@ifc-lite/viewer --only, with TEST_PATTERN set to ClashClassifyAll, LayerReviewSection.single-flight, LayerReviewSection|ClashClassifyAll.
Mutation checks:
| Guard | Result / named failing test |
|---|---|
review-key | Killed — C-1 candidate replacement hides the old review and ignores its late refresh |
review-open-after-push | Killed — C-1 retiring a review during push prevents the next registry operation |
review-open-refresh | Killed — C-1 retiring a review during open prevents the next registry operation |
review-post-refresh | Killed — C-1 retiring a comment during post performs no stale follow-up |
review-post-toast | Killed — C-1 retiring a comment during refresh performs no stale follow-up |
clash-result-dep | Killed — C-10 replacing the result aborts the old classification and resets its controls |
clash-model-dep | Killed — C-10 selecting another model aborts the classification owner |
clash-abort | Killed — unmounting during a full-run classification aborts the in-flight request and reports nothing |
clash-invalidate | Killed — unmounting during a full-run classification aborts the in-flight request and reports nothing |
clash-reentry | Killed — C-10 same-tick classification presses start one request |
clash-reset-chunks | Killed — C-10 replacing a completed review clears its progress, merged summary and normalization consent |
clash-reset-run | Killed — C-10 replacing a completed review clears its progress, merged summary and normalization consent |
clash-reset-consent | Killed — C-10 replacing a completed review clears its progress, merged summary and normalization consent |
clash-reset-error | Killed — C-10 replacing a review clears the previous classification error |
review-open-error | Killed — #9566 a retired Open review push failure cannot toast into another candidate |
review-read-ticket | Killed — #9566 older success refresh cannot overwrite a posted comment |
review-read-success | Killed — #9566 older success refresh cannot overwrite a posted comment |
review-read-error | Killed — #9566 older failure refresh cannot overwrite a posted comment |
review-read-retire | Killed — #9566 token/client replacement resets the draft and ignores an old-client 401 |
review-token-key | Killed — #9566 token/client replacement resets the draft and ignores an old-client 401 |
Survivors: none in these 20 checks.
Unverified / scope findings: Hosted registry integration and browser GPU rendering were not exercised. The tests mount real review/classification components, use the real local layer store and classification planner/runner, and defer the external transport.
🤖 Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Layer and clash review work now resets when the selected review or model changes, preventing progress, comments, errors, or results from a previous selection from carrying over.
- Outdated review refreshes and actions no longer overwrite newer content or show stale success notifications.
- Clash classification stops when its results are replaced or the selected model changes, and rapid repeated starts no longer trigger duplicate runs.