Skip to content

fix(cli): a long-running caller sees an edit to a doc file it already read - #7998

Merged
josephfarina merged 2 commits into
mainfrom
josephfarina/doc-edits-seen-in-process
Oct 23, 2026
Merged

josephfarina merged 2 commits into
mainfrom
josephfarina/doc-edits-seen-in-process

Conversation

@josephfarina

@josephfarina josephfarina commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

User impact

A process that calls the CLI API more than once — a docs site's search endpoint, an agent harness, anything that keeps Node running between calls — never saw an edit to a doc file it had already read. After editing a topic, a guide, a component doc or an integration's doc, docs(), component() and search() kept returning the old text until the process restarted. Adding or removing a file was seen; editing one was not.

Problem and solution fit

  • Why the old text: doc files are loaded with import(), and Node keeps one module per URL for the life of the process; jiti does the same for .ts docs. On top of that, the reader memoized each lowered file for the life of the process.
  • Why search stayed stale even when it re-gathered: search reuses its gathered catalog while the files it read are unchanged, but a module import doesn't go through fs, so the doc files themselves were never part of that check.
  • Why it matters: an author or agent who edits a doc and asks again gets an answer about text that no longer exists, with no sign it's stale.

The fix makes the importer content-aware and lets the two caches above see the files it imports.

Expected behavior and authority

The search adapter already promises that "an edited doc in a linked package is seen on the next call" (api/search/_adapter.mjs). The reader's contract test, "hands readers the module's own doc, as main always did", still holds: an unchanged file is imported exactly as before.

