Skip to content

feat: add skip missed policy and actor-facing reminder run history - #98

Open
cardmagic wants to merge 1 commit into
mainfrom
feat/js-37-remaining
Open

cardmagic wants to merge 1 commit into
mainfrom
feat/js-37-remaining

Conversation

@cardmagic

Copy link
Copy Markdown
Owner

Why

Remaining work on #37 (portable durable scheduling): skip as a missed-run policy, actor-facing last run / occurrence / error on both adapters, the timing contract in JS docs, and one conformance suite both adapters run.

What

  • skip. Public missed / missedPolicy is "latest" | "all" | "skip" on ReminderOptions, ReminderIntent, ScheduledReminder, ReminderRecord, and the Durable Objects stored missed value. SQL CHECK accepts all three. Default when missed is omitted stays latest. Docs name skip and say latest is the PRD run_once and all is catch_up. No rename.
  • Recurring skip. At the due pass, with now N and stored next run T and interval I: if T <= N < T+I, enqueue once, increment occurrence, set last run. If N >= T+I, do not enqueue, do not increment occurrence, do not set last run, and move to the next aligned time still in the future. A skipped window creates no mailbox message. latest and all are unchanged. SQL still decides the next run at enqueue. Durable Objects still re-arms at consume, and jumps a skipped window at the due pass. One-shot skip is stored if requested and does not change one-shot fire.
  • ScheduledReminder. lastRunAtMilliseconds (null if never enqueued), occurrence (starts at 0, +1 per enqueue; the PRD "attempt"), and errorName (null unless paused). Replace keeps last run and occurrence and clears errorName, including the in-turn read. A read still applies this turn's staged intents, including completed rows before hiding them, so replace of a completed one-shot matches SQL ON CONFLICT. Resume does not reset last run or occurrence. Operator ReminderRecord does not gain last run. Durable Objects generation is not exposed. Mailbox retry count is not on ScheduledReminder.
  • Durable Objects pause. Writes errorName from the mailbox message when it pauses on an exhausted mailbox or PayloadTooLarge.
  • SQL schema version 15. Adds last_run_at_ms and widens the missed-policy check. Existing latest / all rows stay valid. Other stored reminder data is not rewritten. Idempotent when the current CREATE TABLE already has that shape. Test installs it on a database that already had the current schema, after downgrading the check and dropping the column.
  • Docs. Timing contract next to schedule({ at }): stores at.getTime() as epoch ms; invalid Date is TypeError (reminder time must be valid); compared with SQL connection nowMilliseconds or a test now, or Durable Objects Date.now() at the due pass; retry and retention follow the mailbox message; no time-zone or clock-skew guarantee. Replaces the sentence that omitted occurrence because only SQL had it. Cancel paragraph from docs: replace stale unschedule rationale #97 is unchanged.
  • Suite. test/support/portable-scheduling-contract.ts, actor PortableReminders. Invoked from the SQL portable tests (a describe that does not call runtime.run()) and from the Durable Objects contract tests. Covers create, replace, cancel, recurring and one-shot execution, latest / all / skip including Durable Objects all catch-up, the new fields including pause, restart recovery (SQL claim owner gone; Durable Objects constructor / alarm() / storage alarm / 30s retry), authorization (fired reminder still runs when authorizeMessage returns false; external enqueue of the same operation still goes through it), and a fired reminder not delivered twice.

Cancel still returns nothing. No reschedule method. authorizeMessage default is unchanged. No module-level external-enqueue flag on the shared Durable Objects test worker.

Checks

On Node 24.22: format:check, check, test (865 passed, 32 skipped), build, test:cloudflare (70 passed). PostgreSQL and MySQL CI are not run here.

Do not merge from this PR alone. Related to #37; this does not close it.

Accept `skip` beside `latest` and `all` on both the SQL and Durable Objects
adapters. Default missed policy stays `latest`. `latest` is the PRD
`run_once`. `all` is the PRD `catch_up`.

A recurring `skip` reminder considered at N enqueues once when T <= N < T+I.
When N >= T+I it does not enqueue, does not increment occurrence, and does
not set last run. It moves to the next aligned time still in the future.
`latest` and `all` are unchanged. SQL still decides the next run at enqueue.
Durable Objects still re-arms at consume, and jumps a skipped window at the
due pass without a mailbox message.

`ScheduledReminder` now includes `lastRunAtMilliseconds`, `occurrence`, and
`errorName` on both adapters. Occurrence is the PRD "attempt". It starts at
0 and increases by 1 on each enqueue. Replace keeps last run and occurrence
and clears `errorName`, including the in-turn read. Resume does not reset
them. Durable Objects writes `errorName` when it pauses on an exhausted
mailbox or a payload that is too large. Operator `ReminderRecord` does not
gain last run.

SQL schema version 15 adds `last_run_at_ms` and widens the missed-policy
check to include `skip`. Existing `latest` and `all` rows stay valid. The
migration is a no-op when the current CREATE TABLE already has that shape.

One portable scheduling suite covers create, replace, cancel, execution,
missed policies, the new fields, restart recovery, authorization of a fired
reminder versus an external enqueue, and duplicate delivery. SQL and Durable
Objects both run it. `docs/api.md` states the timing contract next to
`schedule({ at })` and documents the new fields in place of the sentence
that omitted occurrence.
@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5 · The PR appears safe to merge, with non-blocking gaps in migration and replacement tests.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect reminder scheduling and inspection across both adapters.

