Skip to content

Flag effects that write reactive state through a same-file helper - #4412

Merged
mstomar125 merged 1 commit into
mainfrom
effect-flag-followup
Dec 1, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
effect-flag-followup

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

What

Four allowlisted effects assign reactive state through a same-file helper but were not flagged writesState, so MAX_STATE_WRITING_EFFECTS (11) understated the debt. They are now flagged and the cap is 15. No effect is removed or rewritten (removal stays tracked in c6cb44c4).

Newly flagged (each read in source):

  • relationship-viewer-modal.svelte, effect calling closeAdd: assigns addGroupKey, addQuery, addResults, addSearching, addAllLinked, addStaged, addEdgeDraft (all $state).
  • relationship-viewer-modal.svelte, effect calling resetTransient and load: resetTransient assigns edgeDrafts, selectedKey, expandedRows, add* fields, mutationError; load synchronously assigns phase, view, errorMessage before its first await.
  • import-options-modal.svelte, effect calling resetToDefaults: assigns modalState, phase, progress, result, errorMessage.
  • pane-content.svelte (found by the re-scan, not in the reviewer's list): the effect calls loadViewerForNodeType (inside untrack), which sets viewerLoading ($state) before its first await and viewerComponents/viewerLoadErrors when it settles. The old drives text said "both write the pane's viewer maps when they settle"; corrected.

The checker header and AGENTS.md now say the flag covers direct assignment and assignment through a same-file helper, and that state written through imported modules or callback props is not detected and relies on review.

Not flagged (judgement, for the reviewer)

  • ai-chat-pty-session.svelte: the listen callback sets $state sessionEnded, but only later in an async event, not when the effect runs.
  • typed-form-shell.svelte (relationships.load) and app-shell.svelte (conflictsStore.load, seedUpdatesStore.load) call imported modules; not detectable by this rule and not verified here (their state classes were not read).
  • conflict-toast.svelte: helper only touches a plain Map and timers; the store dismiss runs in a timeout.

Verification

  • bun scripts/check-effect-allowlist.ts: pass
  • bun test scripts/: 1729 pass, 0 fail
  • bun run quality:scripts:check: pass
  • Mutations (each reverted): cap 15 to 14 fails 3 tests; removing the import-options flag fails the new flagged-through-helper test; loosening the cap comparison to > MAX + 1 fails the existing cap test and the new helper-cap test.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE at ff10e2d

Independent review at that exact head, in my own worktree. The 4 new flags are correct and the cap of 15 matches the rule as written. I found should-fix items below, but none is a blocker for this PR.

Verified by reading the effect body and the helper (all 4 flags are true and accurately worded)

  1. relationship-viewer-modal.svelte, effect at :258 if (addGroupKey && !addGroup) closeAdd(). closeAdd (:495) assigns 7 $state fields: addGroupKey, addQuery, addResults, addSearching, addAllLinked, addStaged, addEdgeDraft. The reason lists exactly these.
  2. relationship-viewer-modal.svelte, effect at :258 resetTransient() / void load(nodeId). resetTransient (:269) assigns $state fields. load (:283) sets phase, view and errorMessage synchronously before its first await. All of them are $state (:128-174). The reason text is accurate.
  3. import-options-modal.svelte, effect at :49 calls resetToDefaults (:57), which assigns modalState, phase, progress, result and errorMessage (all $state, :34-38). Accurate.
  4. pane-content.svelte, effect at :161 calls loadViewerForNodeType inside untrack. It sets viewerLoading (:57) before its first await, then viewerComponents and viewerLoadErrors on settle. All three are $state (:36-38). The reason text is accurate. The reworded drives ("the import writes the pane's viewer maps when it settles") is also correct. hydrateNode writes no local state.
  5. The removal id c6cb44c4 is the same one the existing entries use.

Header and AGENTS.md text: both match the code. The same-file-helper wording is true for the 4 flags. The "imported module or callback prop is not detected" caveat is stated honestly. Only scripts/AGENTS.md changed (3 files: AGENTS.md, the checker, its test). No effect was removed or rewritten, and no packages/ files changed.

What I ran

  • bun scripts/check-effect-allowlist.ts: every effect is covered.
  • bun test scripts/check-effect-allowlist.test.ts: 22 pass.
  • bun test scripts/: 1729 pass, 0 fail.
  • bun run quality:scripts:check (eslint and tsc): clean.
  • Mutations, each reverted afterwards: cap 15 to 14 failed 3 tests (committed allowlist well formed, repository holds exactly the allowlisted effects, new flags test). Cap 15 to 16 failed the new "flags the state written through same-file helpers" test, which asserts cap equals the flagged count. Deleting the resetToDefaults flag failed the same new test.
  • Not run: the two-test claim of "cap counts a helper-flagged effect" was only read. It is a plain re-run of the existing cap logic.

Findings

  1. Should-fix (follow-up, not blocking), ai-chat-pty-session.svelte:103-121. The effect registers listen(...), and the callback sets sessionEnded = true ($state, :73). The write happens later, inside a closure that sits in the effect body. It is documented in the drives text but not flagged or counted. The stated rule says "in its body", so this is ambiguous. Either flag it (cap 16) or add one sentence to the header saying writes from callbacks that run on later events are not counted. For consistency: the confirmation-card effects do write in .then and timer callbacks, but they also write synchronously, so they are flagged for a different reason.
  2. Should-fix (follow-up), writes through imported classes that happen synchronously when the effect runs. The PR's caveat says these are not detected, but a few are real:
    • typed-form-shell.svelte:84-94, relationships.load(nodeId). NodeRelationshipsState.load (services/node-relationships-state.svelte.ts) sets this.view = null and this.loadFailed = false, both $state, before its fetch. The effect does not read them, so there is no loop, but it is a state write.
    • code-block-node.svelte:130 and :137, renderer.render(...) and renderer.clearPreview(). CodeBlockRenderer (code-block-renderer.svelte.ts:40-95) sets highlightedLines, mermaidSvg, mermaidError and previewSvg/previewError synchronously on the plaintext, mermaid and clear paths. The comment at :128 says the effect "writes no reactive state itself", which is only true of its own body.
    • If the author wants the cap to be a ceiling on every state-writing effect, the count would be 18 (or 19 with the pty one). Under the stated rule, which excludes imports, 15 is correct.
  3. Verified not state-writing, so the author was right to leave these unflagged:
    • app-shell.svelte:111: conflictsStore.load and seedUpdatesStore.load only write records, loaded, updates after an await invoke(...), so the effect body causes no synchronous write. loadConflicts also calls conflictNotifications.add in a later .then.
    • conflict-toast.svelte: only a plain Map and timers (dismiss is called from scheduleAutoDismiss, a timer callback).
    • ai-chat-acp cardShown is a plain let (:125).
    • Click, scroll and focus handlers, pinReachableNodes (plain registry), and chat-markdown, table-node, onboarding-wizard, relationship-field and the textarea-controller effects write no $state. I skimmed controller.initialize and updateContent in the TextareaController class and did not trace them to the end.
  4. Nit: the new test identifies same-file-helper flags with writesState?.includes("through"). That is brittle if the wording changes. A named field or a writesVia marker would be sturdier.
  5. Nit: the reason for the resetTransient/load entry says "add* fields" and omits addChooserOpen. This is harmless.

Conclusion: the PR does what it says and the numbers are right under its rule. I treated the imperfect count as non-blocking because the limitation is stated in the header and AGENTS.md. Items 1 and 2 are worth a small follow-up, either by flagging those effects or by tightening the wording.

🤖 Generated with Claude Code

…the effect allowlist

Four allowlisted effects assign $state through a helper they call
(closeAdd, resetTransient/load, resetToDefaults, loadViewerForNodeType) but
were not marked writesState. Mark them and raise MAX_STATE_WRITING_EFFECTS
from 11 to 15 to the true count. The checker header and AGENTS.md now say the
flag covers direct and same-file-helper writes and that imported modules and
callback props rely on review.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the effect-flag-followup branch from ff10e2d to 6d4b2ed Compare December 1, 2026 14:14
@mstomar125
mstomar125 merged commit 30c1298 into main Dec 1, 2026
@mstomar125
mstomar125 deleted the effect-flag-followup branch December 1, 2026 14:14
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