Repository navigation
Description
Found by the writer-state matrix in #1097. Real filesystem, temp project, SEQUANT_TEMPLATES_DIR = the repo's templates/.
What happens
When the destination of a sequant-owned file is an existing symlink, several writers call writeFile on it. writeFile follows the link, so the link stays and its target is overwritten with template content. #1053 fixed this for scripts/dev in copyTemplates' copyDir; the other write sites still do it.
| Destination | Writers that write through a local or foreign symlink |
|---|---|
.claude/settings.json |
init, init --force, sync, sync --force, update, update --force (copyTemplates writes it directly, outside copyDir; update writes every file with a bare writeFile) |
.claude/skills/spec/SKILL.md and every other copyDir destination |
update, update --force only (sync/init replace the link) |
scripts/dev/<x>.sh (copy and link routes) |
update, update --force only |
Repro (foreign symlink): ln -s /somewhere/else/file .claude/settings.json && sequant sync. /somewhere/else/file now holds the template; .claude/settings.json is still a symlink.
Expected
Same rule as #1053: an existing symlink is replaced, never written through, and its target is left alone.
The matrix pins the current behaviour (letter W in src/lib/__tests__/writer-state-matrix.test.ts) and lists this under KNOWN_DEFECTS. Fixing it fails those cells until the grid is updated.
Also in scope: a directory at the destination (folded from #1124)
Same writer-state matrix (#1097), same code paths. When a directory sits where a template file goes, the writers reject with a raw EISDIR (or EEXIST from symlinkDir on the link route) and abort partway, dry-runs included: computeTemplateChanges reads the path as a file, so sync --dry-run and update --dry-run crash instead of reporting the collision. Affected destinations: .claude/settings.json, .claude/skills/*/SKILL.md, .claude/memory/constitution.md (every writer); .sequant/settings.json, .mcp.json, .gitignore (init, init --force); scripts/dev/<x>.sh (init --force, sync, update).
Expected: a named, actionable error per destination (<path> is a directory; move it aside) or a documented skip, and a dry-run that reports the collision instead of throwing. The matrix pins this as letter X under KNOWN_DEFECTS; the fix updates those cells alongside the W cells above.
Acceptance criteria
Tier: judgment · Graph: 2026-09-w3 (docs/internal/graph-2026-09-w3/issue-graph.md)
- AC-1: no writer (
init,sync,update, with and without--force) writes through an existing symlink at a sequant-owned destination; the link is replaced and its target stays byte-identical — Verify:npx vitest run src/lib/__tests__/writer-state-matrix.test.tswithsymlink-written-through-at-sequant-ownedremoved fromKNOWN_DEFECTS - AC-2: a directory at a template destination yields the named error
<path> is a directory; move it aside(or a documented skip) with no partial write, andsync --dry-run/update --dry-runreport the collision instead of throwing — Verify:npx vitest run src/lib/__tests__/writer-state-matrix.test.tswithdirectory-crashes-writerremoved fromKNOWN_DEFECTS - AC-3: the foreign-symlink repro above (
ln -s <outside file> .claude/settings.json && sequant sync) leaves the outside file's content unchanged — Verify: a named case insrc/lib/__tests__/writer-state-matrix.test.tsasserting the foreign file's bytes survivesyncandupdate - AC-4: build and full suite green — Verify:
npm run build && npm test
Activity
admarble commentedon Sep 25, 2026
Runner context (graph 2026-09-w3,
docs/internal/graph-2026-09-w3/issue-graph.md, PR #1154) — these rules apply to the spec, exec AND qa phases:npm test. Verify each AC with its own verify command and run only the named test files. The runner runs the full suite once per PR, serially — three phase agents share this machine and a full-suite call inside a phase can hit the 30-minute no-progress wall.timeout; neverrun_in_background.<!-- SEQUANT_MUTATION: {...} -->marker needsfailedTestto start with the test file path (src/.../x.test.ts > describe > case), or /qa §6i floors it to AC_NOT_MET.[Unreleased]line.admarble commentedon Sep 25, 2026
/spec — Plan (#1122)
Complexity: Standard (4 ACs, 4 directories)
AC Quality Check
lintAcceptanceCriteria→ 4/4 pass, 0 flagged. Two parser-level notes:verificationMethod: "manual". This wave's style uses— Verify:;ac-parser.ts:200(EVIDENCE_CLAUSE_RE) only recognizesEvidence:, so the declared-evidence path (feat(spec/qa): explicit Evidence: clause on ACs — declared verification replaces keyword inference #938) never fires even though AC-1/2/3 name realnpx vitestcommands. Affects bug(worktree): new-feature.sh and sequant run derive different branch names for the same issue #1145 and test: state-hook.test.ts writes a real /nonexistent/path/state.json when run as root, poisoning state-utils.test.ts #1141 identically — follow-up, not this issue.Scope Assessment
Non-Goals: not present in the issue body.
Verdict: SCOPE_WARNING — clustering artifact: the detector split AC-3 into "config" and AC-4 ("build and full suite green") into "ui". Real spread is
src/lib/+src/commands/+ one test file.The two defects, located
AC-1 (symlink write-through), 24 pinned cells — two call sites:
src/lib/templates.ts:1127—copyTemplateswrites.claude/settings.jsonwith a barewriteFile, outsidecopyDir, so it never reaches the fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053 guard attemplates.ts:1051. → 8 cells (init/sync x ±force x 2 symlink states).src/commands/update.ts:308— the applySet loop is a barewriteFilefor every file. → 16 cells (settings, skill, scriptsCopy, scriptsLink x update ±force x 2 states).Both go through
src/lib/fs.ts:51 writeFile=ensureDir+fsWriteFile, andfsWriteFilefollows the link.AC-2 (directory at destination), 32 pinned cells:
fileExistsusesaccess, which returns true for a directory, so every guard gated on it falls into areadFile/writeFilethat throwsEISDIR:templates.ts:1040(copyDiruser-owned check ->readFile),templates.ts:1060(writeFile)templates.ts:830(symlinkDircopy fallback;createSymlinkgivesEEXISTon the link route)templates.ts:643—computeTemplateChangesis the dry-run crash:fileExiststrue ->readFile-> EISDIR, before any preview is printedinit.ts:132(updateGitignore'sreadFile),settings.ts:1276(createDefaultSettings)Implementation Plan
Phase 1 — symlink replacement (AC-1, AC-3)
src/lib/fs.ts: makewriteFilereplace an existing symlink instead of following it —lstat,unlinkwhenisSymbolicLink(), thenfsWriteFile. One site fixes both AC-1 call paths and cannot be regressed by a future writer. (Alternative: awriteFileReplacingSymlinkhelper applied attemplates.ts:1127+update.ts:308only — Open Question 1.)templates.ts:1051, or keep it with a comment pointing at thefs.tsguarantee. KeepsymlinkDir'sremoveFileOrSymlink— it precedescreateSymlink, notwriteFile.#1053: foreign symlink in copy modeblock: foreign symlink at.claude/settings.json, runsyncandupdate, assert the outside file's bytes are unchanged and the destination ends as a regular file with template content.Phase 2 — directory collision (AC-2)
lstat-basedisDirectory(path)tosrc/lib/fs.ts(fileExistscannot answer this).computeTemplateChanges: check beforereadFile; emit a newTemplateChange.statusvalue"directory-collision"(union attemplates.ts:454).sync.ts/update.ts: filter that status out of the applySet and report it in its own block with the exact string<path> is a directory; move it aside. Do not list it underModified files:/New files:—printedDecisionwould read that asoand break theDECISIONSrows.copyDir,symlinkDir's copy fallback,updateGitignoreandcreateDefaultSettings, each skipping the destination rather than throwing.Phase 3 — re-pin the grid (AC-1, AC-2)
KNOWN_DEFECTS(writer-state-matrix.test.ts:456).GRID. With thefs.tsfix these are the exact deltas;localSymlinkandforeignSymlinkare identical in every row:settingsW W W W W WT T T T T TskillT T T T W WT T T T T Tconstitution= = = T = W= = = T = TsequantSettings= W = = = == T = = = =agentsMd= W = W = == T = T = =scriptsCopyT T T T W WT T T T T TscriptsLinkL L L L W WL L L L T TgitignoreandmcpJsonstayM M = = = =(classifyreturnsMfor a merged regular file too). Alldirectoryrows become= = = = = =.=.Phase 4 — verification
npx vitest run src/lib/__tests__/writer-state-matrix.test.ts(63 cells x 2 suites — run this file alone, notnpm test, per the runner-context comment).npm run build && npm testonce, foreground, with atimeout.Design Review
src/lib/fs.tsfor the symlink rule (36writeFilecall sites across 14 files inherit it);computeTemplateChangesfor the directory rule, the single reader both dry-run paths share.expect(dry.threw === null).toBe(apply.threw === null), and AC-2 requires the dry-run not to throw — so apply must not throw either. Further,classifyreturnsXwhenever a writer threw with a directory before and after, so throwing keeps all 32 cells atXanddirectory-crashes-writercannot be removed fromKNOWN_DEFECTS. Only the skip branch satisfies AC-2 as written: print the exact message, skip the destination, continue.28bc0748), which madecreateProjectMcpJsonreturn early without writing and report the file untouched — which is whymcpJson'sdirectoryrow already reads= = = = = =while every other destination readsX.writeFilefor everyone?" The 24 cells span two unrelated call sites and the class already recurred once after fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053 fixed it locally; a local fix leaves.sequant/settings.json,AGENTS.mdand the constitution still writing through links.Feature Quality Planning
Wcells sit at user-owned destinations (constitutionx2,sequantSettingsx2,agentsMdx4) — same data-loss bug, uncounted because thesymlink-written-through-at-sequant-ownedinvariant filters onownershipPolicy() === "sequant-owned". Thefs.tsfix flips all 8; the grid deltas above already include them..mcp.jsonusesfs.writeFileSyncdirectly (mcp-config.ts:243,356,471), so itsMcells at symlink states stay write-throughs. Outside AC-1's literal scope (mergepolicy) and no invariant counts it — recommend a follow-up issue rather than widening scope here.SEQUANT_MUTATIONrecord — mutation: restore the barefsWriteFileinfs.ts;failedTestmust start withsrc/lib/__tests__/writer-state-matrix.test.ts > ...or /qa §6i floors it to AC_NOT_MET.Derived AC
SEQUANT_MUTATIONmarker for AC-3,failedTeststarting with the test file pathConflict Risk Analysis
No file overlap.
feature/1122-...exists ataa865de3with an empty diff. In-flight siblings touchtemplates/scripts/new-feature.sh+ a new test (#1145) and.github/workflows/upstream-assessment.yml(#1153). Shared merge point isCHANGELOG.md[Unreleased]only — one line, mergemainin rather than rebasing.#1145 edits
templates/scripts/new-feature.sh, which the matrix reads at test time as a fixture. Content-agnostic (it compares against that same template), so no ordering constraint.Open Questions
fs.writeFileglobally, or a helper at two sites? Recommendation: globally. Impact if wrong: a caller that intends to follow a symlink starts replacing it — I found none among the 36 sites, and the alternative's failure mode is another fix(sync): copy-mode sync leaves existing machine-specific scripts/dev symlinks in place, and doctor's hint loops back to sync #1053-class recurrence.=enough? Recommendation:=, with a legend note that a named skip leaves the destination byte-identical. Impact: cosmetic..mcp.jsonwrite-through follow-up now or after merge? Recommendation: after, referencing this PR.Recommended Workflow
Phases: exec -> qa
Quality Loop: enabled
Reasoning: Nothing for testgen to stub — AC-1/2 modify an existing 1,137-line matrix test and AC-3 adds a case to it. Quality loop on: SCOPE_WARNING, and Phase 3 re-derives 63 grid cells by hand, exactly what a second pass catches. Per the runner-context comment, qa verifies each AC with its own command and must not run
npm test.docs(#1153): graph w3 execution log — #1145 blocked by #1122, #1153 h…
docs(#1122): troubleshooting entry for the directory-at-destination skip
admarble commentedon Sep 25, 2026
Runner note (resume): the first exec phase hit the MCP 30-minute no-progress wall. Its work is on
origin/feature/1122-…(4 commits, headaef6c9db), and the worktree was reaped. The resumed exec should build on those commits rather than start over. Finish the remaining ACs, run only the named test files (src/lib/__tests__/writer-state-matrix.test.ts, the canary projectnpx vitest run --project canary), and open the PR. Do not run the fullnpm testin exec or qa; the runner runs it once per PR. Note: #1145 depends on this PR, because the requiredcanarycheck needssyncto replace thescripts/dev/*.shsymlink.admarble commentedon Sep 25, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
Gaps:
docs(#1159): graph w3 — #1145 blocked by #1159 not #1122; #1160 filed
admarble commentedon Sep 25, 2026
Runner verification (PR #1157, head
aef6c9db) — QA: AC_MET_BUT_NOT_A_PLUS.KNOWN_DEFECTSis empty inwriter-state-matrix.test.ts.npx vitest run src/lib/__tests__/writer-state-matrix.test.ts→ 649 passed.aef6c9dbshowstest,typecheckandcanaryall success.npx vitest run --project canarylocally → 4 passed..mcp.jsonwrites bypass the new guard. Filed as fix(mcp-config): .mcp.json writes still follow an existing symlink (#1122 follow-up) #1160, out of scope here.importOriginalspread ininit.test.ts/sync.test.ts): noted, not changed.fix(#1122): writers replace a symlink and skip a directory at a templ…
docs(#1153): graph 2026-09-w3 plan for #1145, #1153, #1122 and #1141 (#…