refactor(core,cli): unified watch coordinator behind one seam, two adapters - #212
Merged
Conversation
…apters Watch policy existed twice: liveServer.ts fused the Apollo generation-swap with a watch coordinator (parcel subscription, picomatch matchers, 150ms coalescing over closed-over mutable state, config reload, codegen refresh) testable only through a real filesystem watcher; codegen's watchAndGenerate ran a second legacy loop (chokidar, a `regenerating` mutex that silently DROPPED events arriving mid-regeneration, its own config reload, full schema rebuild). New packages/core/src/watch/coordinator.ts owns the policy — interface: file events in → committed/rejected generations out. It handles classification (config globs → classifyPath → document globs), debounced coalescing with delete-wins semantics, single in-flight build with mid-build events QUEUED (fixes the legacy drop), config replacement with matcher recompilation, reindex calls, codegen scheduling, and per-phase rejection isolation (build errors never kill the loop). Subscribers get monotonic WatchCoordinatorResult events — the seam the effort-graph committed-generation bridge wires into next. Home is core by dependency direction: flatbread depends on codegen, so neither could host a module both consume; core has zero @flatbread deps and owns classifyPath. Codegen scheduling stays an injected hook, so core imports nothing new. Both former loops are now thin adapters (two adapters = the seam is real): startGraphqlServer keeps parcel plumbing + the Apollo swap — swap mechanics byte-untouched, all 7 liveServer AVA tests green unmodified — and watchAndGenerate keeps chokidar + kleur output but delegates all policy. docs/local-dev-loop.md now documents the single `flatbread start --watch` loop instead of two terminals. Test plan: 12 new coordinator AVA unit tests driven entirely by synthetic events via an injectable scheduler (classification routing, coalescing, config-change rebuild, queueing during in-flight builds, rejected-generation recovery, codegen scheduling, idle-flush regression); liveServer suite unchanged; watch-patterns vitest suite green. Full suite: pnpm verify (271 AVA + 52 vitest). Co-authored-by: Cursor <cursoragent@cursor.com> Change-Id: I92f7ac7914952a0d5c42952f192ee7e0f187f004
Collaborator
Author
|
This pull request is part of a Mergify stack:
|
This was referenced Jul 17, 2026
Merged
Merged
Collaborator
Author
|
@Mergifyio queue |
Contributor
Merge Queue Status
This pull request spent 34 minutes 7 seconds in the queue, including 4 minutes 1 second running CI. Required conditions to merge
|
Base automatically changed from
stack/tonyketcham/feat/unified-watch-effort-graph/collection-query-executor-owns-filter-sort-paging--f0e0928c
to
main
July 18, 2026 09:05
…graph/unified-watch-coordinator-behind-one-seam-two--92f7ac79
tonyketcham
deleted the
stack/tonyketcham/feat/unified-watch-effort-graph/unified-watch-coordinator-behind-one-seam-two--92f7ac79
branch
July 18, 2026 09:10
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.
Watch policy existed twice: liveServer.ts fused the Apollo
generation-swap with a watch coordinator (parcel subscription,
picomatch matchers, 150ms coalescing over closed-over mutable state,
config reload, codegen refresh) testable only through a real
filesystem watcher; codegen's watchAndGenerate ran a second legacy
loop (chokidar, a
regeneratingmutex that silently DROPPED eventsarriving mid-regeneration, its own config reload, full schema
rebuild).
New packages/core/src/watch/coordinator.ts owns the policy — interface:
file events in → committed/rejected generations out. It handles
classification (config globs → classifyPath → document globs),
debounced coalescing with delete-wins semantics, single in-flight
build with mid-build events QUEUED (fixes the legacy drop), config
replacement with matcher recompilation, reindex calls, codegen
scheduling, and per-phase rejection isolation (build errors never kill
the loop). Subscribers get monotonic WatchCoordinatorResult events —
the seam the effort-graph committed-generation bridge wires into next.
Home is core by dependency direction: flatbread depends on codegen,
so neither could host a module both consume; core has zero @flatbread
deps and owns classifyPath. Codegen scheduling stays an injected hook,
so core imports nothing new.
Both former loops are now thin adapters (two adapters = the seam is
real): startGraphqlServer keeps parcel plumbing + the Apollo swap —
swap mechanics byte-untouched, all 7 liveServer AVA tests green
unmodified — and watchAndGenerate keeps chokidar + kleur output but
delegates all policy. docs/local-dev-loop.md now documents the single
flatbread start --watchloop instead of two terminals.Test plan: 12 new coordinator AVA unit tests driven entirely by
synthetic events via an injectable scheduler (classification routing,
coalescing, config-change rebuild, queueing during in-flight builds,
rejected-generation recovery, codegen scheduling, idle-flush
regression); liveServer suite unchanged; watch-patterns vitest suite
green. Full suite: pnpm verify (271 AVA + 52 vitest).
Co-authored-by: Cursor cursoragent@cursor.com
Depends-On: #211