Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix: stop refresh feedback loop on large Syncthing folders - #142

Open
devmil wants to merge 1 commit into
omarchy-QOL:devfrom
devmil:fix/event-feedback-loop
Open

devmil wants to merge 1 commit into
omarchy-QOL:devfrom
devmil:fix/event-feedback-loop

Conversation

@devmil

@devmil devmil commented Nov 30, 2026

Copy link
Copy Markdown

Problem

On a large folder (~960k files, ~1.16M items, 8 GB index database) Syncthing stayed at 150–440% CPU while fully synced and idle, as long as the plugin was running. Pausing syncshell-core alone brought it down to Syncthing's own baseline.

Cause: requiresHydration treats every event except download/item progress as structural. FolderSummary, StateChanged and FolderCompletion therefore each trigger a full Refresh. Every refresh calls /rest/db/status per folder and /rest/db/completion per folder/device pair. On a folder that size, one completion lookup costs several seconds of CPU and is followed by further FolderCompletion events, so the loop never settles. The lookups also often run past the 5 s loadRemoteSharing timeout, so the remote state stays unknown despite the cost.

Change

  • Patch from event payloads: FolderSummary (status fields), StateChanged (state) and FolderCompletion (remoteState) are applied directly to the current snapshot, with no REST calls. Counts and revision are updated; an unchanged payload doesn't bump the revision.
  • Fall back to hydration when a payload isn't enough: unknown folder, malformed or empty payload, transitions into or out of error, or a changed pullErrors count (the bounded error list has to be reloaded). This keeps the StateChanged-after-FolderErrors recovery behaviour.
  • Coalesce structural events (ConfigSaved, ClusterConfigReceived, device and folder pause/connect events, …) into at most one hydration every 5 s, with a trailing refresh. The 1 s event long-poll lets the trailing refresh run promptly.
  • Cache remote sharing states per folder/device: 15 min TTL, 3 min after a failed lookup. FolderCompletion events refresh the cache for free. The cache is cleared on topology events, event gaps or reconnects, and after mutations and ambiguous mutations.
  • The periodic refreshInterval reconciliation and the probe and telemetry schedules are unchanged.

Tests

  • New eventpatch_test.go: payload patching, the hydration fallbacks, and an event-loop test showing that a stream of status events causes no /rest/db/status or /rest/db/completion requests while 10 structural batches coalesce into 1–3 hydrations.
  • New TestRemoteSharingIsCachedUntilInvalidated. The existing sharing tests now invalidate between steps or use distinct folder IDs.
  • TestSharingEventsRefreshRemoteState now asserts the new split: ClusterConfigReceived rehydrates and invalidates, while FolderCompletion is patched.
  • syncshell-waybar lifecycle fixture: it now also emits StateChanged for f2, as Syncthing does per folder. Before, it relied on the side effect of a rehydration triggered by f1's event.
  • go vet ./... and go test -race ./... pass with Go 1.27.3; tests/architecture, native-core-architecture and scripts pass.

I didn't rebuild the bundled cores, so they're left to the release build.

Result

On the affected machine, with a build of this change installed, Syncthing went from about 150–440% CPU to its own baseline (about 0–75% in 30 s windows, mostly its own rescans). That matches what it used with the plugin process stopped.

🤖 Generated with Claude Code

Every FolderSummary, StateChanged and FolderCompletion event triggered a full
rehydration, and each rehydration issued /rest/db/status per folder plus
/rest/db/completion per folder/device pair. On a folder with ~10^6 items each
completion lookup costs seconds of CPU and itself leads to more completion
events, keeping Syncthing at several cores while idle.

- patch folder status, state and remote sharing state from event payloads
- fall back to a full hydration only when a payload is insufficient
  (unknown folder, error transitions, changed pull error counts)
- coalesce structural events into at most one hydration per 5 seconds with a
  trailing refresh
- cache remote sharing states; re-query only after topology events,
  mutations, reconnects/gaps, or a 15 minute TTL (3 minutes after failures)
- emit per-folder StateChanged events in the waybar lifecycle fixture, as
  Syncthing does, instead of relying on a rehydration side effect

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ilyaZar

ilyaZar commented Nov 30, 2026

Copy link
Copy Markdown
Member

@devmil thanks this is a really good catch !

Part of the next release in a couple days

I think it's likely I'll reproduce it, and may change a bit in the code , would you mind checking a (potentially) adjusted fix on your side ?

Thanks again 👍

@devmil

devmil commented Nov 30, 2026

Copy link
Copy Markdown
Author

@devmil thanks this is a really good catch !

Part of the next release in a couple days

I think it's likely I'll reproduce it, and may change a bit in the code , would you mind checking a (potentially) adjusted fix on your side ?

Thanks again 👍

sure, just let me know

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants