Accept bounded close-after-update skew in GitHub imports

Merged
UN
12h ago
+260-37

Problem

GitHub writes closed_at and updated_at independently, so a closed issue can report closed_at a few seconds after updated_at. validateImportLifetime refused any closed_at > updated_at, and the gated import stopped for the whole repository. Two real issues closed through the REST API on 2026-11-24 (pm-rl#140 and pm-memory#44, reported as #285 and #284) show exactly two seconds of skew and blocked the scheduled pm-rl sync until a workaround comment moved updated_at.

Design

  • validateImportLifetime now accepts a closure up to 5 seconds inclusive after the last update — the same forward-skew bound the closure-timeline matcher (latestClosure) already applies — comparing instants at millisecond precision and preserving both original timestamps.
  • Genuinely inconsistent data still refuses the whole batch before any write: timestamps before creation, invalid instants, and a closure beyond the bound. The refusal now names all three source timestamps (sanitized, no arbitrary provider text) and the retry remedy, instead of the bare "nothing may be imported".
  • Persisted gated plans validate through the same rule; an older plan's empty-string absent closure normalizes to absent, so replays of previously verified plans keep working.
  • README documents the bound and the per-issue retry workflow; the identity ownership inventory is regenerated (line-anchor shifts only).

Before/after

  • Before: GitHub issue #140 has an invalid source lifetime; nothing may be imported. — the two recorded pairs refused the whole batch.
  • After: both recorded pairs pass gated preview, apply and byte-identical repeat (REST and GraphQL), with exact source fidelity retained; only real inconsistencies refuse, with an actionable diagnostic.

Tests and revert proof

New coverage: inclusive bound across a minute and a UTC offset; the refusal corpus (invalid instants, pre-creation timestamps, malformed closure, arbitrary provider text sanitized); gated preview/apply/repeat with the recorded pairs; GraphQL refresh repeat without extra history; persisted-plan validation; packed npm and native Bun CLI consumers (JSON detail and TOON stderr). Behavioral revert of the changed validator at the base commit: 6 failures, 0 passes; removing the upper bound, the close-before-creation, update-before-creation and malformed-closure checks one at a time each fails with Missing expected exception. Revert proof recorded in the pm item.

Gates (local, exact head 5754cd4)

typecheck, lint, docstring, duplication, privacy and identity-inventory checks, changelog:check after npm run changelog:full, and pinned-host pm health --strict-exit --require-merge-drivers all pass. Tests: import-fidelity 57/57, refresh 48/48, import-projection 6/6 (npm and Bun consumers included), the 20 remaining suites that directly reference the shared validator 535/535, and the recorded focused command 5/5. Coverage and the full release gates are left to CI at unchanged thresholds.

Scope audit

The single shared validator covers every place in this component: REST import, GraphQL refresh, gated plans and replay, preview/apply parity, JSON and TOON diagnostics, and the packed npm and native Bun consumers. No other component (the SDK engine and the other fleet importers) enforces a closed ≤ updated ordering, so no follow-up issue is required.

Fixes #285
Fixes #284

pm items:


Summary by cubic

Fixes scheduled GitHub syncs failing when GitHub records closed_at a few seconds after updated_at, which the importer rejected as an invalid lifetime and then refused the whole batch. The lifetime validator now accepts a closure up to 5 seconds inclusive after the last update and refuses only genuinely inconsistent records.

Bug Fixes

  • validateImportLifetime reuses the 5-second bound already applied by the closure-timeline matcher, compares instants at millisecond precision, and preserves the original GitHub timestamps.
  • Refusals now name all three source timestamps and the retry remedy instead of "nothing may be imported".
  • Persisted gated plans validate through the same rule; older plans with an empty-string absent closure normalize to absent and still replay.
  • README documents the bound and the per-issue retry workflow.

Fixes #285
Fixes #284