Skip to content

fix(maintenance): hold a timed-out purge instead of detaching it (#1103) - #1247

Merged
cameri merged 3 commits into
rewrite/mainfrom
contrib/1103-purge-in-flight
Nov 26, 2026
Merged

cameri merged 3 commits into
rewrite/mainfrom
contrib/1103-purge-in-flight

Conversation

@chappie-daemon

@chappie-daemon chappie-daemon commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Lands the fix for #1103. The first two commits are AgrimTawani's, exactly as written on their
fork (6269d9e on c75a92c); the third is mine and touches only the test file, because the
late-result test could not fail — deleting log_late_purge(previous.handle.await) left every
assertion passing. It now captures the log line and asserts the counts on it; with the call
removed the test reports 9 passed, 1 failed.

Both of the author's commits keep their authorship: the repository allows merge commits only
(squash and rebase are off).

A retention purge that outlived the pass's 5 s cap used to be detached rather than stopped: the pass
returned, the loop cleared its running flag, and the next tick started another purge. The worker now
holds the timed-out purge, the next pass waits on it again with the same cap instead of starting a
second one, and reports its counts if it finishes then. A purge that finishes between passes has its
result logged rather than lost. An overlapping pass can no longer overwrite a held purge.

Related Issue

Closes #1103.

Motivation and Context

A store whose cleanup is slower than the maintenance interval accumulated purges competing for the
same database. Aborting a store write midway was rejected: a purge that never returns now holds
retention until it does or the relay restarts, which is stated in the module doc, the ADR and the
changeset rather than left implicit.

How Has This Been Tested?

  • cargo test -p nostream-services --test maintenance — 10 passed, the target 10 more times back to
    back with no failures, and the late-log assertion proved by deleting the call it names
  • cargo test --workspace --all-features — 1820 passed, 0 failed
  • cargo fmt --all --check and cargo clippy --workspace --all-targets --all-features -- -D warnings
    — clean
  • merges cleanly onto rewrite/main 6d1454b1; feat(mcp): the maintenance tools, the counts the pass drops, and the run record #1226 does not touch these files

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

AgrimTawani and others added 2 commits November 24, 2026 14:50
…tarting another

A purge that outlived its cap was detached, not stopped: the pass returned,
the loop cleared its running flag, and every later tick spawned another
purge, so a store slower than the interval piled up purges against the same
database. The worker now holds the timed-out purge's handle. The next pass
waits on it again, with the same cap, instead of starting a second one, and
reports its counts if it finishes then. A purge that finishes between passes
has its result logged, and only then does a pass start a new one.

A purge that never returns now holds retention until it does or the relay
restarts; each pass that waits on it logs how many passes it has waited.
The loop logs each pass's outcome.

Closes #1103

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, and test the late arm

From review on #1103:
- store_outstanding_purge no longer overwrites a held purge; an overlap
  is a debug_assert and, in release, an error log rather than a silent
  detach
- a test reaches the arm that reads a purge which finished between
  passes and starts a new one
- ADR 0019 D1/D3 no longer say the loop discards the outcome; D1 records
  the two new PassOutcome fields
- purge_started is set at each arm rather than derived from the counter
- the run_pass doc names what a cancelled or overlapping pass does
- the still-running warning fires on the first wait and every tenth

Refs #1103

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

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8750ba14-c0fa-4322-a55c-eedad496ee03

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@changeset-bot

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cd0bfd8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; the previous finding is addressed and no new actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous finding is addressed and no new actionable issues were found.

Summary

The worker keeps a timed-out purge and waits on it again instead of starting another.

  • Timed-out retention purges stay tracked until a later pass finishes them.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Maintenance pass] --> B{Held purge?}
  B -->|No| C[Start purge]
  B -->|Still running| D[Reuse purge]
  B -->|Finished| E[Log late result]
  E --> C
  C --> F[Run other maintenance steps]
  D --> F
  F --> G[Wait up to the cap]
  G -->|Finished| H[Return result]
  G -->|Timed out| I[Keep purge for next pass]
Loading

Reviews (2) · Last reviewed commit: "test(maintenance): pin the late purge's ..." · Reviewed by Greptile

… be silenced

The late-purge case asserted only that a fresh purge started; deleting log_late_purge(previous.handle.await) left every assertion passing. Capture the formatted log through a subscriber installed in the test binary and assert the line and its counts. Removing the call now fails the test (9 passed, 1 failed), which the previous version did not.
@cameri
cameri merged commit a4312b6 into rewrite/main Nov 26, 2026
19 checks passed
@cameri
cameri deleted the contrib/1103-purge-in-flight branch November 26, 2026 20:22
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.

3 participants