fix(drive): emit watch events as single-line NDJSON in json mode#75
Merged
Conversation
Pretty-printed multi-line JSON events break line-oriented consumers: a drive_sync_once event lists every path in the library and easily exceeds any reassembly buffer, so the desktop app lost the event and its sync badge stayed on "Syncing..." forever.
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.
What
drive watch --jsonnow emits each event as a single line of NDJSON instead of a multi-line pretty-printed JSON object.Why
In
--jsonmode the watch loop rendered events withJSON.stringify(data, null, 2), producing events that span many lines. Adrive_sync_onceevent lists every path in the library (includingunchangedfiles), so for a large synced folder a single event easily exceeds any line-oriented reassembly buffer on the consumer side.The WSPC Drive desktop app reassembles these multi-line events with a 64KB buffer. When an event blew past that cap, the app dropped it, its sync badge froze on "Syncing…" forever, and the corrupted buffer went on to swallow every subsequent event for that binding (including realtime reconnect notices). This was reproduced from the app's
events.log: a largedrive_sync_oncesplit intocli output: {/"action": "upload_create"fragments, after which that binding produced no further log lines.Single-line NDJSON removes the multi-line reassembly problem at the source: consumers parse line by line, and no per-event size assumption can wedge the stream.
Notes for reviewer
render().shouldOutputJson()is now exported fromoutput/render.tsso the watch command can branch on the same output-mode logic the renderer uses.