Smallest restoration

  • foundation/doc-compiler/import.mjs: each importer imports a file as before until it changes (so readers keep the module's own doc). When the file's stamp changes, each importer (plain import, jiti, JSX jiti) imports it once more, fresh and in its own way, and shares that module until the next change. So a .doc.ts read after an edit gives each reader what a new process would. Each import counts as a read of the file for the running operation.
  • foundation/doc-compiler/read.mjs: the lowered-file memo is kept per file stamp, so an edited file is lowered again.
  • api/docs/_adapter.mjs: the CLI's own tree files and authoring docs were loaded once per process, so docs('authoring') kept an edited guide's old summary. They now come from reusedWhileUnchanged, which keeps the loaded value while every file and folder it read is unchanged.
  • foundation/fs/read-record.mjs: recordContentRead(file) adds a file read without fs (a module import) to the running record. A run inside another records into both, and a kept value's reads count for the operation that asks for it, so search's own reuse still sees those files. fileStamp (size, modification time, change time, inode) is now the state it compares, so a rewrite that keeps size and modification time, as an npm reinstall does, also counts as a change.
  • Only a doc file's own edits count. A module the doc file imports stays as first loaded.

Evidence

  • Reproduction before the change (one process: read, edit, read again): the CLI color topic, the authoring/quick-start guide, the Core Button doc and a linked integration's topic all kept their old text in docs() / component(), and search() didn't find a word added to any of them. docs('authoring') also kept listing an edited guide's old summary.
  • Result after the change: all of them show the edit on the next call, search() finds the new word in each, and docs('authoring') lists the new summary.
  • Representative unchanged path: an unchanged file is imported once and shared, as before.
  • Timing, head vs main:
    • One-shot CLI, median of 9 runs each, interleaved: docs authoring --index 660 vs 655 ms, docs color 671 vs 665, search button 1847 vs 1841, component Button --dense 689 vs 686.
    • In-process, 3 runs per side: warm search about 173–175 ms vs 173–211 ms per query; first search about 1.3 s on both.
    • A warm in-process docs() call costs about 1 ms more (5.3 → 6.3 ms), because it checks the CLI tree's files for changes.
  • Regression tests: new tests in read.test.mjs (an edited .mjs doc, an edited .ts doc, the whole-project memo, and a fix after a broken edit), in read-record.test.mjs (a recorded import; a same-size, same-mtime rewrite) and in api/search/_adapter.test.mjs (an edited integration doc in a linked package is re-gathered with its new text). With the importer change reverted, all five of those reader and search tests fail. A .doc.ts read through loadDocs and then loadComponentDoc after an edit checks that each importer keeps its own module; it fails when one module is shared. read-record.test.mjs also covers nested runs and reusedWhileUnchanged (keep, reload after an edit, fresh, a kept value's reads counted, retry after a failure).

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm vitest run --project node packages/cli: everything passes except two tests in foundation/release/cache.test.mjs (process-group checks around an npm install), which fail the same way on main on the machine I ran them on. Under the full parallel load, docs-homes.test.mjs hit its 60 s limit once; run alone it passes in 15.7 s (16.2 s on main).
  • pnpm check:repo, check:knowledge, check:changesets, changeset coverage against v0.7.4, the CLI README check, and eslint on the changed files: all pass. typecheck:strict reports only the two @astryxdesign/theme-neutral/built errors a tree without a root build always has.

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 23, 2026 8:27pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 23, 2026
@astracat-bot

astracat-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 23, 2026, 8:49 PM UTC

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

46 of 494 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 26 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works for .doc.mjs docs: in one process, edited topics, guides and component docs now show up in docs(), component() and search() on the next call, and the new regression tests cover each case. One change is needed before merging: importCurrent in packages/cli/foundation/doc-compiler/import.mjs shares one re-imported module per file across all three importers, so after an installed integration's .doc.ts is rewritten, a long-running search() returns a description that astryx search --json in a new process does not. Keeping the shared first-import stamp but holding the re-imported module per importer (for example seen.changed[kind] ??= loadFresh(file)), with a .doc.ts test that reads through loadDocs before loadComponentDoc after an edit, fixes it. Separately, docs('authoring') still lists an edited CLI guide's old summary, so the changeset's docs() claim should be narrowed or the CLI's own docs tree refreshed on a change.

[Automated review]

Comment on lines +55 to +63
const seen = imported.get(file);
if (!seen) {
imported.set(file, {stamp});
return load(file);
}
if (seen.stamp === stamp) return seen.changed ?? load(file);
const changed = loadFresh(file);
imported.set(file, {stamp, changed});
return changed;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a change this entry is shared by all three importers, so whichever re-imports first decides what the others get. For a .doc.ts under node_modules, search's native reader then serves the module jiti loaded, and a long-running search() disagrees with astryx search --json; in the opposite order importDocModule gets the native failure until the next change. Keeping this shared first-import stamp but holding the re-imported module per importer (for example seen.changed[kind] ??= loadFresh(file)) gives each reader a fresh process's answer.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ready to merge: in one long-running process, docs(), component() and search() now return a doc file's edited content on the next call, matching what a new astryx process returns, and the new tests fail without the change. The per-importer fresh modules and the refreshed CLI docs tree also settle the two earlier change requests. One optional follow-up: component() still keeps the first-read text of a .doc.js from a package whose package.json has no "type" field, because importDocModule's fresh read goes through require() there; evicting the file's require cache entry and importing a fresh file URL reloads it.

[Automated review]

export function importDocModule(file) {
return importUserModule(file);
return importCurrent(file, 'doc', importUserModule, changed =>
importUserModule(changed, {fresh: true}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After an edit this re-reads the file with importUserModule(changed, {fresh: true}), whose .js branch uses require() unless the nearest package.json says "type": "module". A .doc.js written with export default in a package with no "type" field (Node loads it as an ES module by syntax detection) then comes back as the module Node already holds, so component() keeps the first-read text while search() shows the edit. Evicting the file's require cache entry and importing a fresh file URL reloads that file, a CommonJS one and a "type": "module" one alike; the same in the native and template importers' fresh reads also covers a CommonJS .doc.js that one of them reads first after a change.

@josephfarina
josephfarina merged commit fccd771 into main Oct 23, 2026
64 checks passed
@github-actions
github-actions Bot deleted the josephfarina/doc-edits-seen-in-process branch October 24, 2026 06:20

This branch was successfully deployed

1 active deployment
Preview — 49b42aaf Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant