Repository navigation
Finish API generation in serve when the client gives up - #4932
Merged
Merged
Conversation
A request to /api/ ran the generation on its own cancellation token. A client that timed out cancelled the build, marked the pages stale, and the next request started it over. A poller with a short timeout never saw a finished build. The generation is now one task that the server owns. Requests wait on it with their own token, so a disconnect stops only that wait. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The stale flag is cleared before the check for changed specs, which sat outside the try block. An IO error there left the pages marked fresh and the faulted task in place, so every later /api/ request rethrew the same error. The try block now covers the whole body, and a failure marks the pages stale again. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A request that arrived during a generation joined it, even when a spec or overlay edit had marked the pages stale since the run began. It received pages built from the old inputs and had to reload to see its edit. The request now waits for another run while the pages are stale. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The lifecycle that keeps a build running when its client gives up was tangled into ReloadableGeneratorState, so only a full API build could exercise it. SharedGeneration now holds that coordination and takes the build as a delegate. Tests cover a cancelled request, concurrent requests, a change that lands mid-run, a failed run and shutdown. A failed run is also retried by the next request without relying on the build to mark the output stale. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Contributor
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4932/ |
A caller checked the stale flag after its run ended, outside the lock. When another caller had already started the next run, that run had cleared the flag, so the first caller returned while pages were still being rewritten in place. The caller now decides under the lock: it leaves only when no run is in flight and the output is fresh. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
docs-builder servenow finishes generating the API pages even when the client that asked for/api/times out or disconnects. A polling script no longer restarts the build on every attempt.Affects: CLI, API reference
Prompt summary: Navigating to
/apiinserveseems to restart the API docs generation from scratch whenever a build is still in progress. A polling script therefore runs forever. The goal is to make a request join the generation in flight.Why
A request to
/api/ran the generation on a token linked to its own HTTP request. When the client gave up, the build was cancelled, the pages were marked stale, and the next request started a full build again. A poller with a timeout shorter than the build time never sees it finish.What
One generation owned by the server
A new
SharedGenerationclass runs one generation at a time on a server-lifetime token. A request waits on the run withWaitAsyncand its own token, so a disconnect ends only that request's wait. Concurrent requests join the same run. The 5-minuteCancelAfterand the semaphore are gone. The timeout caused the same restart loop for a slow build without any poller.A request never gets output older than a change it saw
A request leaves only when no run is in flight and the pages are fresh, and it decides that under a lock. A spec, overlay or hot-reload change that lands mid-run therefore costs the request one more run, as the semaphore version did. A request that wakes after another request started that run joins it and does not return early.
Failures retry
ReloadableGeneratorStatemarks the pages stale when any step of a run fails, including the check for changed specs.SharedGenerationalso starts a new run after a faulted one, so a failure surfaces once and the next request goes ahead.Verify
On
mainthe loop never exits. With this change it exits once the one build finishes, about two minutes on this machine for thedocs/specs. A second request then returns in about a millisecond. Aftertouch docs/api/docs-builder-elasticsearch/op-async-search-get.md, the next request regenerates once, and several concurrent requests share that one build.Out of scope: the hot-reload path (
InvalidateApiReferencesfromdotnet watch) was not exercised end to end.SharedGenerationTestscovers the same stale-again behavior with a controllable generation.🤖 Generated with Claude Code