Skip to content

fix(workspace): the parent stats.json carries the children totals (#433) - #858

Draft
hr1juldey wants to merge 2 commits into
trailhq:mainfrom
hr1juldey:fix/433-workspace-stats-aggregate
Draft

hr1juldey wants to merge 2 commits into
trailhq:mainfrom
hr1juldey:fix/433-workspace-stats-aggregate

Conversation

@hr1juldey

@hr1juldey hr1juldey commented Nov 18, 2026 •

Copy link
Copy Markdown

Fixes #433.

Root cause

A workspace parent has no wiring.json of its own, so the sync child's stats patch (which merges computeStats(wiring) for single repos) had nothing to compute — the root stats.json stayed at emptyStats() zeros while the children held the real graphs. The statusline reads the root stats → "not built" despite every query working.

Fix

  • workspaceStats(repoDir, override) (claude/stats.ts): reads each child's wiring graph and sums what computeStats already computes per repo — node/edge/total/ready summed, languages unioned and sorted. Returns null when no child has a graph, so zeros stay honest instead of invented.
  • The workspace build path writes it after federation; the sync child's workspace branch merges it into its flags patch too, so a later sync never overwrites the aggregate back to zeros.
  • Layering kept: graph/ never imports claude/ — the helper lives in the claude layer, which already imports graph types.

Tests (adversarial)

The first version of the test restated the implementation's arithmetic; the committed set attacks the design instead:

  • the sync child merges totals around a real rebuild (runSync's build is injected — its default spawns the installed CLI, which does not exist in a source checkout, so the un-injected call silently no-ops its rebuild and lies about what was tested);
  • a corrupt child wiring graph degrades the aggregate to the surviving children, no NaN, and the next rebuild repairs it back in;
  • real drift (a child grows a function) moves the totals by its true delta; inflated stale numbers do not survive a sync;
  • a deleted child takes its counts out (discovery re-derives membership, so a workspace.json-only removal is correctly undone by the rebuild);
  • workspaceStats answers null or finite on a nonexistent child, a non-graph JSON shape, and an empty workspace — never invented numbers.

Test-seam finding, noted not fixed

runSync's default build silently no-ops in source checkouts (graftCliPath resolves src/cli.js, a build artifact) — any future test calling it un-injected hits the same silent no-op. Real installs point at dist; behavior there is unaffected.

…otals (trailhq#433)

A workspace build federates every child but left the parent's
stats.json at all zeros (written by the sync child, which had no
counts to fill in — a workspace parent has no wiring.json of its own),
so the statusline and anything else reading the root stats saw 'not
built' while every query worked.

- workspaceStats (claude/stats.ts) sums the children's graphs — the
  same totals the federated queries serve: node/edge/total/ready
  counts summed, languages unioned, sorted. Null when no child has a
  graph, so zeros stay honest instead of invented.
- The workspace build writes it after federation; the sync child's
  workspace branch merges it too, so a later sync never overwrites the
  aggregate back to zeros. Single-repo stats untouched.
github-actions Bot added a commit that referenced this pull request Nov 18, 2026
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🌱 graft blast radius

Nothing outside this diff depends on it. 2 areas changed; no indexed dependents at depth 2.
Tests: 1 area updated its tests.
Tag: @anirudhkumar-nanonets — Sync Run Statistics, CLI · @shhdwi — Sync Run Statistics, CLI

Who knows this code — 2 people across 2 areas
Area Who knows it
Sync Run Statistics · changed @anirudhkumar-nanonets — 4 commits, last 16d ago · @shhdwi — 4 commits, last 4mo ago
CLI · changed @anirudhkumar-nanonets — 75 commits, last yesterday · @shhdwi — 51 commits, last 22d ago

Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no @ has no GitHub handle in its commit email — tag them by hand, or add a .mailmap entry. A suggestion from history, not a CODEOWNERS rule.

Test signal per changed area — 1 ✓ · 1 –

Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.

  • ✓ Sync Run Statistics — 2 of 2 reached · 1 test file changed here: test/graph-extensions.test.ts
  • – CLI — no function, method or class changed here
1 test suite also references this code

1 symbol, kept out of the diagram and the table so they cannot crowd out the areas a reviewer has to look at.

  • test/claude-hooks.test.ts

graft blast · origin/main...HEAD · depth 2 · 4 changed files

Open the interactive graph → — click an area to see its dependent symbols at file:line.

Three rounds of hardening after the first version turned out to
restate the implementation's own arithmetic:

- the sync child MERGES totals around a real rebuild (runSync's build
  is injected: its default spawns the installed CLI, which does not
  exist in a source checkout, so the un-injected call silently
  no-ops its rebuild and lies about what was tested);
- a corrupt child wiring graph degrades the aggregate to the surviving
  children — no NaN — and the next rebuild repairs it back in;
- real drift (a child grows a function) moves the totals by its true
  delta; inflated stale numbers do not survive a sync; a deleted child
  takes its counts out (discovery re-derives membership, so a
  workspace.json-only removal is correctly undone by the rebuild);
  and workspaceStats answers null or finite on a nonexistent child, a
  non-graph JSON shape, and an empty workspace — never invented
  numbers.

Also found while probing: runSync's default build silently no-ops in
source checkouts (graftCliPath resolves src/cli.js under tsx). Test
seam problem only — real installs point at dist — noted here because
any future test that calls runSync un-injected will hit the same
silent no-op.

This branch has not been deployed

No deployments
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.

graft build in WORKSPACE mode writes empty stats.json

1 participant