Repository navigation
engine/server: sweep discarded cache state in the background - #13916
Merged
Merged
Conversation
vito
force-pushed
the
fix-discarded-cache-sweep
branch
from
August 18, 2026 16:58
bc0dbe0 to
1e14375
Compare
sipsma
approved these changes
Aug 18, 2026
sipsma
left a comment
Contributor
There was a problem hiding this comment.
non blocking nit for a further corner case, if you agree worth a quick fix otherwise lgtm
Comment on lines
+141
to
+144
| // trashSweepFullSpeed reports whether the sweeper should skip its rest slices: | ||
| // once the disk is under the same free-space pressure that triggers cache GC, | ||
| // reclaiming the trashed bytes promptly matters more than smoothing I/O. | ||
| func (srv *Server) trashSweepFullSpeed() bool { |
Contributor
There was a problem hiding this comment.
nit: this makes sense, but in the case where the disk was actually full or nearly full I think we'd need to go further and still block startup on this removal rather than going async. Otherwise the engine will probably just shutdown again quickly once it starts trying to make files and fails
Resetting invalid local cache state (unclean shutdown, schema mismatch, corrupt DBs) deleted the entire worker root dir inline with os.RemoveAll before the engine came up. On a warm cache that is tens of GB across millions of inodes: startup blocked for the whole delete, and the unlink storm saturated the disk queue hard enough to stutter the host for about a minute. Rename the discarded state aside to a sibling worker-trash-<unique> dir instead — an O(1) rename on the same filesystem — so startup proceeds immediately, and remove the tree from a background sweeper at a bounded duty cycle (50ms of unlinks, 200ms of rest) so the filesystem journal drains between bursts instead of monopolizing the disk. The sweeper runs at full speed when the disk is under the same free-space pressure that triggers cache GC, resumes leftover trash dirs on the next startup if interrupted, and detaches stale mounts left behind by the crashed engine (recursively up front, plus an EBUSY fallback per path) rather than failing the reset. The unclean-shutdown integration test now also polls the state volume until the trash dir is swept, so discarded state cannot silently leak across resets. Signed-off-by: Alex Suraci <[email protected]>
Remove discarded worker state synchronously when the configured GC policy reports disk pressure. This ensures startup reclaims enough space for the engine to operate before it begins creating files again. Signed-off-by: Alex Suraci <[email protected]>
vito
force-pushed
the
fix-discarded-cache-sweep
branch
from
August 27, 2026 17:32
674d2cd to
ba4e216
Compare
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.
Resetting invalid local cache state — after an unclean shutdown, a schema
mismatch, a corrupt DB — deleted the entire worker root directory inline with
os.RemoveAllbefore the engine came up.On a warm cache that is tens of gigabytes across millions of inodes. Startup
blocked for the whole delete, and the unlink storm saturated the disk queue
hard enough to stutter the host for about a minute. The engine hadn't done
anything yet; it was still taking out the trash.
Rename, then sweep. The discarded state is moved aside to a sibling
worker-trash-<unique>directory — an O(1) rename on the same filesystem — sostartup proceeds immediately. A background sweeper then removes the tree at a
bounded duty cycle: 50ms of unlinks, 200ms of rest, so the filesystem journal
drains between bursts instead of being monopolized.
The sweeper is not naive about it:
that triggers cache GC — pacing is a courtesy, not a suicide pact.
interrupted, so nothing accumulates silently.
failing the reset (recursively up front, plus an
EBUSYfallback per path).The unclean-shutdown integration test now polls the state volume until the
trash dir is actually swept, so discarded state cannot quietly leak across
resets.
New:
engine/server/trash.goand its unit tests. Changelog entry included.Independent fix, based on
main. Extracted from the LLM workspace stack(#13832–#13838); it has no dependency on those PRs and can land on its own.