The PR appears safe to merge, with non-blocking gaps in migration and replacement tests.

Findings

  1. P2 Database upgrades lack coverage ▶
  2. P2 Replacement states lack coverage ▶
Fix with agent prompt
### Issue 1
test/dead-letters.test.ts:233-234
The new upgrade test always uses SQLite. It never exercises the PostgreSQL and MySQL branches of `missedPolicyAllowsSkip` and `replaceMissedPolicyCheck`, which use different queries and statements to replace checks. Upgrade failures on those databases could go unnoticed.

Add tests for both backends that start with the old check, preserve existing reminders, accept `skip`, and succeed on a second install.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
test/support/portable-scheduling-contract.ts:262-270
The shared suite only replaces scheduled reminders. It resumes the paused reminder before replacing it, and never replaces a completed one-shot. The tests could therefore miss an old error surviving replacement or run history being lost.

Add direct replacement tests for both states. Assert that the in-turn read matches the saved reminder, keeps `occurrence` and `lastRunAtMilliseconds`, and clears `errorName`. This also protects the new completed-row ordering in `#reminderView`.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR adds skip for recurring reminders and exposes run history on both adapters.

  • Recurring reminders can skip windows they missed by too much.
  • Actors can see when reminders ran and why they paused.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Due recurring reminder] --> B{Skip policy and a full interval late?}
  B -->|Yes| C[Move to next aligned future time]
  C --> D[Keep run history unchanged]
  B -->|No| E[Enqueue mailbox message]
  E --> F[Increase occurrence and save last run]
  F --> G{Adapter}
  G -->|SQL| H[Advance schedule at enqueue]
  G -->|Durable Objects| I[Advance schedule after consumption]
Loading

Reviews (1) · Last reviewed commit: "feat: add skip missed policy and actor-f..." · Reviewed by Greptile

Comment thread test/dead-letters.test.ts
Comment on lines +233 to +234
runtime = configuredRuntime({ database: sqlite({ path }) })
await runtime.install()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Database upgrades lack coverage

The new upgrade test always uses SQLite. It never exercises the PostgreSQL and MySQL branches of missedPolicyAllowsSkip and replaceMissedPolicyCheck, which use different queries and statements to replace checks. Upgrade failures on those databases could go unnoticed.

Add tests for both backends that start with the old check, preserve existing reminders, accept skip, and succeed on a second install.

Knowledge Base Used: SQLite, PostgreSQL, and MySQL adapters

Prompt To Fix With AI
This is a comment left during a code review.
Path: test/dead-letters.test.ts
Line: 233-234

Comment:
**Database upgrades lack coverage**

The new upgrade test always uses SQLite. It never exercises the PostgreSQL and MySQL branches of `missedPolicyAllowsSkip` and `replaceMissedPolicyCheck`, which use different queries and statements to replace checks. Upgrade failures on those databases could go unnoticed.

Add tests for both backends that start with the old check, preserve existing reminders, accept `skip`, and succeed on a second install.

**Knowledge Base Used:** [SQLite, PostgreSQL, and MySQL adapters](https://app.greptile.com/-/switch-tenant?tenant=craftsmanfounder&next=%2Fcustom-context%2Fknowledge-base%2Fcardmagic%2Fsolid-objects-js%2F-%2Fdocs%2Fdatabase-adapters.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +262 to +270
const replaced = await reference.replaceAndInspect({ at: future + INTERVAL, missed: "all" })
expect(replaced).toMatchObject({
status: "scheduled",
occurrence: paused!.occurrence,
lastRunAtMilliseconds: paused!.lastRunAtMilliseconds,
errorName: null,
missedPolicy: "all",
runAtMilliseconds: future + INTERVAL,
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Replacement states lack coverage

The shared suite only replaces scheduled reminders. It resumes the paused reminder before replacing it, and never replaces a completed one-shot. The tests could therefore miss an old error surviving replacement or run history being lost.

Add direct replacement tests for both states. Assert that the in-turn read matches the saved reminder, keeps occurrence and lastRunAtMilliseconds, and clears errorName. This also protects the new completed-row ordering in #reminderView.

Prompt To Fix With AI
This is a comment left during a code review.
Path: test/support/portable-scheduling-contract.ts
Line: 262-270

Comment:
**Replacement states lack coverage**

The shared suite only replaces scheduled reminders. It resumes the paused reminder before replacing it, and never replaces a completed one-shot. The tests could therefore miss an old error surviving replacement or run history being lost.

Add direct replacement tests for both states. Assert that the in-turn read matches the saved reminder, keeps `occurrence` and `lastRunAtMilliseconds`, and clears `errorName`. This also protects the new completed-row ordering in `#reminderView`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@context7

context7 Bot commented Nov 29, 2026

Copy link
Copy Markdown

Docs7 for cardmagic/solid-objects-js

Result Status Action
Deployment ➖ Not used —
Content review ➖ Did not run. This site has no agent runs available this month. Wait for the monthly reset or check your Docs7 plan. —

Commit b38d5a2

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.

1 participant