The build that claims edits it never read
Publish only the generation captured by the matching build, then rebuild the latest pending generation.
What’s going wrong
Original Microsoft-style interview practice. This is not an actual Microsoft interview question. Bugger does not provide an AI assistant.
A watch-mode build runs while more edits arrive. Its completion labels old output as the newest source generation, and a duplicate callback can finish an unrelated later build. Repair watchBuilds so requested source state, active snapshot ownership and completed artifacts remain distinct.
Read {"events":[{"type":"edit"},{"type":"complete","id":1},...]}. Initially the source generation is 0, no generation is published, and no build is active. Each edit increments the source generation by one. If idle, immediately start a build capturing that generation and give it the next build ID, beginning at 1. If busy, retain the newer requested generation without starting parallel work.
A complete event finishes work only when its ID matches the current active build. Ignore every other completion, including future, old and duplicate IDs. A matching completion publishes the generation captured when that build started. After publication, if the current source generation is newer, immediately start one build for that latest generation. Intermediate pending edits are coalesced. Finishing an older snapshot is allowed; claiming it contains later edits is not.
Print {"generation":N,"published":N_or_null,"active":null_or_{"id":N,"generation":N},"log":[...]}. Each start appends ["start",buildID,capturedGeneration] and each matching completion appends ["publish",buildID,capturedGeneration], in event order. Ignore events without logging them. Process only the supplied events; do not auto-complete remaining work at EOF.
Valid input has at most 200 events. Each is exactly an edit or a complete with a positive integer ID at most 1000000000. All matching builds succeed. There is no initial build of generation 0, filesystem, compiler, timer, cancellation or network; the event list is the complete deterministic timeline.
Expected behavior
Publish only the generation captured by the matching build, then rebuild the latest pending generation.
Reproduction
{"events":[{"type":"edit"},{"type":"edit"},{"type":"complete","id":1}]}{"generation":2,"published":1,"active":{"id":2,"generation":2},"log":[["start",1,1],["publish",1,1],["start",2,2]]}{"events":[{"type":"edit"},{"type":"complete","id":1}]}{"generation":1,"published":1,"active":null,"log":[["start",1,1],["publish",1,1]]}{"events":[{"type":"edit"},{"type":"complete","id":1},{"type":"edit"},{"type":"complete","id":1}]}{"generation":2,"published":1,"active":{"id":2,"generation":2},"log":[["start",1,1],["publish",1,1],["start",2,2]]}Before you begin
- Event-driven state machines
- Snapshot generations and ownership tokens
- Coalescing work without losing updates
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.