Skip to content

[2.0 rc.15 / next] GRAPH_GROWTH reports a keyed cache filling with new keys as a leak, and a cache has no way to say what it is #4035

Closed

Description

@rvlzzr

Summary

A cache that keeps entries by key reports GRAPH_GROWTH when visits fill it with new keys, and the message says a visit left a createRoot() behind with no dispose. This is the usual shape of a data layer's entity cache: one entry per item, each under its own root so it can be evicted, all under the cache's long-lived root. Since #4020 (fixing #4007), a series must also climb in what outlived each navigation, but a cache's entries are alive when the next navigation starts and survive it, exactly as a leaked root would. Nothing in the graph's shape tells a cache filling up from a leak, and there is no way for the cache to say what it is. OBSERVE.exclude is meant for an observer's own subtree and silences every diagnostic under it, not only this check.

Reproduction

solid-js 2.0.0-rc.15, no DOM. Each visit to /items/:page lists two items the cache hasn't seen; / sits between visits.

import {
  OBSERVE,
  createEffect,
  createMemo,
  createProjection,
  createRenderEffect,
  createRoot,
  createSignal,
  flush,
  getOwner,
  runWithOwner,
} from "solid-js";
import { attribution } from "solid-js/attribution";

const variant = process.argv[2] ?? "A";
attribution.enable({ log: false });
const findings: { route: string; grew: string[] }[] = [];
OBSERVE!.diagnostics.subscribe((event) => {
  if (event.code === "GRAPH_GROWTH") findings.push(event.data as { route: string; grew: string[] });
});

// An entry per item (a signal and a projection of it), each under its own
// root so it can be evicted, all under the cache's root.
const cache = createRoot((dispose) => ({ owner: getOwner()!, dispose }), {
  cache: variant !== "A",
});
const entries = new Map<number, { value: number }>();
const fill = (id: number) =>
  runWithOwner(cache.owner, () =>
    createRoot(() => {
      const [value] = createSignal(id);
      entries.set(
        id,
        createProjection<{ value: number }>(
          (draft) => {
            draft.value = value() * 2;
          },
          { value: 0 },
        ),
      );
    }),
  );

const leaked: (() => void)[] = [];
const app = createRoot((dispose) => {
  const [location, setLocation] = createSignal("/");
  createRenderEffect(
    () => (location(), [...entries.values()].reduce((sum, entry) => sum + entry.value, 0)),
    () => {},
  );
  return { setLocation, dispose };
});
flush();

const navigate = (name: string, to: string, before?: () => void) => {
  OBSERVE!.attribution.withOrigin({ kind: "navigation", name, to }, () => {
    before?.();
    app.setLocation(to);
  });
  flush();
};
for (const page of [1, 2, 3]) {
  navigate("/items/:page", `/items/${page}`, () => {
    fill(page * 2 - 1);
    fill(page * 2);
    if (variant === "C")
      runWithOwner(null, () =>
        createRoot((dispose) => {
          leaked.push(dispose);
          const [n] = createSignal(0);
          createEffect(n, () => {});
          createMemo(() => n() + 1);
        }),
      );
  });
  navigate("/", "/");
}
console.log(variant, findings);

Run with node --conditions=browser --conditions=development repro.ts <A|B|C>.

Variant 2.0.0-rc.15 2.0.0-rc.15 with the fix below
A: the cache under a plain root reports reports
B: the cache root created with { cache: true } reports quiet
C: B, plus a detached root left behind on every visit reports reports

Without the fix the option doesn't exist, so B is the same as A.

Cause

walkGraph (packages/signals/src/core/attribution.ts) counts every node alive at a navigation's start and still alive at its settle as survived, whoever owns it. Projections also record no owner: createStore puts its owner in storeOwners, and store property nodes are stamped from it, but createProjection doesn't, so a projection's property nodes have none.

Expected

A cache can declare itself, and what it keeps is left out of what survived, while a leak beside it still reports. Related: #4007, #4020.

Possible fix

Let a root say it is a cache: createRoot(fn, { cache: true }) (and createOwner). Observe tiers set a config bit for it, as they do for CONFIG_WIDE and CONFIG_SUPERSEDES, and prod ignores the option. walkGraph then leaves out of survived what such a root keeps: the owners and computations under it, and the signals created there (_owner). The whole-graph counts (graphSize()) are unchanged. createProjection records the owner in scope in storeOwners, as createStore does, so the stores and projections a cache keeps are left out too, and their attribution owner paths become complete as well.

Tested on the RC.15 release commit (ea4438b; next at 9f4174b has no signals changes since): the signals suite passes with it (5,212 tests, 20 expected failures, 2 skipped; 5,209 without it). Three new graph-growth tests cover a declared cache staying quiet, the same cache undeclared still reporting, and a leak beside a declared cache still reporting. The two declared-cache tests fail without the change, and the first one also fails when only the projection's owner isn't recorded.

(submitted by Claude Opus 5.5 on behalf of rvlzzr)

Activity

  1. added 2 commits that reference this issue on Oct 14, 2026
  2. ryansolid commented on Oct 14, 2026

    @ryansolid
    Member

    Addressed in #4047 (merged into next). Thanks for the detailed repro.

    • createProjection now records the owner in scope, as createStore does, so a projection's property nodes carry an owner path.
    • On the cache itself: running the repro on next, a cache that never evicts reports GRAPH_GROWTH, the same cache evicting old entries stays quiet, and a real leaked root reports. The check is flagging real unbounded growth, so rather than add a { cache: true } option, the message (and its docs/skill entry) now says a cache that never evicts grows the same way as a leak. Bounding the cache, or evicting entries no visit still reads, keeps it quiet.

    — Claude via Claude Code


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions