Skip to content

fix: reserve the once slot on batch and digest paths, clear the cron deadline on deregistration (1.6) - #999

Merged
scttbnsn merged 1 commit into
dev/v1.6from
fix/v1.6-once-reservation-deadline
Sep 4, 2026
Merged

scttbnsn merged 1 commit into
dev/v1.6from
fix/v1.6-once-reservation-deadline

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Backport of #997 to the 1.6 line, cherry-picked from 680eee1. All six code files applied clean; only CHANGELOG conflicted because 1.6's Unreleased Fixed section has its own bullets, resolved by appending the new one.

What it fixes, same as on 1.8:

  • Batch and digest once eligibility reserve the slot instead of reading history, so a manual scan overlapping a cron scan can no longer send the same candidate twice in batch or digest mode. Reservations are tracked in their own collection and released in a finally; the digest flush reserves exactly what it sends and drops anything already notified; retry-buffer containers reserve too. Both new sites are gated on once like the existing ones, so once=false behaviour is unchanged.
  • The cron-scan deadline timer is cleared on deregistration, the race settles with a deregistration sentinel without logging, a late cleanup cannot clear a newer scan's handle, and a scan requested after deregistration (the pending docker-event debounce, the startup and discovery timers) returns without starting.

16 new tests, all failing against the previous code. Reviewed on #997 by Codex (three findings fixed there) and CodeRabbit (one real finding fixed, one refuted and filed as DR-72).

Three comments that named the discovery-settle timer were reworded because 1.6 has no pending-discovery path (dropped from #991 for the same reason); no code hunk was dropped. 11 of the 16 new tests fail against the 1.6 base, the other five are the deliberate still-works guards.

…ear the cron deadline

* fix(triggers): reserve the once slot on batch and digest paths

The once=true reservation from #979 only covered the simple path. Batch
and digest eligibility still read the notification history without
reserving, and that history is written after the send resolves, so a
manual single-container scan overlapping a cron scan passed the check in
both evaluations. Batch sent the same candidate twice; digest re-buffered
it behind an in-flight flush, which made the post-send identity delete
skip the entry and the next flush send it again.

Both eligibility checks now take the same synchronous reservation.
handleContainerReports tracks the reservations it took in its own array
rather than deriving them from the business-id map, which can replace one
reserved result with another, and releases them in a finally.
handleContainerReportDigest releases its own in a finally, and
flushUpdateDigestBuffer holds one for exactly the results it is sending
so a report that lands mid-flush is turned away.

* fix(watcher): clear the cron-scan deadline timer on deregistration

The deadline that bounds a single-flight cron scan lived entirely in the
closure that raced it, so resetCronWatchState() could not reach it.
Deregistering a watcher while its watch() was stalled left a refed timer
running to the full deadline, which then logged "exceeded its deadline"
against a watcher that no longer existed, and the call that started the
scan plus every caller coalesced into it stayed pending on a watch() that
may never settle.

The timer and a cancel resolver now live on the watcher as a per-scan
handle. resetCronWatchState() clears the timer and cancels the race with
its own sentinel, so every caller resolves to the same empty result the
maintenance-window skip uses and nothing warns about a deadline that was
never missed. The final cleanup compares the handle by identity before
clearing it, so a late settlement cannot take a newer scan handle with
it.

* fix(triggers): honour a failed once reservation in retries and digest flush

Two send paths reached triggerBatch without passing the once gate, so
reserving on the eligibility check alone did not close them.

The digest flush substitutes the current store container for the buffered
one at send time. When that substitute was a result an earlier flush had
already sent, the flush sent it again and the post-send identity-guarded
delete then evicted the newer candidate the buffer was actually holding,
losing a real update. The flush now honours the reservation it takes: a
container whose current state was already digested is dropped from the
send and its buffer entry evicted the same way a revalidation miss evicts
one, and a genuinely pending update re-enters the buffer on the next scan.

Entries pulled out of the batch retry buffer took no reservation at all,
so two overlapping batches after a failed send both carried the same entry
to triggerBatch. They now take the same reservation fresh reports do and
are tracked in the same collection released in the finally. A retry only
exists because a send failed and recorded no history, so a reservation
that fails means the result is already sent or in flight elsewhere and the
retry is spent: it is dropped and cleared, and a send that fails again
re-buffers it from the catch.

* fix(watcher): refuse a cron scan on a deregistered watcher

deregisterComponent() resets the single-flight cron state, but timers
captured before it still fire afterwards: the docker-events debounce, the
startup delay, the discovery-settle timer and the maintenance-window queue
all call watchFromCron from a closure. Each one started a full watch()
against a torn-down watcher and published a fresh refed deadline handle
that the reset could no longer reach, so the handle added for the
deregistration fix was reintroduced right after it was cleared.

watchFromCronOrchestration now answers a deregistered watcher with the
same empty result the deregistration path uses, before starting a scan or
publishing a handle. init() clears the flag, so a re-registered watcher
scans again.

just-debounce 1.1.0 exposes no cancel, so the pending docker-events
timeout cannot be cleared at teardown and fires up to five seconds later.
Its callback now stops on the same flag, which keeps the dead scan off the
call stack, and catches instead of discarding the promise with a bare
void, which would have surfaced a failed scan as an unhandled rejection.

* fix(triggers): gate the retry and digest-flush reservations on once

The two reservation sites added for the retry buffer and the digest flush
called reserveOnceNotificationSlot() unconditionally, unlike all three
eligibility call sites, which return early when `once` is off. That method
opens with a plain history read and recordNotifiedForResult() runs whether
or not `once` is set, so under once=false both new sites read back history
their own previous send had just written.

In digest mode the flush sent and recorded, the next scan re-buffered the
same unchanged result as once=false intends, and the flush then evicted
that entry instead of sending it, so the digest went out exactly once ever.
On the retry path a container delivered by an earlier successful batch and
later parked in the retry buffer by a failure already had matching history,
so its retry was dropped rather than retried.

Both sites now reserve only when `once` is set, which restores the
once=false path to sending exactly as it did before. Nothing is reserved
there, so the releases in the finally blocks stay no-ops.

The earlier reasoning held only for once=true, where a prior successful
send of the same hash blocks the next send at eligibility and the retry
buffer can never receive an entry whose history already matches.

(cherry picked from commit 680eee1)
@scttbnsn

scttbnsn commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@vercel

vercel Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
drydockdemo-website Ready Ready Preview Sep 4, 2026 5:13am UTC

@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

Deployment failed for project drydock-website with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/codeswhat?upgradeToPro=build-rate-limit

@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: e3b19f62-8dbf-4b4f-be20-c690e591aa50

📥 Commits

Reviewing files that changed from the base of the PR and between 6e00609 and 0572055.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (6)
  • app/triggers/providers/Trigger.test.ts
  • app/triggers/providers/Trigger.ts
  • app/watchers/providers/docker/Docker.test.ts
  • app/watchers/providers/docker/Docker.ts
  • app/watchers/providers/docker/docker-cron-watch.test.ts
  • app/watchers/providers/docker/docker-cron-watch.ts

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

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@biggest-littlest biggest-littlest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cherry-pick of #997 (reviewed there by Codex and CodeRabbit); code hunks identical to 1.8, only three comments reworded for the missing discovery-settle path. CodeRabbit is rate limited on this one.

@ALARGECOMPANY ALARGECOMPANY left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cherry-pick of #997 (reviewed there by Codex and CodeRabbit); code hunks identical to 1.8, only three comments reworded for the missing discovery-settle path. CodeRabbit is rate limited on this one.

@scttbnsn
scttbnsn merged commit aa9ec5b into dev/v1.6 Sep 4, 2026
31 of 33 checks passed
@scttbnsn
scttbnsn deleted the fix/v1.6-once-reservation-deadline branch September 4, 2026 05:36

This branch was successfully deployed

1 active deployment
Preview – drydockdemo-website — 05720559 Deployed Sep 4, 2026 by vercel[bot]
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