Repository navigation
Conversation
Benchmark resultsschedule — dispatch and reconcile at scale (4 cores, 10000 schedules: 30% cron / 70% interval, 30 ticks)
115680 occurrences dispatched, 3856 per tick average. Selecting one minute of coverage spends 0.081% of the 60s tick interval. Shared CI runners — treat absolute numbers as rough, compare modes within a run. Commit d3500f2. |
|
| if ($syncedUntil !== null) { | ||
| $seen = $this->moment($syncedUntil); | ||
| foreach ($this->entries as &$entry) { | ||
| $entry['coverFrom'] = $this->coverFrom($entry['activeFrom'], $seen, $entry['replaced']); |
There was a problem hiding this comment.
When both replicas load the same replacement before handoff, the follower keeps replaced=true even after the leader dispatches and commits that replacement. During takeover, this makes the follower ignore the predecessor's committed syncedUntil and restore coverage from activeFrom, so it can deliver the replacement's occurrences again. The rebase must distinguish replacements already covered by the predecessor from replacements seen only by the follower.
Knowledge Base Used: Scheduling and email delivery
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/schedule/src/Scheduler.php
Line: 780
Comment:
**Takeover replays replacements**
When both replicas load the same replacement before handoff, the follower keeps `replaced=true` even after the leader dispatches and commits that replacement. During takeover, this makes the follower ignore the predecessor's committed `syncedUntil` and restore coverage from `activeFrom`, so it can deliver the replacement's occurrences again. The rebase must distinguish replacements already covered by the predecessor from replacements seen only by the follower.
**Knowledge Base Used:** [Scheduling and email delivery](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/utopia-php/monorepo/-/docs/scheduling-email-delivery.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
The replay is reproducible, but treating it as a merge-blocking correctness defect requires a stronger guarantee than this library provides. Scheduler and Occurrence::key() explicitly promise at-least-once delivery across handoff, not exactly-once delivery.
I ran the same two-scheduler reproduction twice: both load v1 at 03:00:30, then read at 03:01:00 around a backdated v2 update (active from 03:00:20, due 03:00:45). The follower sees v2 in both runs; the leader sees v1 in one run and v2 in the other. Snapshot reads starting at the same time need not observe the same side of an update.
Both runs produce exactly the same shared claim: coveredUntil=03:01:00 and syncedUntil=03:01:00 (same token and expiry too). In the first run the leader delivers nothing; in the second it delivers [email protected]. After lease expiry the follower delivers that same key in both runs, then commits and does not replay on the next tick.
The successor therefore cannot distinguish these cases from the shared watermark. Suppressing the second run's duplicate also suppresses the first run's required recovery. Retaining pending replacement coverage deliberately favors duplicates over silent loss, consistent with the existing contract. Distinguishing them would need durable per-definition coverage or a stronger source revision protocol, a separate API/storage change outside this rollout fix.
Documented this specific handoff limitation in 7bd8cd2. Keeping the conservative behavior; consumers use the stable occurrence key for deduplication. Please reassess the P1 against the at-least-once contract.
There was a problem hiding this comment.
You're right. Given the explicit at-least-once contract, this is not a merge-blocking correctness defect. The two executions are observationally indistinguishable from the shared claim, so suppressing the replay would also risk suppressing the only delivery; retaining pending replacement coverage is the correct conservative choice. The replay is an expected handoff limitation, and Occurrence::key() gives consumers the intended deduplication mechanism. With the limitation documented, I withdraw the P1.
|
packages/schedule now lives in appwrite/appwrite; ported as appwrite/appwrite#13913. Thanks! |
A replacement scheduler currently waits for leadership before loading its source. If loading takes several minutes, a surge rollout still stops dispatch during takeover and can exceed the recovery window.
Reconcile on every replica before attempting leadership, keeping followers prepared while the leader dispatches. Add
isReady()for completed initial loading (using the existing reconciliation cursor), leave the claim untouched when initial loading fails, and rebase a follower's pending discovery coverage against the predecessor's committed source view so takeover does not replay changes already delivered.Document how applications can use readiness with a shared Redis store, graceful shutdown, and a surge rollout. The application still needs to expose readiness, monitor dispatch progress separately, and wire termination signals. Readiness stays true after initialization even if a later refresh fails, matching the existing last-good-view behavior. Delivery remains at-least-once; follower reads add source load, and slow reconciliation still pauses an active leader's own loop. Kubernetes rollout behavior needs an application-level staging drill; this PR tests the library handoff only.
Validation:
bin/monorepo check schedule --fix: Pint, PHPStan, and Rector passed.bin/monorepo test schedule: 100 unit tests / 256 assertions and 10 real-Redis tests / 96 assertions passed.bin/monorepo validateandvale packages/schedule/README.mdpassed.A takeover regression also proves a late-discovered one-shot is recovered when the predecessor advanced coverage using an older source view. This failed with the simplified clear-only rebase and passes when takeover recomputes coverage from the retained effective timestamp.
Pending backdated replacements retain their coverage across takeover until committed. A regression covers the missed replacement one-shot, and failed-initialization coverage verifies another scheduler can deliver against the shared store without asserting claim representation.