Skip to content

Add check-effect-allowlist: fail on an effect outside a reviewed allowlist - #4411

Merged
mstomar125 merged 1 commit into
mainfrom
effect-allowlist-checker
Dec 1, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
effect-allowlist-checker

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

NodeSpace task: e4d933d6 (a new effect outside a reviewed allowlist fails the push check).

What

scripts/check-effect-allowlist.ts scans non-test .svelte/.ts/.js under packages/desktop-app/src/ for $effect(, $effect.pre( and $effect.root(, after blanking comments (line, block, HTML) and string literals, and compares the count per file with EFFECT_ALLOWLIST. Each entry names the file and one element per effect with the external system it drives.

  • Fails on a file with more effects than listed (or no entry), naming file:line of each call site.
  • Fails on an entry whose file has fewer effects than listed (stale).
  • An effect that assigns reactive state in its own body is listed only with a writesState reason ("removal tracked in c6cb44c4"); MAX_STATE_WRITING_EFFECTS = 11 caps them so the set can shrink but not grow.
  • Wiring: push check (scripts/test-gate.ts, same shape as the lifecycle/key-prefix checks), bun test scripts/ (real-repo test), and gate-scope.ts now routes a frontend change to the scripts tier (scope.frontend implies scope.scripts; its test and the describeScope test updated). Comments in test-gate.ts and AGENTS.md that said the scripts tier is skipped for frontend-only diffs are corrected.
  • AGENTS.md gets an "Effects only push out" rule describing the check.

No component was changed: state-writing effects are listed, not removed (that is c6cb44c4).

Counts

46 production effect call sites in 30 files, matching the issue. 11 assign reactive state directly in the effect body (settings-pane, collection-move-dialog, database-name-dialog, node-ref-preview, kanban-view, person-schema-form x2, relationship-viewer-modal x2, remote-tool-confirmation-card x2), matching the issue's 11. Not flagged, but they write state through a call or callback and say so in drives: import-options-modal (resetToDefaults), relationship-viewer-modal's closeAdd and load effects, pane-content (async viewer maps), ai-chat-pty-session (listener sets sessionEnded), code-block-node render effects (CodeBlockRenderer state).

Not done

The reactivity decision and the code-quality standard are NodeSpace workspace nodes, not files in this repo; they are not updated here (the daemon was not reachable, and I did not write to the workspace). Proposed text is in the author's report.

Verified

  • bun test scripts/: 1727 pass, 0 fail. bun run quality:scripts:check clean. bun run scripts/check-effect-allowlist.ts passes on the tree. The push check ran on push and passed.
  • Each new test was mutation-checked by breaking the checker (comment blanking, string blanking, HTML comments, stale detection, uncovered detection, off-by-one threshold, test-file exemption, pre/root matching, cap, empty drives/reason, duplicate entries, line numbers) and the gate-scope line; each mutation failed at least one test.
  • Not run: the merge gate.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE at dbeac1b

Independent review at this exact head (base bbf5a82, up to date with origin/main, mergeable).

Ran myself in a clean worktree:

  • bun run scripts/check-effect-allowlist.ts: passes. bun test scripts/: 1727 pass, 0 fail. bun run quality:scripts:check (eslint + tsc): clean.
  • Own count, different method: plain grep -rnE '\$effect' over packages/desktop-app/src minus test paths, then dropped comment-only lines and kept only $effect(, $effect.pre(, $effect.root( call lines. Result: 46 call sites in 30 files. Compared to EFFECT_ALLOWLIST file by file with a script: 0 differences, no extra files, 11 writesState entries (matches the cap). The remaining grep hits are test setup files, tests/ dirs and 3 doc-comment lines in header-node.svelte.
  • Stray $effect(() => {}) in a scratch .svelte: fails with rc=1, "zz-scratch.svelte:2: $effect(" and the explanation. Removing the effect from settings-pane.svelte: fails as "stale entry". Both reverted, worktree clean.
  • Breaking attempts on findEffects: $effect.tracking(), $effect.active(), $effect.pending(), $effectful(, foo$effect(, x.$effect(, $effects(, aliasing: not counted. .pre, .root, multi-line calls, $effect (, URL in a string before an effect, comment markers inside strings, // in an escaped regex: counted correctly. Scope: latest.ts is scanned (not mistaken for a test), .test.ts, tests/, __tests__/, .spec.ts are exempt.
  • Wiring: test-gate.ts runs the checker as a push-check stage and run() exits non-zero on failure; gate-scope sets scripts=true for any frontend change (test + describeScope assertions updated accordingly).
  • Read the bodies of all 11 flagged effects (all do write $state directly: confirmed) and 19 unflagged ones.

Findings

  1. should-fix (not blocking), relationship-viewer-modal.svelte:254 and :258, import-options-modal.svelte:49. These three unflagged effects write reactive state synchronously in their own body through same-file helpers: closeAdd(), resetTransient() (sets edgeDrafts, selectedKey, expandedRows, addQuery, mutationError, ...) plus load() setting phase/view, and resetToDefaults() (modalState, phase, progress, result, errorMessage). They are listed as "daemon fetch" / "import progress listener" with the reset only mentioned in prose. Under the stated rule these are state-writing effects, so the true count is nearer 14, and the cap of 11 understates the debt. Risk: the cap cannot catch a fourth such effect being added in the same disguise (a state write behind a helper), so the "cannot go up" guarantee is weaker than the docs say. The author's choice is defensible because the board issue says 11, and the entries do disclose it. Suggest: mark these three writesState and raise the cap to 14 now (one-time, with the removal ticket), or state in the checker header that only direct assignments in the effect body count. Other unflagged ones (pane-content, typed-form-shell, pty-session, code-block-node, chat-markdown, app-shell, table-node, acp viewer, PIN effects, conflict-toast) write only plain (non-$state) variables, async callbacks, renderer-store state, or nothing: acceptable.
  2. nit, scripts/check-effect-allowlist.ts blankNonCode: it is a hand-rolled lexer without regex-literal or template ${} awareness, so it can hide an effect only in contrived input: a regex literal containing a backtick (//) blanks everything up to the next backtick, possibly across lines; a quote inside a regex (/['"]/) blanks the rest of that line; ${ $effect(...) }inside a template is not seen;$effect\n((newline before the paren) is not matched. None occurs in today's source (my independent count matched), and nothing hides an effect by accident in normal code. Optional hardening: allow\s*before(`.
  3. nit, cost: frontend-only diffs now run the whole scripts tier (bun test scripts/, 62 files, about 40 s here) in test:changed instead of skipping it. Acceptable (one-time ~40 s on frontend changes, the push check already runs the checker in seconds). The two changed assertions only follow the intended behaviour change (frontend now also sets scripts); they do not weaken coverage, the Rust/skill/md-only cases are untouched.
  4. Docs. AGENTS.md text is accurate against the code (check name, scope, counting per file, stale-entry failure, writesState cap, comments and strings). The reactivity decision and code-quality standard live in the NodeSpace workspace, not the repo; I agree this should not block the merge, provided they are updated as a follow-up (they are the board-graph docs the issue's checklist item refers to).

Trusted without re-running: the removal ticket c6cb44c4 contents, and the PIN registry claim for pinReachableNodes (I read the call sites only).

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Merge queue: #4411 was taken out of the queue — the merge gate failed on it, on top of main. Reproduce by merging or rebasing origin/main and running bun run test:changed, fix, push, and re-run bun run merge 4411.

cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin
  CFLAGS_aarch64_apple_darwin = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin
  CFLAGS_aarch64-apple-darwin = None
  cargo:warning=sccache: error: Server startup failed: File exists (os error 17)
  cargo:warning=Run with SCCACHE_LOG=debug SCCACHE_NO_DAEMON=1 to get more information
  exit status: 2
  cargo:warning=ToolExecError: command did not execute successfully (status code exit status: 2): env -u IPHONEOS_DEPLOYMENT_TARGET LC_ALL="C" "/Users/mayanktomar/nodespace/core/.tools/bin/sccache" "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-macosx" "-mmacosx-version-min=27.2" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/pregenerated" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-gfull" "-DNDEBUG" "-o" "/Users/mayanktomar/nodespace/core/.claude/worktrees/_gate/target/debug/build/ring-02464c93aa49b344/out/a0330e891e733f4e-ecp_nistz.o" "-c" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/fipsmodule/ec/ecp_nistz.c"
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  exit status: 0
  --- stderr
  error occurred in cc-rs: command did not execute successfully (status code exit status: 2): env -u IPHONEOS_DEPLOYMENT_TARGET LC_ALL="C" "/Users/mayanktomar/nodespace/core/.tools/bin/sccache" "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=arm64-apple-macosx" "-mmacosx-version-min=27.2" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include" "-I" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/pregenerated" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-gfull" "-DNDEBUG" "-o" "/Users/mayanktomar/nodespace/core/.claude/worktrees/_gate/target/debug/build/ring-02464c93aa49b344/out/a0330e891e733f4e-ecp_nistz.o" "-c" "/Users/mayanktomar/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/fipsmodule/ec/ecp_nistz.c"
error: script "shape:check" exited with code 101
[stage exited with code 101]

  full output: /var/folders/3w/y9kj522n1_j9wqmt6vl_sb6r0000gp/T/nodespace-gate-logs/_gate-merge-2026-12-01T13-41-33-865Z/shape-check-built-in-shape-snapshot-and-change-log.log

✗ shape:check (built-in shape snapshot and change log) failed — merge blocked.
  Fix the failure, push, and re-run: bun run merge <PR#>

…wlist

scripts/check-effect-allowlist.ts scans non-test source under
packages/desktop-app/src/ for $effect, $effect.pre and $effect.root calls
(comments and strings blanked first) and compares the count per file with
EFFECT_ALLOWLIST, which names the external system each effect drives.
Fails on an uncovered call (file and line) and on a stale entry. Effects
that write reactive state carry a writesState reason and are capped by
MAX_STATE_WRITING_EFFECTS.

Wired into the push check (test-gate.ts) and bun test scripts/; the gate
scope now routes a frontend change to the scripts tier. AGENTS.md describes
the rule and the check.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the effect-allowlist-checker branch from dbeac1b to 34f216a Compare December 1, 2026 13:56
@mstomar125
mstomar125 merged commit 52cebe0 into main Dec 1, 2026
@mstomar125
mstomar125 deleted the effect-allowlist-checker branch December 1, 2026 13:56
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