Repository navigation
feat(core): rank fold blockers by dominator retained-count over the import graph - #1968
Merged
Merged
Conversation
Computes immediate dominators (Cooper-Harvey-Kennedy) over the forward import-failure graph among a --fold build's run-mode files, so fixing one root cause is ranked by how many files it actually unblocks — conserved, with diamonds and independent-blocker files counted exactly once. Reverse-taint files (chant #1044 — would fold in isolation, held back by a run-mode importer) are excluded from the tree and reported in a separate bucket, since that contagion direction can't be expressed as a dominator edge. Surfaced via `chant build --fold --fold-rank [<path>]`, mirroring --report's context-sensitive bare-boolean-vs-path convention: bare prints the ranked text report, a path additionally exports the dominator tree in Brendan Gregg collapsed stack format (weighted by retained count) for any flame/icicle viewer. fold-import.ts's planFoldTaint already built the project import-edge graph; extracted it into exported buildProjectImportEdges so the new ranking (discovery/fold-rank.ts) reuses it instead of re-parsing every file's imports. Fixes #1083. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Model
chant build --foldalready reports a flat fallback list. This ranks it: immediate dominators (Cooper–Harvey–Kennedy) over the forward import-failure graph among a build's"run"-mode files. Fileddominates filenwhen every causal path ton's failure passes throughd;d's retained count is its dominator-subtree size — the number of files that would fold ifd's own problem were fixed. Every file lands in exactly one dominator subtree, so retained counts are conserved (top-level blockers' retained sum to the total run-labeled file count), a diamond is never double-counted, and a file with two independent blockers inflates neither — it becomes its own entry instead.Per the issue's re-scope (2026-08-26 comment), this is forward contagion only: file
nfails because an import,d, also fails. Fold's other rule (#1044) runs the opposite direction — a file that would fold fine in isolation is forced to run because a run-mode importer needs it to keep object identity. A dominator tree over import edges can't express that edge, so those files are excluded from the tree entirely and reported in a separatereverseTaintedbucket instead of being folded into anyone's retained count.The import-edge graph itself isn't rebuilt:
fold-import.ts'splanFoldTaintalready parses every project file's imports/re-exports to compute its own (differently-directed) taint propagation. That loop is extracted into an exportedbuildProjectImportEdges, whichplanFoldTaintnow calls too —discovery/fold-rank.tsreuses it for the dominator graph instead of re-parsing.FoldDecisiongains one new field,reverseTainted?: boolean, set exactly wherediscovery/index.tsalready builds the reverse-rule reason string — so the ranking doesn't need to pattern-match reason text to tell the two contagion directions apart.CLI surface
chant build --fold --fold-rank [<path>], mirroring--report's existing context-sensitive bare-boolean-vs-path convention (main.ts'sparseArgs):--fold-rankalone prints the ranked text report to stderr, independent of--verbose.--fold-rank <path>also writes the dominator tree as a Brendan Gregg collapsed stack export (weighted by retained count) to<path>— one line per file, each a chain from a syntheticfoldroot frame through its dominators down to itself, weight1; folding identical prefixes (what every collapsed-format consumer does) reproduces each node's retained count exactly. Opens in any flame/icicle viewer, no chant-specific tooling.No new build-time cost unless
--fold-rankis passed.Example output
Against a synthetic project (
process-cfg.tsreadsprocess.envdirectly;params.tsimports it; three files importparams.ts/each other; one unrelated leaf; one file that would fold in isolation but is dragged to"run"by a run-mode importer):Collapsed export (
--fold-rank <path>):process-cfg.tsretains 5 (itself + params.ts + a/b/c), never 8 —dependent-c.tsis reached once, throughdependent-a.ts, not double-counted;unrelated-leaf.tsis its own independent blocker;would-fold.tsnever enters the tree.Tests
packages/core/src/discovery/fold-rank.test.ts(real temp-file fixtures, same convention asfold-import.test.ts):Plus CLI-surface tests:
main.test.ts(--fold-rank/--fold-rank <path>/joined-form parsing) andbuild.test.ts(--fold-rankend-to-end throughbuildCommand, asserting both the printed report and the written collapsed file).Test plan
npm installnpx vitest run packages/core— 328 files / 5027 tests passedCHANT_SKIP_ARTIFACT_CHECK=1 npx vitest run packages/core/src/discovery/fold-rank.test.ts packages/core/src/discovery/fold-import.test.ts packages/core/src/discovery/index.test.ts packages/core/src/cli/main.test.ts packages/core/src/cli/commands/build.test.ts— all greenFixes #1083
Note for reviewers
Per the issue: another PR (#1174) is concurrently touching call-form fold handling in
fold-import.ts. The only change here to that file is extractingplanFoldTaint's existing edge-building loop into an exportedbuildProjectImportEdges(identical logic, no behavior change) — nothing in the call-form resolution path was touched.🤖 Generated with Claude Code