Skip to content

feat(core): rank fold blockers by dominator retained-count #1083

Closed

Description

@lex00

#1064 measured 13/55 on loomster and found the fallbacks cascade. 15 files fail directly on process, 10 more fail on params because they import those, 5 more behind those. Roughly 30 of 42 trace to one authoring pattern.

The fallback report today is flat. A flat list of 42 files says 42 problems. The real content is that fixing one file unblocks thirty.

Why dominators

The import graph is a DAG, not a tree. A file is reachable by many paths, so naively counting "files downstream of X" double-counts every diamond and the totals stop meaning anything.

Immediate dominators are the principled fix. File d dominates n when every import path reaching n passes through d. Retained count is then the number of files that would fold if d folded, and every file lands in exactly one dominator subtree, so the counts sum to the total with nothing counted twice.

Prior art in a sibling repo. spicypath computes exactly this over heap object graphs (src/heap-dominators.js, Cooper–Harvey–Kennedy) and gets the same conservation property over a graph that is cyclic and irreducible. Different domain, same math, and an import graph is the easier case.

Scope

  • Compute immediate dominators over the module graph discovery already builds, with fold outcome per file as the input.
  • Rank blockers by retained count. A root cause with 30 retained outranks 12 unrelated leaves.
  • Report the ranking from chant build --fold alongside the existing per-file reasons.
  • Export the dominator tree in Brendan Gregg collapsed format, weighted by retained count, so it renders in any flame or icicle viewer with no chant-specific tooling. The seam stays at the file format.

AC

  • chant build --fold reports blockers ranked by how many files each would unblock, not just a flat fallback list.
  • loomster's src/loom-db/params.ts ranks first with retained around 30.
  • Retained is conserved. Summing over top-level blockers equals the total fallback count, and no file is counted twice through a diamond.
  • A file with two independent blockers is handled without inflating either.
  • Collapsed-format export, weighted by retained count.

Stays useful after #1064 lands, because resolving process.env promotes whatever is behind it to the top of the same ranking.

Relates #1062 (generate the inventory rather than hand-maintain it), #1064 (the finding), #1019 (epic).

Activity

  1. lex00 commented on Jul 27, 2026

    @lex00
    ContributorAuthor

    Dependency correction after checking current state.

    #1054 is a hard blocker, not a relation. This ranking keys on fold-failure reasons, and #1090 documents that reasons are currently unreliable to attribute — two wordings exist for the same rejection (function call as a value and call expression as a value), and reasons embed the entire multi-line source node, so line-based grepping silently miscounts. Root-cause grouping inherits that defect directly. Land #1054 first, and parse whole blocks rather than lines.

    #1062 landed (closed 2026-07-26). No overlap. #1062 publishes what folds and keeps the inventory generated. This ranks what doesn't fold by blast radius. The generated inventory is a reasonable input rather than something to rebuild.

  2. lex00 commented on Jul 27, 2026

    @lex00
    ContributorAuthor

    Two gaps found while tracing this to the goal.

    The only concrete AC is now stale. It asserts src/loom-db/params.ts ranks first with retained around 30. That number is pre-migration. loomster#156 merged, migrating those files off process.env to build-time parameters, so params.ts should no longer be a blocker at all and the AC as written may be unsatisfiable. Replace it with a re-measured target once the post-migration ratio is posted on #1064.

    No freshness guard. #1062 exists because a hand-maintained inventory went stale within an hour of the merge it described, and its AC required CI to fail on divergence. This issue produces a ranking with no equivalent requirement, so it decays the same way. Add an AC that the ranking is generated and guarded, in the shape of the post-synth barrel guard #1062 cites as precedent.

  3. lex00 commented on Jul 27, 2026

    @lex00
    ContributorAuthor

    Model gap found while measuring loomster (numbers on #1064).

    This issue assumes contagion flows one way — a file fails because its imports failed, so dominators over the import graph rank blockers by how many importers they unblock.

    Fold has a second rule in the opposite direction. params.ts post-migration reports:

    would fold in isolation, but a file that imports it (directly or transitively) falls back to run — folding independently would create a duplicate, non-identical instance

    So a perfectly foldable file falls back because an importer fell back. Contagion is bidirectional, and a dominator tree over import edges alone cannot express it. Ranking built on the one-way model would credit a fix with unblocking files that stay blocked by the reverse rule.

    Whatever this becomes, it has to model both directions, and the retained-count semantics need restating. "Files that would fold if this one folded" is no longer a subtree over import edges.

    This may also be the more valuable version of the issue. On the current numbers the reverse rule looks like it dominates the outcome, which is exactly the kind of thing a blast-radius ranking should surface and a flat reason list cannot.

  4. lex00 commented on Jul 27, 2026

    @lex00
    ContributorAuthor

    Measured data for the model correction (full context: #1064 (comment)). On loomster under 0.20.0, the reverse-contagion edge blocks exactly 2 files; the dominant blockers on real src (0/40 foldable) are exported helper function declarations (>=9 files) and their unresolved-identifier cascade (>=10). The prior AC (params.ts ranks first with retained ~30) is unsatisfiable under any discovery scope — params.ts now folds in isolation and only 2 files are held back by the reverse edge. If this issue proceeds after #1054, the ranking should treat exported-function-declaration sites as the seeds and model both edge directions, with the reverse direction expected to contribute little on current loomster.

  5. added
    area:core
    enhancement
    on Aug 23, 2026
  6. lex00 commented on Aug 26, 2026

    @lex00
    ContributorAuthor

    Re-scoping this before implementation, based on the measurements recorded on #1064/#1090 and the thread above:

    Blocker cleared. #1054 closed via PR #1109 — reasons are now attributable, so the ranking's input is reliable.

    AC replacement. The concrete AC (params.ts ranks first, retained ~30) is confirmed unsatisfiable and is dropped. Replacement acceptance criteria:

    1. Ranking runs against any --fold build and reports blockers ordered by dominator retained-count; retained is conserved (sums to total run-labeled files) and files with two independent blockers are not double-counted.
    2. Validated on two scopes: the differential corpus (where fold: call-form composite/intrinsic calls are the top remaining corpus gate — Checkout(...) ×8+forgejo, helm include/printf ×3 (41 files, sole blocker in 13 entries) #1174's call-form cause should rank at or near the top until it lands) and loomster real-src per the three-scope metric on feat(core): build-time parameter injection — DECIDED: option 1 (unblocks loomster, folds 13/55 today) #1064 (where exported-helper function declarations should dominate).
    3. Bidirectional taint handled explicitly: the dominator tree models forward contagion only. Files held back by the reverse rule (would-fold-in-isolation, tainted by a run importer) are reported as a separate annotated bucket, never folded into the tree — the tree cannot express that edge and pretending it can would credit fixes with unblocking files that stay blocked.
    4. Collapsed-format export retained from the original AC.
    5. Freshness: the ranking is generated on demand from a build (CLI/report surface), never a committed hand-maintained document. If any artifact is committed, CI must fail on divergence (docs(core): generate the foldability inventory instead of hand-maintaining it #1062 precedent).
  7. added a commit that references this issue on Sep 4, 2026
    612792b
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

    area:coreenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions