Skip to content

Judge recurring occurrences by one range test and their overrides (#98) - #110

Merged
PhilflowIO merged 22 commits into
mainfrom
fix/override-occurrences
Oct 8, 2026
Merged

PhilflowIO merged 22 commits into
mainfrom
fix/override-occurrences

Conversation

@PhilflowIO

@PhilflowIO PhilflowIO commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Problem

Recurring events were judged by their original dates and by the series' own STATUS/TRANSP (#98). A cancelled or transparent single occurrence still showed as busy, an occurrence moved from the 20th to the 14th did not appear on the 14th and was still reported on the 20th, and an opaque occurrence of a transparent series did not block time.

The reviews of this PR found more under the same question, "which occurrences touch a range":

  • free/busy and the lists disagreed on a meeting running into the window
  • RECURRENCE-IDs and EXDATEs written in another form than DTSTART did not match, or matched the wrong occurrence at a DST fold (ical.js#847)
  • THISANDFUTURE overrides that name no occurrence were applied
  • ical.js tests rule candidates without a bound: a limiting BYHOUR from 1950 took 27 s, fifty such series 45 s per tool call, and BYMONTH=2;BYMONTHDAY=30 never returned (also on main)

Change

tsdav-utils 0.7.0 (npm:@philflow/[email protected], lockfile: only that entry). Since 0.5.0, moving a series' DTSTART moves its overrides; one test expectation follows. 0.7.0 also makes an EXDATE/RDATE field the whole list. Nothing in this PR writes EXDATE expecting an append; #126 covers cancelling one occurrence.

One engine, src/occurrences.js, used by free/busy, calendar_query, list_events and the event display, built on the library's expandOccurrences so dav-mcp and the write side agree on which occurrences a series has:

  • In range means the RFC 4791 §9.9 half-open test, the same for every tool.
  • RECURRENCE-ID and EXDATE as the library reads them:
    • Both are read in the series' frame by the instant they name, with a local time shown twice taken as its first pass (RFC 5545 §3.3.5).
    • A floating id is read by its digits; a date-time id on an all-day series by its date; a date id on a timed series names that day's midnight; a UTC id on a floating series names nothing.
    • An EXDATE excludes by instant; a date on a timed series excludes the whole day. A floating EXDATE in a zoned series, or a UTC one in a floating series, names nothing.
    • A series the library cannot read (e.g. a UTC UNTIL on a floating series) is reported incomplete.
  • On top of the library:
    • Occurrences are judged where they now are.
    • Overrides moved in from anywhere are found: the overrides outside the window are checked in clusters.
    • RANGE=THISANDFUTURE overrides move later occurrences by their own wall-clock move; ones that name no occurrence are ignored.
  • Near-range start: the copy handed to the library has its DTSTART moved closer to the range (or to the override checked).
    • SECONDLY–WEEKLY: to the period holding the range, for BYDAY/BYMONTH and a BYHOUR/BYMINUTE/BYSECOND that expands the rule. A moved start the rule would not generate, or one past UNTIL, is dropped, since the library counts any DTSTART.
    • MONTHLY/YEARLY: by whole months or years on the wall calendar, anchored one period before the one holding the range, so ical.js' first, possibly partial, period is never used. Only where every month or year provably holds an occurrence: a BYMONTHDAY within ±28, an ordinal BYDAY within ±4 of a month (±52 of a year), a plain BYDAY, a BYYEARDAY within ±365, a BYWEEKNO within ±52 with BYDAY, DTSTART's day 1–28, or BYSETPOS over plain weekdays within the 4 each month surely has. Where a period can be empty, ical.js shifts its INTERVAL grid.
    • COUNT rules without BY parts are cut at their computed last occurrence.
    • Walked from DTSTART instead: a limiting BYHOUR (on HOURLY), every MONTHLY/YEARLY shape whose periods can be empty (the 31st, 29 February, a fifth Monday, week 53, day 366, intersecting BY parts), MONTHLY with BYMONTH, and YEARLY BYWEEKNO without BYDAY. That is cheap for monthly and yearly series.
  • One budget per tool call, shared fairly, in two measures:
    • Rule candidates: 300 000, deterministic, at most 100 000 in any one call into the library, since a call cannot be stopped once it runs.
    • Time: 1.5 s of measured expansion work, covering the library calls and everything the engine does around them.
    • Whichever runs out first ends the expansion. Each calendar object gets at least an equal share of what is left of both, so one heavy series cannot leave the others unexpanded.
    • Bound: about 1.5 s of expansion per tool call, plus up to one library call per remaining object, since each object gets at least 20 ms and the clock is checked only before a call. So it grows with the size of the answer (20 objects with 4 000 in-range overrides each: about 10 s).
    • Under machine load a series may come back incomplete where it would not otherwise.
    • A walk needing more than 100 000 candidates is incomplete even for a lone series, e.g. DAILY;BYMONTHDAY=1,15 from 1970, which cannot start near the range.
    • Measured on this machine:
      • a year of 100 ordinary series: complete, 1.5 s total
      • 30 monthly series from 2010, or 200 yearly birthdays: complete, under 0.1 s
      • 50 series with 300–500 overrides moved in from 75 years: 2.3–2.6 s total (≈1.5 s expansion, the rest parsing and formatting)
      • MINUTELY with 3 000 moved-in overrides: 2.2 s
    • Running out means incomplete, never wrong: unchecked overrides, and whatever an unchecked THISANDFUTURE override might move, are left out. freebusy_query names each such series (with the library's reason where it cannot read one) and never answers a bare "Nothing blocks this window"; event lists say the series could not be expanded fully.
  • All-day without DTEND/DURATION lasts its day, a timed one no time (RFC 5545 §3.6.1), for every occurrence.
  • Display: times are shown as tsdav-utils converts them, so a local time shown twice at a DST change reads with its first pass's offset.
  • Zone converters are cached per VTIMEZONE definition. Copies keep only nearby EXDATEs and only the overrides in their window.
  • Order of candidates: ical.js yields a BY list in the order it is written (BYHOUR=17,9; MONTHLY;BYMONTH a year's months in list order), and expandOccurrences stops at the first candidate past until while reporting the list complete. dav-mcp reads one period past its window whenever a BY list is out of ascending order, mixes signs or has ordinals. Upstream: tsdav-utils#31.

Free/busy returns the blocking occurrences per object, and the event details print exactly those. blocksTime compares case-insensitively; an override without STATUS of a cancelled series blocks time. Listed events show their STATUS. Tool descriptions, manifest.json and the CHANGELOG ([Unreleased]) describe all of this.

Out of scope:

  • Todos: no todo path expands recurrence.
  • Stored VFREEBUSY (RFC 4791 §7.10), and judging floating times in the collection's calendar-timezone: separate issues.

Tests

  • __tests__/override-occurrences.test.js (53 tests):
    • Free/busy and queries mishandle overrides: cancelled still busy, moved-in missed #98 cases; the three tools agreeing at the window edges; RECURRENCE-ID/EXDATE frames and the DST fold; THISANDFUTURE; status
    • hang guards under 2 s: SECONDLY;BYHOUR since 1950; 50 × MINUTELY;BYHOUR; BYMONTHDAY=30 in February
    • ordinary calendars complete in every tool: 30 MONTHLY series of six shapes from 2010-2014 over a year; 200 all-day YEARLY birthdays without an end from 1950-2000 over a week (whole days)
    • fairness: a heavy series next to 20 ordinary ones, only it named
    • all-day without an end: single, weekly, override; and a timed one without an end
    • the fold display; the unreadable reason; MONTHLY;BYMONTH out of order
    • edge tests: fake start, past UNTIL, unchecked THISANDFUTURE
    • Empty periods (29 February with UNTIL, the 31st every fifth month, a BYSETPOS fifth Monday), each against the library's full expansion from DTSTART.
    • Overrides of candidates yielded out of order (BYHOUR=17,9 on MONTHLY/DAILY/WEEKLY, BYMINUTE=45,15 on HOURLY).
    • All 6 new tests fail on the previous commit and pass here.
  • Differential test (__tests__/fixtures/override-differential.mjs, 100 cases × 4 host zones run in parallel):
    • The reference is expandOccurrences from DTSTART with an unlimited budget, plus THISANDFUTURE moves, the RFC default length and the touches-range test, written separately from the engine.
    • It now generates MONTHLY/YEARLY series from 1995-2015 (ordinal BYDAY, negative BYMONTHDAY, BYSETPOS, BYMONTH, BYWEEKNO with and without BYDAY, COUNT, UNTIL) and all-day series and overrides without an end.
    • Also periods that can be empty (the 31st, 29 February, fifth weekdays, day 366, week 53, BYSETPOS past the set, DTSTART on the 29th–31st) and BY lists out of order.
    • About 15 % of cases run with a too-small budget, where the fast side may only drop occurrences.
    • 0 deviations over 200 cases × 4 seeds × 3 zones.
    • Reviewer's family probe: 0 deviations from the library's full expansion over 3 689 cases.
    • Deliberate breaks are caught: dropping the non-empty-period check, dropping the look-ahead, anchoring inside the range's period, shifting MONTHLY;BYMONTH, no validation, no lead, no THISANDFUTURE, an ignored unchecked THISANDFUTURE, a kept fake start, ignored UNTIL.
  • Re-verifier probes (review-110e):
    • monthly (30 series): complete, 0.1 s; bday (200): complete, 0.05 s
    • realistic (100 series, week / month / year): complete, 0.8 / 0.7 / 1.5 s
    • calls (MINUTELY with 3 000 moved-in overrides): 2.2 s total, budget-capped and flagged incomplete
  • Full suite: 888 tests in 37 files, plain and under TZ=UTC, America/New_York and Asia/Kolkata.

Closes #98

🤖 Generated with Claude Code

PhilflowIO and others added 5 commits October 8, 2026 10:23
A series was expanded by its original recurrence ids, so an occurrence
moved into the queried range from outside it was missed and one moved
out of it was still listed there. seriesOccurrences judges each
occurrence after its overrides apply (incl. RANGE=THISANDFUTURE) and
finds moved-in overrides from their finite list, checking with a short
walk around the RECURRENCE-ID that it is a real occurrence — so the
walk still starts just before the range, not at DTSTART.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Every occurrence of a series counted with the master's STATUS and
TRANSP at its original time: a cancelled or transparent single
occurrence still blocked time, a moved one blocked its old slot, and an
opaque occurrence of a transparent series did not block. Free/busy now
goes through seriesOccurrences, which also gives it the near-the-range
start it lacked. The event details list only what blocks the window,
each as its occurrence there, not every object the server returned.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
With occurrences listed one by one, a cancelled occurrence looked like
a meeting that takes place. The STATUS of what is shown — for a series,
the occurrence listed — is now printed.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Regression cases for #98, plus a differential check: random series
with random overrides (moved in, out, within, cancelled, transparent,
THISANDFUTURE, orphaned, EXDATEd) and random ranges, the fast path
against a plain expansion from DTSTART, in four host zones. A spy on
the expansion pins that the walk still starts near the range.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Closes #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PhilflowIO and others added 3 commits October 8, 2026 11:21
Review of #110 found that "which occurrences touch a range" had several
answers. Free/busy counted overlap while the lists counted "starts in
range, end included", so a running meeting was busy but "not in range".
Overrides were matched to occurrences by the text of RECURRENCE-ID, so a
UTC id on a zoned or floating series missed. ical.js applied
THISANDFUTURE overrides that name no occurrence. Moved-in overrides
re-walked from DTSTART one by one (34 s for 200 of them). A capped walk
reported busy time as free.

src/occurrences.js now answers it once for every tool:
- RFC 4791 9.9 half-open overlap, instants read like toInstant
- RECURRENCE-IDs aligned to DTSTART's frame by instant before relating;
  THISANDFUTURE applied here, only when its id is an occurrence
- overrides in range plus THISANDFUTURE ids validated in one walk
  that restarts near each id
- near-range start also for HOURLY/MINUTELY/SECONDLY, BYHOUR/BYMINUTE/
  BYSECOND, and COUNT without BY parts (cut at its last occurrence)
- truncation reported: free/busy names the series, lists say an earlier
  occurrence may exist

Free/busy returns the blocking occurrences per object and the details
print exactly those. blocksTime moves next to todoStatus and compares
case-insensitively. The differential test now runs the callers
themselves against an independent reference expanded once per case,
including capped series.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
calendar_query and list_events now list a recurring event as its first
occurrence touching the range, cancelled ones included with their
Status; freebusy_query names a series it could not expand fully. The
descriptions say so, so a model does not read a running meeting or a
cancelled entry as an error.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The entry described the first fix only; it now covers the range test,
RECURRENCE-ID matching, the wider near-range start, the cap warning,
and that an override without STATUS of a cancelled series stays busy.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PhilflowIO PhilflowIO changed the title Judge recurring occurrences by their overrides (#98) Judge recurring occurrences by one range test and their overrides (#98) Oct 8, 2026
PhilflowIO and others added 7 commits October 8, 2026 12:38
Re-review of #110 (2855b1f) found:
- each override re-walked from days before its RECURRENCE-ID with a cap
  per walk: MINUTELY since 2000 + 1000 overrides took 123 s
- dense rules spent the cap on the 26 h pre-range slack (Busy (0))
- capped results could contain wrong occurrences (an unchecked
  THISANDFUTURE not applied)
- a timed RECURRENCE-ID on an all-day series took the UTC day
- floating EXDATEs matched as UTC while RECURRENCE-IDs use the host
  clock

Now one 25 000-step budget bounds a whole call. Walks start at the
period that holds the id or range (whole periods on DTSTART's wall
clock), dropping a shifted start the rule would not generate, so an
override costs a few steps. Under truncation, unchecked overrides and
anything an unchecked THISANDFUTURE might move are left out: incomplete,
never wrong. A timed id on an all-day series names its written date;
EXDATEs are aligned like RECURRENCE-IDs. Overrides also match by the
instant their id names (the aligned wall clock is ambiguous at a DST
fold). Limiting BYHOUR/BYMINUTE/BYSECOND (BYHOUR on HOURLY) is walked
from DTSTART: ical.js does not step it on a fixed grid. ical.js no
longer looks up overrides at all.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The entries now describe the per-call step budget, the start at the
period holding the range, the incomplete-but-not-wrong guarantee, and
how a timed RECURRENCE-ID on an all-day series and EXDATEs on a floating
series are read.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The wall-clock guards measured 1.18 s on a loaded two-core CI runner for
work that takes 0.17 s locally, while the differential's child processes
share the CPU. Expansion steps are what tells the fixed pass (a few per
override) from the old one (hundreds or thousands per override), and
they do not depend on the machine; a 5 s bound stays as a stall guard.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
0.7.0 exports what the occurrence engine needs: a bounded expansion
(expandOccurrences with a shareable budget) and zone conversion that is
right at DST changes (resolveZone). The lockfile changes only that entry.

Since 0.5.0, moving a series' DTSTART moves its overrides with it; the
one test that pinned the old behaviour follows.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Final review of #110 found two faults with one root: dav-mcp read
occurrences with its own ical.js walk. ical.js converts UTC to local up
to an hour off near DST changes (ical.js#847), so EXDATEs and
RECURRENCE-IDs at the autumn fold matched the wrong occurrence; and it
tests rule candidates without a bound, so a limiting BYHOUR from 1950
took 27 s, fifty such series 45 s per call, and BYMONTHDAY=30 in
February never returned.

The expansion is now the library's expandOccurrences, the reader the
write side uses, so both agree on overrides and EXDATEs (by instant,
first pass at a fold). On top of it: the copy expanded starts at the
period holding the range (or the override checked), overrides moved in
from anywhere are checked in clusters, THISANDFUTURE moves later
occurrences. One budget per tool call bounds every candidate and every
library call; out of budget means incomplete, never wrong.

A shifted start the rule would not generate, or one past UNTIL, is
dropped (the library counts any DTSTART). Converters are cached per
VTIMEZONE text and copies keep only nearby EXDATEs, as neither is
budgeted. Copies are deep clones: toJSON is ical.js's live jCal.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The entries claimed EXDATEs matched by instant and a near-range start for
any BYHOUR; neither held. They now describe the library's reading of
RECURRENCE-ID and EXDATE, the expanding-only near-range start, the
per-call budget, and the 0.7.0 bump with its EXDATE write change.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PhilflowIO and others added 4 commits October 8, 2026 22:07
Review of #110 (f327ead) found ordinary calendars reported incomplete:
MONTHLY and YEARLY series walked from DTSTART, so 30 monthly series
from 2010 or 200 yearly birthdays spent one 150 000 budget and most
came back incomplete; and one heavy series could starve the rest.

MONTHLY/YEARLY now start a whole number of months or years later,
anchored one period before the one holding the range so ical.js'
first, possibly partial period is never used (ordinal BYDAY, negative
BYMONTHDAY, BYSETPOS covered; MONTHLY;BYMONTH and YEARLY BYWEEKNO
without BYDAY excluded). Each object gets a fair share of the call's
budget. A request budget charges measured time (400 000 units, ~2 s),
so the stated bound holds; only overrides in the main window go to it.

Also: an all-day occurrence without DTEND/DURATION lasts its day (RFC
5545 3.6.1); times are shown via tsdav-utils (exact at a DST fold); an
unreadable series is named with the library's reason; MONTHLY;BYMONTH
gets a year of lookahead, as ical.js yields its months out of order
and the library stops at the first past `until`.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Describes the MONTHLY/YEARLY near-range start, the time-charged budget
with its measured bound and fair shares, the all-day default length,
the display conversion and the reason given for an unreadable series.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
CI ran one degenerate series for 2.4-2.7 s: the timed budget counted
candidates and measured time on one scale, so a single library call
could spend all its units on candidates before any time was charged,
and on slower CPUs that is far over the stated bound.

Candidates (300 000 per tool call, at most 100 000 per library call)
and time (1.5 s of expansion) are now separate, each shared fairly by
the objects of a call; whichever runs out first ends the expansion. The
time can overrun by one capped call at most.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PhilflowIO and others added 2 commits October 8, 2026 23:09
Review of #110 (81b865d) found two ways to a wrong answer reported as
complete. A MONTHLY/YEARLY start moved into a period without a valid
day makes ical.js shift its INTERVAL grid, roll to 1 March or stop
(29 February from 1980 gave 1 March 2026; the 31st every fourth month
lost 1 December 2028). And ical.js yields BY lists in written order
(BYHOUR=17,9) while the library stops at the first candidate past its
window, so an override of the skipped candidate vanished.

The start now moves only where every month or year provably holds an
occurrence (BYMONTHDAY within ±28, ordinal BYDAY within ±4 of a month,
BYSETPOS within the weekdays every month has, ...); the rest walk from
DTSTART. Any BY list out of ascending order (or mixed signs, ordinals,
MONTHLY;BYMONTH) reads one period past the window.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The time bound is 1.5 s plus up to one library call per remaining object,
so it grows with the answer; load can flag a series incomplete; a walk
over 100 000 candidates is incomplete even alone. Also the provably
non-empty periods the near-range start now requires.

Refs #98

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PhilflowIO

Copy link
Copy Markdown
Owner Author

Review summary: reviewers A (correctness, independent RFC oracle, live Baïkal) and B (callers/design), then five verification rounds. Final state: one occurrence engine on tsdav-utils 0.7.0 (expandOccurrences + dav-mcp's moved-in override pass and THISANDFUTURE), one half-open range test across free/busy, calendar_query and list_events, RECURRENCE-ID/EXDATE matched by instant (RFC 5545 §3.3.5), near-range start only for rule shapes where every period provably has an occurrence, look-ahead for non-monotonic BY lists, per-call budget with per-object fairness, flagged-incomplete instead of wrong. Last round: 6,240-case fuzz 0 unexplained; MONTHLY/YEARLY sweep 0 PR-only deviations; birthday/monthly calendars complete; my own re-run of the reviewer's empty-period probe: 1,500 cases, 0 deviations; dropped-override probe: all shapes found. Documented limits: time bound grows with response size; load can mark series incomplete (always flagged). Follow-ups: tsdav-utils#31 (non-monotonic iteration upstream), dav-mcp#117 (floating times). CI green.

@PhilflowIO
PhilflowIO merged commit 1c4dd2f into main Oct 8, 2026
10 checks passed
@PhilflowIO
PhilflowIO deleted the fix/override-occurrences branch October 8, 2026 21:13
PhilflowIO added a commit that referenced this pull request Oct 8, 2026
Brings in the occurrence engine (#110) and tsdav-utils 0.6 adoption with
the write-refusal mapping (#114). Resolved so that:
- every library refusal goes through explainWriteRefusal; the
  occurrence-name refusals stay composed in occurrence-edits and hand
  everything else to it. Library sentences that name options the tools
  do not have (cancelOccurrences, list mode "replace", absoluteTime
  "as-given") are translated or replaced, and an orphaning rule change
  names restore_occurrences in the same call or the raw tool;
- the series-change reply compares the object after cancel/restore with
  the one after the fields, and counts exclusions, extra dates and
  overrides by occurrence name (occurrence-names.js), not by stored text
  or position; the Occurrences line stays separate;
- tool descriptions combine both, kept compact: cancel/restore through
  the parameters, move or retitle one occurrence through the raw tools,
  start_date is the series' first start;
- the CHANGELOG has one tsdav-utils 0.7.0 line, points #126 to
  cancel_occurrences, and corrects how to start a series later.

Refs #126

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PhilflowIO PhilflowIO mentioned this pull request Oct 9, 2026
3 tasks done
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.

Free/busy and queries mishandle overrides: cancelled still busy, moved-in missed

1 participant