Skip to content

Improve docs-builder serve reliability and startup speed - #2982

Merged
Mpdreamz merged 1 commit into
mainfrom
feature/docs-builder-serve
Mar 30, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
feature/docs-builder-serve

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Mar 28, 2026 •

Copy link
Copy Markdown
Member

What changed

This PR fixes several regressions in docs-builder serve and adds a quality-of-life improvement for anyone writing docs locally.

Why this matters for writers

If you use docs-builder serve day-to-day, you've probably hit these pain points:

  • Editing docset.yml did nothing — you had to kill and restart the server to see navigation changes. Now it live-reloads automatically.
  • Adding, removing, or renaming files required a restart — the file watcher didn't pick up structural changes. Now it does, including changes to toc.yml and _docset.yml.
  • The server was slow to start — OpenAPI spec generation (e.g. Kibana APIs) blocked startup. Now API docs are generated lazily on first request, so the server is ready to use immediately.
  • CTRL+C took a long time — background builds weren't properly cancelled on shutdown. Now cancellation propagates immediately.
  • Navigation collapsed on every reload — when you had sections expanded in the sidebar and made a file change, everything collapsed back. Now your expanded sections are preserved across reloads. ONLY during development or running docs-builder serve.

Technical summary

Configuration reload on file changes

  • Added BuildContext.ReloadConfiguration() to re-read docset.yml/_docset.yml from disk on config or structural file changes, while skipping the expensive re-parse for simple markdown content edits.
  • Added _docset.yml and toc.yml to the FileSystemWatcher filters.
  • Serve-mode feature flags (diagnostics panel) are now preserved across reloads.

Lazy OpenAPI generation

  • Moved OpenAPI document generation out of the startup path into an on-demand EnsureApiReferencesAsync() method triggered by the first /api/ request.
  • Uses a stale flag + semaphore for thread safety, with change detection so specs are only regenerated when the underlying files are modified.

Faster CTRL+C cancellation

  • Wired a service-scoped CancellationTokenSource through the reload/debounce pipeline, replacing the previous Cancel.None that caused in-flight reloads to ignore shutdown signals.

Navigation state preservation (dev mode only)

  • Persists expanded/collapsed sidebar state to sessionStorage so sections stay open across live reloads.
  • Only active when the diagnostics panel is present (serve mode) — zero impact on production builds.

Test plan

  • Run docs-builder serve, verify server starts and reaches "Now listening" without waiting for OpenAPI generation
  • Edit _docset.yml (e.g. comment out a file entry), verify navigation updates on reload
  • Add/remove/rename a .md file, verify it's reflected without restart
  • Edit a toc.yml file, verify navigation updates on reload
  • Expand several nav sections, edit a markdown file, verify sections stay expanded after reload
  • Verify diagnostics HUD (error/warning bar) remains visible after file changes
  • Press CTRL+C, verify the server shuts down promptly
  • Visit /api/ endpoint to trigger lazy OpenAPI generation, verify it works

Made with Cursor

The serve command had several regressions that made the local authoring
workflow frustrating: editing docset.yml no longer reloaded properly,
adding/removing/renaming files required a full restart, OpenAPI generation
blocked startup, CTRL+C was slow to cancel, and the diagnostics HUD
disappeared after the first file change.

This fixes all of those issues and adds a quality-of-life improvement
that preserves navigation tree state across live reloads.

Configuration reload on file changes:
- Add BuildContext.ReloadConfiguration() to re-read docset.yml from disk
  when config files or file structure changes, while skipping the
  expensive re-parse for simple markdown content edits.
- Watch _docset.yml and toc.yml in addition to docset.yml and *.md so
  navigation structure changes are detected without a restart.
- Preserve serve-mode feature flags (e.g. diagnostics panel) across
  configuration reloads.

Lazy OpenAPI generation:
- Move OpenAPI document generation out of the startup path so the server
  reaches "Now listening on" immediately instead of blocking on spec
  parsing.
- Generate API references on-demand when the first /api/ request arrives,
  with change detection so specs are only regenerated when modified.

Faster CTRL+C cancellation:
- Wire a service-scoped CancellationTokenSource through the reload
  pipeline so in-flight reloads are cancelled promptly on shutdown,
  replacing the previous Cancel.None that caused hangs.

Navigation state preservation (dev mode only):
- Persist expanded/collapsed navigation tree state to sessionStorage so
  sections you had open stay open after a live reload, instead of
  collapsing back to only the current page's ancestors.
- Gated behind the diagnostics panel presence check so it has zero
  impact on production builds.

Made-with: Cursor
@coderabbitai

coderabbitai Bot commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request adds configuration reloading and lazy-loading of API references to the documentation builder. The BuildContext now supports reloading the configuration from docset.yml and toc.yml files while preserving diagnostic settings. The reload service has been enhanced to detect configuration file changes and trigger targeted reloads via ReloadConfiguration(). API reference generation has been decoupled from the standard reload flow into a separate EnsureApiReferencesAsync() method that lazily prepares OpenAPI artifacts on-demand. Navigation state persistence for the pages panel checkbox has been added to the frontend using sessionStorage. Minor YAML formatting adjustments were also made.

Sequence Diagram(s)

sequenceDiagram
    participant Watcher as File Watcher
    participant RGService as ReloadGeneratorService
    participant RGState as ReloadableGeneratorState
    participant BuildCtx as BuildContext
    participant FileSystem as File System

    Watcher->>RGService: File change detected<br/>(docset.yml/toc.yml)
    RGService->>RGService: Reload(reloadConfiguration: true)
    RGService->>RGState: ReloadAsync(ctx, reloadConfiguration: true)
    RGState->>BuildCtx: ReloadConfiguration()
    BuildCtx->>FileSystem: Load docset.yml & toc.yml
    BuildCtx->>BuildCtx: Rebuild Configuration<br/>(preserve diagnostics)
    RGState->>RGState: Regenerate documentation
    RGState-->>RGService: Reload complete
Loading
sequenceDiagram
    participant Client as HTTP Client
    participant WebHost as DocumentationWebHost
    participant RGState as ReloadableGeneratorState
    participant FileSystem as File System

    Client->>WebHost: GET /api/...
    WebHost->>RGState: EnsureApiReferencesAsync(ctx)
    RGState->>RGState: Check _apiReferencesStale flag
    alt API references need regeneration
        RGState->>FileSystem: Check if specs changed
        RGState->>FileSystem: Regenerate /api/ artifacts
        RGState->>RGState: Update spec timestamps<br/>Mark references fresh
    end
    RGState-->>WebHost: API references ready
    WebHost->>FileSystem: Read index.html
    WebHost-->>Client: Serve API documentation
Loading

Suggested labels

feature, enhancement

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main objectives: improving reliability and startup speed of docs-builder serve.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description clearly describes the changes: fixing regressions in docs-builder serve (config reload, file watching, lazy API generation, cancellation, navigation state preservation) and maps them to specific code changes across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feature/docs-builder-serve

Comment @coderabbitai help to get the list of available commands and usage tips.

@Mpdreamz Mpdreamz removed the feature label Mar 28, 2026
@Mpdreamz
Mpdreamz requested a review from theletterf March 28, 2026 18:18
@Mpdreamz
Mpdreamz merged commit 5c04bd6 into main Mar 30, 2026
24 of 27 checks passed
@Mpdreamz
Mpdreamz deleted the feature/docs-builder-serve branch March 30, 2026 08:45
@cotti cotti mentioned this pull request Jun 3, 2026
1 of 3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants