Skip to content

pm-stack(aggregator): isSessionRecord accepts impossible and non-ISO lastSeenAt/startedAt — a non-ISO stamp wins merge recency forever, and impossible dates roll in registryActivityMs #5078

Closed

Description

@dezren39

pm-stack(aggregator): isSessionRecord accepts impossible and non-ISO lastSeenAt/startedAt — a non-ISO stamp wins merge recency forever, and impossible dates roll in registryActivityMs

Evidence

isSessionRecord (pm-stack/aggregator/src/registry.ts:166) gates the two
timestamps only on type: (r.lastSeenAt === undefined || typeof r.lastSeenAt === "string")
and the same for startedAt. That type check is the #2376 fix — it stops the
mergeRecords sort crash on non-string values — but it never checks that a
string timestamp is a real ISO calendar date. Every sibling store validator in
the aggregator gates timestamps with isIsoDate
(pm-stack/aggregator/src/validate.ts:116): snapshots (isSnapshotRecord),
quota rows (isSubscriptionRow, isChargeRow, isBurnSegment), saved views,
events, saas overlays. The registry record is the one boundary left on
string-only.

Verified on the laptop at origin/main 6a69ab52d (bun probe importing the
real modules):

  • isSessionRecord returns true for lastSeenAt/startedAt of
    2026-02-30T10:00:00Z, 2026-04-31T10:00:00Z, March 2, 2026, and
    not-a-date.
  • registryActivityMs (pm-stack/aggregator/src/registry-view.ts:62,
    Date.parse) then reports the impossible stamps as different instants than
    the strings claim: 2026-02-30 → 2026-03-02, 2026-04-31 → 2026-05-01,
    March 2, 2026 → 2026-03-02T06:00:00Z.
  • mergeRecords (pm-stack/aggregator/src/registry.ts:136, lastSeenAt pick
    at :158) compares the stamps as strings. Probe: merging a record stamped
    2026-06-01T00:00:00Z with one stamped March 2, 2026 keeps
    March 2, 2026 as lastSeenAt in both merge orders — lexicographic
    M > 2, so a non-ISO stamp permanently wins recency and no later ISO
    record can ever displace it. The merged record is also what the final sort
    ((b.lastSeenAt ?? "").localeCompare(...)) orders by, so the poisoned
    stamp pins the session to the top of the registry ordering.

Consumers reached through the two load paths that filter on this validator
(sources/live.ts:795 registry store load, :1380 feed registry merge):
the sessions registry, registryActivityMs-based recency windows, and every
render that shows lastSeenAt/startedAt verbatim.

Control: 2026-03-02T10:00:00Z validates and parses to itself.

Why it matters

The registry is the fleet's session record of truth for the dashboard. One
malformed writer (or one hand-edited/corrupted store row) with a non-ISO
lastSeenAt becomes permanently "most recent" — it survives every later
merge, distorts recency windows and ordering, and displays a stamp that does
not mean what it says. Impossible dates silently shift a session's activity
by days. The fix is the house pattern already applied at every sibling
boundary.

Acceptance criteria

  • isSessionRecord refuses a record whose lastSeenAt or startedAt is
    present and not a real ISO calendar date (isIsoDate), e.g. 2026-02-30,
    2026-04-31, March 2, 2026, not-a-date; absent timestamps stay allowed.
  • Valid ISO timestamps (incl. offsets/fractional seconds) still validate.
  • Tests cover the refused and control cases for both fields; bun test in
    pm-stack/aggregator passes.
  • Out of scope: changing mergeRecords' comparison or the SessionRecord shape
    (both are correct once inputs are real ISO).

Filed by new-issue-creator-code-a (lane A). Dedup: searches for
isSessionRecord, registry lastSeenAt (2026-11-03) — #3414/#2376 cover
non-string types only, #3525 covers status/agentLabel/tokensTotal, #4890
covers taskRefs; none covers timestamp validity.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    app/pm-stackpm-stack (Pad/Grist) in developing-today/code
    on Nov 3, 2026
  2. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: filed
    Found via: filed this run (new-issue-creator-code-a, lane A) — verified by laptop bun probes at origin/main 6a69ab52d importing the real registry.ts/registry-view.ts modules: isSessionRecord accepts 2026-02-30, 2026-04-31, 'March 2, 2026' and 'not-a-date' as lastSeenAt/startedAt; registryActivityMs rolls Feb-30 to Mar 2 and Apr-31 to May 1; mergeRecords keeps 'March 2, 2026' over a June ISO stamp in both merge orders. Fix packet enqueued to repo-health-code-pilot (small_fix).

  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 3, 2026
  4. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  5. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 3, 2026
  6. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  7. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 3, 2026
  8. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  9. added a commit that references this issue on Nov 3, 2026
  10. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/pm-stackpm-stack (Pad/Grist) in developing-today/codekind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions