Skip to content

fix(cache): extract shared date patterns to internal/dates and drop false positives - #1511

Merged
okwasniewski merged 1 commit into
e2e-inc:mainfrom
Mohsintl:fix/unify-date-anchor-patterns
Nov 7, 2026
Merged

okwasniewski merged 1 commit into
e2e-inc:mainfrom
Mohsintl:fix/unify-date-anchor-patterns

Conversation

@Mohsintl

@Mohsintl Mohsintl commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Follow-up to #1496 and #1498 addressing maintainer review feedback:

  • Extracted shared date and time regex patterns (ISO_DATE, CLOCK_TIME, MONTH_DAY_DATE, DAY_MONTH_DATE) into neutral src/internal/dates.ts, shared by both agent/derived.ts and cache/anchors.ts. Kept MONTH and DAY unexported to avoid unused exports.
  • Rebased on main (now containing fix(cache): read a date with an ordinal suffix as a date #1498) and dropped duplicated deltaMismatch tests.
  • Reverted unrelated import churn in anchors.ts and collapsed blank lines in derived.ts.
  • Eliminated false-positive volatile anchor matches on non-date terms (e.g. Marketing 12, Mayor 3, Augusta 3, 12 Marketing) which previously matched due to loose [a-z]* month prefixes.
  • Updated unit test in packages/e2e/tests/unit/trace-anchors.test.ts with inputs that main actually matched to prove the fix.
  • User-facing changeset in .changeset/unify-date-anchor-patterns.md.
  • Note on non-English months: Main's [a-z]* pattern previously matched some non-English month words by accident (e.g. 3 septembre, Octobre 3, Juni 3, Marzo 3). With this change they are no longer treated as volatile text anchors (leading safely to a cache handoff rather than a false pass).
  • Note on derived.ts spacing: The shared pattern uses \s+ instead of the previous single space between month, day, and year, so inputs with multiple spaces or whitespace tabs (e.g. Oct 26, Oct\t26, 26\nOct) now also count as dates in derivedReason.

Issue

Follow-up refactor to #1496 / #1498

Verified

Ran regression checks covering:

  • Dates with ordinal suffixes in both month-first and day-first formats.
  • False positive checks against Marketing 12, Mayor 3, Augusta 3, and 12 Marketing.
  • Unit tests in packages/e2e/tests/unit/trace-anchors.test.ts and agent/derived.ts integration.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package
  • Breaking change: not applicable
  • Docs updated in the same PR: not applicable
  • Contract change: not applicable
  • Engine contract change: not applicable

@github-actions github-actions Bot added the size:S Up to 29 changed lines, not counting tests, fixtures, translated docs, or the lockfile label Nov 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski 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.

Automated review (thermo-nuclear pass by an agent on behalf of the maintainers). A human will take the final look.

Thanks for picking up the MONTH/DAY reuse from #1498.

Verdict: changes needed. The regexes are correct. Behavior is identical to main for every English month form, ordinals match in both orders, and the [a-z]* false positives (Marketing 12, Mayor 3, Augusta 3, 12 Marketing) are gone. Reverting each regex line on its own fails a test. Unit tests pass (45/45 in trace-anchors + agent-derived).

Merge order: #1498 (the original fix for #1496, by @21prnv) is in the merge queue. The two deltaMismatch tests here are copied verbatim from it, so please rebase on main once it lands, drop the duplicated tests, and keep this PR as the follow-up refactor.

Must fix

  1. tests/unit/trace-anchors.test.ts:190-192: Marketing 1st / Decision 2nd / Octane 3rd gen already pass on main (main's \d{1,2}\b never matched an ordinal), so they don't prove the false-positive fix. Use inputs main actually matches: Marketing 12, Mayor 3, Augusta 3, 12 Marketing.
  2. .changeset/unify-date-anchor-patterns.md: names internals (MONTH, DAY, cache/anchors.ts). Write it for users, e.g. "A replay no longer skips text like Marketing 12 as a date when checking its end state."
  3. Ownership of the patterns: exporting regex source fragments from agent/derived.ts (model-derived value detection) makes that module the owner of date parsing for the cache. Move them to a small neutral module (e.g. src/internal/dates.ts) that both files import. Both files also duplicate the ISO date and clock-time regexes today, so those can move too.
  4. Silent regression: main's [a-z]* caught some non-English month names by accident (3 septembre, Octobre 3, Juni 3, Marzo 3). With this PR they are no longer volatile. That's the safe direction (a cache handoff, not a false pass), but call it out in the PR body.

Nits

  • anchors.ts: the RedactedNode import move is unrelated churn, please revert it.

@Mohsintl
Mohsintl force-pushed the fix/unify-date-anchor-patterns branch from 3430754 to addf08c Compare November 3, 2026 07:12
@Mohsintl Mohsintl changed the title fix(cache): reuse canonical month and day patterns in volatile text anchors fix(cache): extract shared date patterns to internal/dates and drop false positives Nov 3, 2026
@github-actions github-actions Bot added size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile and removed size:S Up to 29 changed lines, not counting tests, fixtures, translated docs, or the lockfile labels Nov 3, 2026
@Mohsintl

Mohsintl commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @okwasniewski!

All points addressed:

  1. Rebased on main following fix(cache): read a date with an ordinal suffix as a date #1498 merge, and dropped the duplicate tests.
  2. Moved MONTH, DAY, ISO_DATE, CLOCK_TIME, and date regexes to a shared neutral module: src/internal/dates.ts, imported by both agent/derived.ts and cache/anchors.ts.
  3. Updated false-positive tests in trace-anchors.test.ts with inputs main actually matched: Marketing 12, Mayor 3, Augusta 3, 12 Marketing.
  4. Rewrote .changeset/unify-date-anchor-patterns.md to be user-facing.
  5. Called out the non-English month behavior note in the PR description.
  6. Reverted the unrelated RedactedNode import churn in anchors.ts.

@okwasniewski okwasniewski 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.

Automated review (agent-run thermo-nuclear review, a human maintainer reviews before merge).

Thanks, all 5 asks are done: rebased with no duplicate tests, the new false-positive tests fail on main (4 vs 8) and pass here, the changeset is user-facing, patterns live in internal/dates.ts, and the non-English note is in the body. Compared old and new patterns on ~90 inputs: nothing new matches in anchors.ts, only the intended English false positives and non-English months drop out. Restoring the loose [a-z]* prefix fails both the anchors and derived tests.

One must-fix:

  • packages/e2e/src/internal/dates.ts:4,7: MONTH and DAY are exported but nothing imports them. fallow dead-code in spec exits 1 with "Unused exports (2)" (spec hasn't run yet, fork CI is waiting on approval). Drop export from both.

Worth knowing:

  • derived.ts changes slightly: the old patterns had a literal space between month, day and year, and the shared ones use \s+, so Oct 26, Oct\t26 and 26\nOct now count as dates in derivedReason, which tests the raw typed value. That's fine, but say so in the body since it reads as a no-op for derived.ts.

Nits:

  • derived.ts:115-117: three blank lines left where MONTH/DAY were. Collapse to one.
  • dates.ts:1: drop the consumer list from the header, "Date and clock-time patterns." is enough.

@Mohsintl
Mohsintl force-pushed the fix/unify-date-anchor-patterns branch from addf08c to cd88bda Compare November 3, 2026 10:52
@Mohsintl

Mohsintl commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @okwasniewski!

Updated:

  1. Dropped export from MONTH and DAY in dates.ts so fallow dead-code passes without unused exports.
  2. Collapsed the extra blank lines in derived.ts.
  3. Simplified the header in dates.ts to /** Date and clock-time patterns. */.
  4. Added the note to the PR body regarding derived.ts accepting \s+ whitespace (e.g. Oct 26, Oct\t26).

@okwasniewski

Copy link
Copy Markdown
Member

Automated review (Claude, on behalf of @okwasniewski).

Re-reviewed cd88bda. All asks done: MONTH/DAY module-private (fallow passes), \s+ widening and non-English month change called out, no duplicated #1498 tests, changeset user-facing. New false-positive tests (Marketing 12, Mayor 3, Augusta 3, 12 Marketing) fail on main and pass here. Lint, typecheck, unit (3249 pass), fallow dead-code pass locally. Merges clean with main.

Optional nits, not blocking:

  • packages/e2e/src/internal/dates.ts:6 JSDoc says DAY is "(1-31)" but \d{1,2} matches 0-99.
  • Day-first anchor pattern now accepts ,? before the year, so Due 3 Oct, 2026 masks to Due # (main: Due #, 2026). Harmless, matches month-first, but untested and not in the PR body.
  • \s+ widening is untested (mutating it to a single space survives). An Oct\t26 case in agent-derived would pin it.

Fork CI still needs maintainer approval to run. Labeling Ready for Human Review.

@okwasniewski
okwasniewski dismissed stale reviews from themself November 3, 2026 16:12

Addressed, see re-review comment.

@Mohsintl

Mohsintl commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Saw on #1460 that a cache rewrite is planned. Does this PR still make sense to land before it, or would you rather I close it in favour of the rewrite?

@okwasniewski

Copy link
Copy Markdown
Member

yeah, lets land it - we have cache rewrite planned but not yet started.

@okwasniewski
okwasniewski added this pull request to the merge queue Nov 7, 2026
Merged via the queue into e2e-inc:main with commit d784448 Nov 7, 2026
22 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 7, 2026
kblok added a commit to hardkoded/e2e-dotnet that referenced this pull request Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Human Review size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants