Skip to content

bug(core): composite propagate() mutates in place — repeat build() of one tree duplicates tags #1032

Closed

Description

@lex00

Found by the #1025 fold-vs-run differential (epic #1019), unrelated to fold — reported separately per that issue's instruction not to paper over real findings.

Symptom

Calling build() on the same source directory more than once in a single process produces different output on the second run — duplicated tags. It reproduces with two build(dir, {fold:false}) calls back to back (no fold involved).

Cause

propagate() in packages/core/src/composite.ts mutates its instance in place rather than returning a copy, so the mutation compounds across repeated builds of the same tree in one process.

Impact

Workaround in place

The #1025 differential self-defends: it detects the mismatch via a cheap control comparison and retries only the affected entry with vi.resetModules() (1 of 98 corpus entries needed it — lexicons/aws/examples/docs-snippets). That's a harness band-aid, not a fix.

Fix

Make propagate() (and audit sibling composite methods) copy rather than mutate in place, so build() is idempotent on repeated calls. Add a regression test that builds one tree twice and asserts identical output.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions