From cdcfad1edffb4722825b93d124a36224752163fc Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:04:59 -0600 Subject: [PATCH 1/3] wip: preserve task 8947 activity changes --- pm-stack/aggregator/src/events.ts | 106 +++++++++++++++++-- pm-stack/aggregator/src/render.ts | 23 +++- pm-stack/aggregator/src/server.ts | 134 +++++++++++++++++++----- pm-stack/aggregator/test/events.test.ts | 37 +++++++ pm-stack/aggregator/test/render.test.ts | 41 ++++++++ 5 files changed, 300 insertions(+), 41 deletions(-) diff --git a/pm-stack/aggregator/src/events.ts b/pm-stack/aggregator/src/events.ts index b4278ff3d9..757f978da7 100644 --- a/pm-stack/aggregator/src/events.ts +++ b/pm-stack/aggregator/src/events.ts @@ -326,29 +326,113 @@ export function pruneEvents(events: readonly T[], now = n export interface EventFilter { kind?: string; ref?: string; + refs?: readonly string[]; actor?: string; + project?: string; + epic?: string; + search?: string; + /** Metadata resolved from the live project pool; event records stay source-native. */ + itemContext?: ReadonlyMap; } -/** The read surface: newest first, exact-match filters on - * kind / ref / actor (case-insensitive, like the views matcher). */ +/** The read surface: newest first, with stable ids breaking equal-time ties. */ export function filterEvents(events: readonly T[], filter: EventFilter = {}): T[] { const eq = (a: string, b: string) => a.toLowerCase() === b.toLowerCase(); - // Newest first by PARSED time (#4489 Codex re-review): accepted - // timestamps may carry offsets or omit fractional seconds, where a - // string comparison misorders them; equal instants keep the later - // arrival first, matching append order. + const normalizeRef = (ref: string) => ref.replace(/^gh:/i, "").toLowerCase(); + const refs = [filter.ref, ...(filter.refs ?? [])].filter((ref): ref is string => Boolean(ref)); + const search = filter.search?.trim().toLowerCase(); + // Newest first by parsed time. Audit ids break equal-time ties so a + // cursor remains stable when later records are appended; legacy + // StreamEvent callers without ids retain append-order tie handling. return [...events] .map((event, index) => ({ event, index })) - .sort((a, b) => Date.parse(b.event.at) - Date.parse(a.event.at) || b.index - a.index) + .sort((a, b) => { + const time = Date.parse(b.event.at) - Date.parse(a.event.at); + if (time) return time; + const aId = "id" in a.event && typeof a.event.id === "string" ? a.event.id : null; + const bId = "id" in b.event && typeof b.event.id === "string" ? b.event.id : null; + return aId !== null && bId !== null ? bId.localeCompare(aId) : b.index - a.index; + }) .map(({ event }) => event) .filter( - (e) => - (!filter.kind || eq(e.kind, filter.kind)) && - (!filter.ref || eq(e.ref, filter.ref)) && - (!filter.actor || eq(e.actor, filter.actor)), + (e) => { + const context = filter.itemContext?.get(normalizeRef(e.ref)); + return ( + (!filter.kind || eq(e.kind, filter.kind)) && + (!refs.length || refs.some((ref) => normalizeRef(e.ref) === normalizeRef(ref))) && + (!filter.actor || eq(e.actor, filter.actor)) && + (!filter.project || Boolean(context?.project && eq(context.project, filter.project))) && + (!filter.epic || Boolean(context?.epic && eq(context.epic, filter.epic))) && + (!search || `${e.actor} ${e.kind} ${e.ref} ${e.summary}`.toLowerCase().includes(search)) + ); + }, ); } +export interface EventPageCursor { + at: string; + id: string; + snapshotAt: string; +} + +export interface EventPage { + events: AuditEvent[]; + nextCursor: string | null; + snapshotAt: string; +} + +function compareEventOrder(a: Pick, b: Pick): number { + return Date.parse(b.at) - Date.parse(a.at) || b.id.localeCompare(a.id); +} + +export function encodeEventCursor(cursor: EventPageCursor): string { + return Buffer.from(JSON.stringify(cursor), "utf8").toString("base64url"); +} + +export function decodeEventCursor(value: string | null | undefined): EventPageCursor | null { + if (!value) return null; + try { + const parsed: unknown = JSON.parse(Buffer.from(value, "base64url").toString("utf8")); + if ( + typeof parsed === "object" && parsed !== null && + typeof (parsed as EventPageCursor).at === "string" && + Number.isFinite(Date.parse((parsed as EventPageCursor).at)) && + typeof (parsed as EventPageCursor).id === "string" && + typeof (parsed as EventPageCursor).snapshotAt === "string" && + Number.isFinite(Date.parse((parsed as EventPageCursor).snapshotAt)) + ) return parsed as EventPageCursor; + } catch { + // An invalid cursor starts a new first page; it never becomes a filter. + } + return null; +} + +/** Stable descending keyset pagination over a fixed ingestion snapshot. */ +export function pageEvents( + events: readonly AuditEvent[], + options: { cursor?: string | null; limit?: number } = {}, +): EventPage { + const limit = Math.max(1, Math.min(100, Math.floor(options.limit ?? 50) || 50)); + const cursor = decodeEventCursor(options.cursor); + const snapshotAt = cursor?.snapshotAt ?? events.reduce( + (latest, event) => event.ingestedAt > latest ? event.ingestedAt : latest, + "1970-01-01T00:00:00.000Z", + ); + const visible = events.filter((event) => + event.ingestedAt <= snapshotAt && (!cursor || compareEventOrder(event, cursor) > 0), + ); + const page = visible.slice(0, limit); + const last = page.at(-1); + return { + events: page, + snapshotAt, + nextCursor: + visible.length > limit && last + ? encodeEventCursor({ at: last.at, id: last.id, snapshotAt }) + : null, + }; +} + /** * The fire-and-forget writer every emission point uses (#1739 * acceptance: writing an event never blocks the underlying action). diff --git a/pm-stack/aggregator/src/render.ts b/pm-stack/aggregator/src/render.ts index a8ef1393a0..5d2654906c 100644 --- a/pm-stack/aggregator/src/render.ts +++ b/pm-stack/aggregator/src/render.ts @@ -38,6 +38,8 @@ import { } from "./tier-items.ts"; import { commentKindCounts, githubCommentUrl, queuedComments, type CommentKindCounts } from "./comments.ts"; import { serviceHomeLinks, type ItemServiceLink } from "./service-links.ts"; +import { activityCoverageHtml, gapsHtml, type ActivityCoverage, type GapRecord } from "./activity.ts"; +import type { AuditEvent } from "./events.ts"; import { aaCaiPoints, aaPoints, summarizeAa } from "./aa.ts"; import { applyInequalityFilters, @@ -2092,6 +2094,8 @@ export interface ItemExtras { epicRollup?: EpicRollup; /** Project-pool briefs for linked refs (#1279). */ briefs?: Map; + /** The shared audit stream, scoped to the item's canonical refs. */ + activity?: { events: AuditEvent[]; globalHref: string; gaps: GapRecord[]; coverage?: readonly ActivityCoverage[] }; } function roadmapAnnotationFormHtml(objectRef: string, identities: AuthorIdentity[]): string { @@ -2113,6 +2117,18 @@ function epicRollupHtml(rollup: EpicRollup): string { return `

Epic rollup — ${children} · Status mix: ${statusMix} · Blocked: ${rollup.blocked}

`; } +export function eventTableHtml(events: readonly AuditEvent[]): string { + const rows = events.map((event) => { + const source = event.source.link + ? `${esc(event.source.identity)}` + : esc(event.source.identity); + const delay = Date.parse(event.ingestedAt) - Date.parse(event.at); + const ingested = Number.isFinite(delay) && delay > 0 ? `(+${Math.round(delay / 1000)}s ingest)` : ""; + return `${esc(event.at)} ${ingested}${esc(event.actor)} (${esc(event.attribution.confidence)})${esc(event.kind)}${esc(event.ref)}${esc(event.summary)}${source}`; + }).join("\n"); + return `
${rows || ''}
Shared activity events
WhenActorKindRefSummarySource
No matching events; this does not establish complete coverage.
`; +} + export function renderItem( title: string, subject: string, @@ -2160,6 +2176,9 @@ export function renderItem( ? `

Live services: ${extras.serviceLinks.map((s) => `${esc(s.label)} ↗`).join(" · ")}

` : ""; const epicRollup = extras?.epicRollup ? epicRollupHtml(extras.epicRollup) : ""; + const activitySection = extras?.activity + ? `

Activity stream

View these events in the global river

Freshness: unknown. The ingestion checkpoint records deliveries, not successful source polls. Known gaps and documented source coverage are shown below.

${eventTableHtml(extras.activity.events)}

Known activity gaps

Gap records are source-scoped and do not currently identify affected item refs, so this is the global known-gap list.

${gapsHtml(extras.activity.gaps)}

Activity source coverage

${activityCoverageHtml(extras.activity.coverage)}` + : ""; return layout( title, `

${esc(title)}

subject: ${esc(subject)}

${epicRollup}${svcLinks}${stripHtml(items, links)} @@ -2172,8 +2191,8 @@ ${ : "" }

Linked issues / PRs

${refRows || ''}
Linked issues and pull requests
RefTitleLabelsUpdated
none resolved
-

Activity stream

${commentRows || ''}
Activity stream
WhenKindAuthorBody
no comments
-${sessionSection}${statusSection}${roadmapAnnotationSection}${dashSection}`, +

Comments

${commentRows || ''}
Comments
WhenKindAuthorBody
no comments
+ ${activitySection}${sessionSection}${statusSection}${roadmapAnnotationSection}${dashSection}`, provenance, "/board", extras diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index f00a427a06..00181bccaf 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -20,7 +20,7 @@ import { import { commentKindCounts, CommentsStore, queuedComments, validateNewComment } from "./comments.ts"; import type { SavedView, ViewFilters, ViewItemLike } from "./views.ts"; import { ViewsStore, filtersFromQuery, itemMatchesView, ownerKey } from "./views.ts"; -import { EventsStore, emitEvent } from "./events.ts"; +import { EventsStore, emitEvent, pageEvents } from "./events.ts"; import { IngestionStore, WatchdogEpisodeStabilizer, @@ -107,6 +107,7 @@ import { renderTodayBody, renderTodayShell, type CommentFormOpts, + eventTableHtml, } from "./render.ts"; import { buildBriefs } from "./brief.ts"; import { timingSafeEqual } from "node:crypto"; @@ -762,6 +763,30 @@ function poolItemLike(item: ProjectPoolItem): ViewItemLike { }; } +function eventContextByRef(pool: readonly ProjectPoolItem[]): Map { + const context = new Map(); + for (const item of pool) { + const ref = item.ref.replace(/^gh:/i, "").toLowerCase(); + context.set(ref, { + project: item.projectUrl, + epic: item.epicRef ?? (item.kind?.toLowerCase() === "epic" ? item.ref : null), + }); + } + return context; +} + +function eventFilterFromUrl(url: URL, itemContext: ReadonlyMap) { + return { + kind: url.searchParams.get("kind") ?? undefined, + refs: url.searchParams.getAll("ref"), + actor: url.searchParams.get("actor") ?? undefined, + project: url.searchParams.get("project") ?? undefined, + epic: url.searchParams.get("epic") ?? undefined, + search: url.searchParams.get("q") ?? undefined, + itemContext, + }; +} + /** A board card / roadmap row matches when its own fields match, or * when any canonical item it links to matches. */ function linkedLike( @@ -1104,40 +1129,80 @@ async function handler(req: Request): Promise { } } if (path === "/api/events.json") { - // #1739: the cross-stack event stream, newest first, with - // kind/ref/actor filters — the machine twin of /events below. - const events = await eventsStore.list({ - kind: url.searchParams.get("kind") ?? undefined, - ref: url.searchParams.get("ref") ?? undefined, - actor: url.searchParams.get("actor") ?? undefined, + // #1739/#3323: the same source-native stream and filters as /events. + const pool = await source.projects().catch(() => [] as ProjectPoolItem[]); + const filtered = await eventsStore.list(eventFilterFromUrl(url, eventContextByRef(pool))); + const page = pageEvents(filtered, { + cursor: url.searchParams.get("cursor"), + limit: Number(url.searchParams.get("limit") ?? 50), }); // #3322 slice A: the audit health surface rides along — pending // retry-outbox count + hash-chain integrity verdict. - const health = await eventsStore.health(); - return json({ events, health }); + const [health, checkpoints, gaps] = await Promise.all([ + eventsStore.health(), + activityStore.checkpoints(), + activityStore.gaps(), + ]); + return json({ + events: page.events, + health, + pagination: { total: filtered.length, snapshotAt: page.snapshotAt, nextCursor: page.nextCursor }, + activity: { + checkpoints, + gaps, + coverage: ACTIVITY_SOURCE_COVERAGE, + freshness: { status: "unknown", reason: "ingestion checkpoints record deliveries, not successful source polls" }, + }, + }); } if (path === "/events") { - // #1739: the human page over the same stream /api/events.json - // serves — same records, same filters (?kind=&ref=&actor=). - const filter = { - kind: url.searchParams.get("kind") ?? undefined, - ref: url.searchParams.get("ref") ?? undefined, - actor: url.searchParams.get("actor") ?? undefined, - }; - const events = await eventsStore.list(filter); - const rows = events - .map( - (e) => - `${esc(e.at)}${esc(e.actor)}${esc(e.kind)}` + - `${esc(e.ref)}${esc(e.summary)}`, - ) - .join("\n"); + // Machine and human surfaces share filters, ordering, and a stable + // ingestion snapshot for cursor pagination. + const pool = await source.projects().catch(() => [] as ProjectPoolItem[]); + const filtered = await eventsStore.list(eventFilterFromUrl(url, eventContextByRef(pool))); + const page = pageEvents(filtered, { + cursor: url.searchParams.get("cursor"), + limit: Number(url.searchParams.get("limit") ?? 50), + }); + const projects = [...new Set(pool.map((item) => item.projectUrl))].sort(); + const epics = new Map(); + for (const item of pool) { + if (item.kind?.toLowerCase() === "epic") epics.set(item.ref, item.title); + if (item.epicRef) epics.set(item.epicRef, pool.find((candidate) => candidate.ref === item.epicRef)?.title ?? item.epicRef); + } + const refs = url.searchParams.getAll("ref"); + const option = (value: string, label: string, selected: string) => + ``; + const projectOptions = [...new Set([url.searchParams.get("project") ?? "", ...projects].filter(Boolean))] + .map((value) => option(value, value, url.searchParams.get("project") ?? "")) + .join(""); + const selectedEpic = url.searchParams.get("epic") ?? ""; + if (selectedEpic && !epics.has(selectedEpic)) epics.set(selectedEpic, selectedEpic); + const epicOptions = [...epics.entries()] + .map(([value, label]) => option(value, label, url.searchParams.get("epic") ?? "")) + .join(""); + const preservedRefs = refs.slice(1).map((ref) => ``).join(""); + const nextUrl = page.nextCursor ? new URL(url) : null; + if (nextUrl && page.nextCursor) nextUrl.searchParams.set("cursor", page.nextCursor); + const apiUrl = new URL(url); + apiUrl.pathname = "/api/events.json"; + apiUrl.hash = ""; return html( `Events — pm-stack` + - `

Events

${events.length} event(s), newest first. ` + - `Machine twin: /api/events.json (filters: kind, ref, actor).

` + - `` + - `${rows}
atactorkindrefsummary
` + + `

Events

Showing ${page.events.length} of ${filtered.length} matching events from a fixed snapshot, newest first. ` + + `Machine twin: /api/events.json.

` + + `

Freshness: unknown. Ingestion checkpoints record deliveries, not successful source polls.

` + + `
` + + `` + + `` + + `` + + `` + + `${preservedRefs}` + + `` + + `` + + `
` + + eventTableHtml(page.events) + + (nextUrl ? `

` : "") + `

Activity gaps

` + gapsHtml(await activityStore.gaps()) + `

Activity source coverage

` + @@ -1951,6 +2016,13 @@ async function handler(req: Request): Promise { const title = subject.title; const links = subject.links; const refs = allRefs([subject]); + const activityRefs = [...new Set([id, ...refs].map((ref) => ref.replace(/^gh:/i, "")))]; + const activityQuery = new URLSearchParams(); + for (const ref of activityRefs) activityQuery.append("ref", ref); + const [itemEvents, itemGaps] = await Promise.all([ + eventsStore.list({ refs: activityRefs }), + activityStore.gaps(), + ]); const [items, comments, allComments, records, pool, orchestration, allActions, roadmapAnnotations] = await Promise.all([ source.items(refs).catch(() => new Map()), @@ -1997,6 +2069,12 @@ async function handler(req: Request): Promise { : {}), ...(epicRollup ? { epicRollup } : {}), briefs, + activity: { + events: itemEvents, + globalHref: `/events?${activityQuery.toString()}`, + gaps: itemGaps, + coverage: ACTIVITY_SOURCE_COVERAGE, + }, }; return html(renderItem(title, id, links, items, comments, prov(), extras)); } diff --git a/pm-stack/aggregator/test/events.test.ts b/pm-stack/aggregator/test/events.test.ts index 98efae9bbd..2019ac0795 100644 --- a/pm-stack/aggregator/test/events.test.ts +++ b/pm-stack/aggregator/test/events.test.ts @@ -13,6 +13,7 @@ import { EventsStore, emitEvent, filterEvents, + pageEvents, pruneEvents, validateStreamEvent, type StreamEvent, @@ -174,6 +175,42 @@ describe("events store (#1739)", () => { expect(filterEvents(events).map((e) => e.summary)).toEqual(["later instant", "earlier instant"]); }); + test("project, epic, ref and summary search filters share one matcher", () => { + const events: StreamEvent[] = [ + { ...base, at: "2026-11-01T10:00:00Z", ref: "gh:developing-today/code#7", summary: "Moved to review" }, + { ...base, at: "2026-11-01T09:00:00Z", ref: "developing-today/code#8", summary: "Closed" }, + ]; + const itemContext = new Map([ + ["developing-today/code#7", { project: "https://github.com/orgs/developing-today/projects/1", epic: "developing-today/code#1" }], + ["developing-today/code#8", { project: "https://github.com/orgs/developing-today/projects/2", epic: null }], + ]); + expect(filterEvents(events, { + refs: ["developing-today/code#7"], + project: "https://github.com/orgs/developing-today/projects/1", + epic: "developing-today/code#1", + search: "REVIEW", + itemContext, + }).map((event) => event.ref)).toEqual(["gh:developing-today/code#7"]); + }); + + test("cursor pages use stable id ordering and exclude events ingested after the snapshot", async () => { + const { store } = tmpStore(); + const now = Date.now(); + await store.record({ ...base, id: "event-c", at: new Date(now - 3 * 60_000).toISOString(), summary: "oldest" }); + await store.record({ ...base, id: "event-b", at: new Date(now - 2 * 60_000).toISOString(), summary: "middle" }); + await store.record({ ...base, id: "event-a", at: new Date(now - 1 * 60_000).toISOString(), summary: "newest" }); + const first = pageEvents(await store.list(), { limit: 2 }); + expect(first.events.map((event) => event.id)).toEqual(["event-a", "event-b"]); + expect(first.nextCursor).not.toBeNull(); + + // A late-arriving old event sorts behind the cursor by event time, + // but its ingestion time is beyond the first page's fixed snapshot. + await store.record({ ...base, id: "late-event", at: new Date(now - 5 * 60_000).toISOString(), summary: "arrived late" }); + const second = pageEvents(await store.list(), { limit: 2, cursor: first.nextCursor }); + expect(second.events.map((event) => event.id)).toEqual(["event-c"]); + expect(second.events.map((event) => event.id)).not.toContain("late-event"); + }); + test("identities the action-result contract accepts are valid events", async () => { // byRun may carry punctuation (stored as appliedByRun); objectRef // may run to 300 chars (isObjectRef). Neither may be lost here. diff --git a/pm-stack/aggregator/test/render.test.ts b/pm-stack/aggregator/test/render.test.ts index 3e656c6ece..ec28b57892 100644 --- a/pm-stack/aggregator/test/render.test.ts +++ b/pm-stack/aggregator/test/render.test.ts @@ -29,6 +29,7 @@ import { type SessionFeedEntry, } from "../src/model.ts"; import type { HealthView } from "../src/health.ts"; +import type { AuditEvent } from "../src/events.ts"; import { FIXTURE_ATTENTION, FIXTURE_BOARD, @@ -292,6 +293,46 @@ describe("render smoke (fixtures)", () => { expect(html).not.toContain("Planning notes"); expect(html).not.toContain("PM-stack design & phase plan"); }); + test("item activity reuses shared events and discloses unknown freshness and partial coverage", async () => { + const src = fixtureSource(); + const item = FIXTURE_BOARD.find((b) => b.id.includes("aggregator")) as BoardItem; + const event: AuditEvent = { + version: 2, + id: "event-1", + at: "2026-11-03T10:00:00.000Z", + ingestedAt: "2026-11-03T10:00:01.000Z", + actor: "watchdog", + kind: "watchdog-event", + ref: "developing-today/openchamber#210", + summary: "source stale", + attribution: { confidence: "unknown", asserted: false }, + source: { identity: "watchdog" }, + prevHash: "0".repeat(64), + hash: "f".repeat(64), + }; + const refs = allRefs([item]); + const html = renderItem( + item.title, + item.id, + item.links, + await src.items(refs), + await src.comments(refs), + src.provenance(), + { + dashComments: [], + formRef: item.id, + formOpts: { identities: [] }, + sessions: [], + activity: { events: [event], globalHref: "/events?ref=developing-today%2Fopenchamber%23210", gaps: [], coverage: [] }, + }, + ); + expect(html).toContain("watchdog-event"); + expect(html).toContain("View these events in the global river"); + expect(html).toContain("Freshness: unknown"); + expect(html).toContain("not establish complete coverage"); + expect(html).toContain("No known activity gaps"); + expect(html).toContain('class="tblwrap"'); + }); test("quota view renders pools and model-choice guidance", async () => { const src = fixtureSource(); const html = renderQuota(await src.quota(), src.provenance()); From 276e9fcef83264c4387f716c2c769c78a15921f6 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 21:15:06 -0600 Subject: [PATCH 2/3] feat(aggregator): add item activity and river filters --- pm-stack/aggregator/src/render.ts | 4 +-- pm-stack/aggregator/src/server.ts | 8 ++++-- pm-stack/aggregator/test/boot.test.ts | 40 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/pm-stack/aggregator/src/render.ts b/pm-stack/aggregator/src/render.ts index 5d2654906c..b2f85b264c 100644 --- a/pm-stack/aggregator/src/render.ts +++ b/pm-stack/aggregator/src/render.ts @@ -2177,7 +2177,7 @@ export function renderItem( : ""; const epicRollup = extras?.epicRollup ? epicRollupHtml(extras.epicRollup) : ""; const activitySection = extras?.activity - ? `

Activity stream

View these events in the global river

Freshness: unknown. The ingestion checkpoint records deliveries, not successful source polls. Known gaps and documented source coverage are shown below.

${eventTableHtml(extras.activity.events)}

Known activity gaps

Gap records are source-scoped and do not currently identify affected item refs, so this is the global known-gap list.

${gapsHtml(extras.activity.gaps)}

Activity source coverage

${activityCoverageHtml(extras.activity.coverage)}` + ? `

Activity stream

View these events in the global river

Freshness: unknown. The ingestion checkpoint records deliveries, not successful source polls. An empty event list does not establish complete coverage. Known gaps and documented source coverage are shown below.

${eventTableHtml(extras.activity.events)}

Known activity gaps

Gap records are source-scoped and do not currently identify affected item refs, so this is the global known-gap list.

${gapsHtml(extras.activity.gaps)}

Activity source coverage

${activityCoverageHtml(extras.activity.coverage)}
` : ""; return layout( title, @@ -2191,7 +2191,7 @@ ${ : "" }

Linked issues / PRs

${refRows || ''}
Linked issues and pull requests
RefTitleLabelsUpdated
none resolved
-

Comments

${commentRows || ''}
Comments
WhenKindAuthorBody
no comments
+

Activity stream comments

${commentRows || ''}
Comments
WhenKindAuthorBody
no comments
${activitySection}${sessionSection}${statusSection}${roadmapAnnotationSection}${dashSection}`, provenance, "/board", diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index 00181bccaf..476ecb3ee2 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -1188,7 +1188,8 @@ async function handler(req: Request): Promise { apiUrl.pathname = "/api/events.json"; apiUrl.hash = ""; return html( - `Events — pm-stack` + + `Events — pm-stack` + + `` + `

Events

Showing ${page.events.length} of ${filtered.length} matching events from a fixed snapshot, newest first. ` + `Machine twin: /api/events.json.

` + `

Freshness: unknown. Ingestion checkpoints record deliveries, not successful source polls.

` + @@ -1203,10 +1204,11 @@ async function handler(req: Request): Promise { `` + eventTableHtml(page.events) + (nextUrl ? `

` : "") + - `

Activity gaps

` + + `

Activity gaps

` + gapsHtml(await activityStore.gaps()) + - `

Activity source coverage

` + + `

Activity source coverage

` + activityCoverageHtml() + + `
` + ``, ); } diff --git a/pm-stack/aggregator/test/boot.test.ts b/pm-stack/aggregator/test/boot.test.ts index 343248c79f..311d0eef29 100644 --- a/pm-stack/aggregator/test/boot.test.ts +++ b/pm-stack/aggregator/test/boot.test.ts @@ -210,6 +210,46 @@ describe("server boots from fixtures", () => { expect(res.status).toBe(200); const html = await res.text(); expect(html).toContain("Linked issues / PRs"); + expect(html).toContain("Activity stream"); + expect(html).toContain("View these events in the global river"); + expect(html).toContain("Freshness: unknown"); + expect(html).toContain("Known activity gaps"); + expect(html).toContain("Activity source coverage"); expect(html).not.toContain("Planning notes"); }); + + test("events filters persist in page and machine-twin URLs", async () => { + const filters = { + project: "project-a", + epic: "developing-today/code#3323", + kind: "issue-comment", + actor: "drew", + ref: "developing-today/code#3323", + q: "coverage gaps", + limit: "25", + }; + const query = new URLSearchParams(filters); + const page = await fetch(`http://127.0.0.1:${port}/events?${query}`); + expect(page.status).toBe(200); + const html = await page.text(); + expect(html).toContain('name="project"'); + expect(html).toContain("overflow-x:auto"); + expect(html).toContain("flex-wrap:wrap"); + expect(html).toContain('value="project-a" selected'); + expect(html).toContain('value="developing-today/code#3323" selected'); + expect(html).toContain('name="q" value="coverage gaps"'); + expect(html).toContain('name="actor" value="drew"'); + + const apiHref = html.match(/href="([^"]+)">\/api\/events\.json/)?.[1]; + expect(apiHref).toBeDefined(); + const apiUrl = new URL(apiHref!.replaceAll("&", "&"), `http://127.0.0.1:${port}`); + for (const [key, value] of Object.entries(filters)) expect(apiUrl.searchParams.get(key)).toBe(value); + const api = (await (await fetch(apiUrl)).json()) as { + pagination: { snapshotAt: string }; + activity: { freshness: { status: string }; coverage: unknown[] }; + }; + expect(api.pagination.snapshotAt).toBeTruthy(); + expect(api.activity.freshness.status).toBe("unknown"); + expect(Array.isArray(api.activity.coverage)).toBe(true); + }); }); From 9728b716f4bdec2b091ee9e0406b3c0544b28cc4 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 23:00:01 -0600 Subject: [PATCH 3/3] =?UTF-8?q?fix(aggregator):=20disposition=20Codex=20P2?= =?UTF-8?q?s=20on=20PR=20#5266=20=E2=80=94=20instant=20ingestion-timestamp?= =?UTF-8?q?=20comparison=20in=20pageEvents;=20all=20ref=20filters=20editab?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pm-stack/aggregator/src/events.ts | 9 +++++++-- pm-stack/aggregator/src/server.ts | 11 +++++++++-- pm-stack/aggregator/test/boot.test.ts | 15 +++++++++++++++ pm-stack/aggregator/test/events.test.ts | 24 ++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/pm-stack/aggregator/src/events.ts b/pm-stack/aggregator/src/events.ts index 757f978da7..10fd02078a 100644 --- a/pm-stack/aggregator/src/events.ts +++ b/pm-stack/aggregator/src/events.ts @@ -414,12 +414,17 @@ export function pageEvents( ): EventPage { const limit = Math.max(1, Math.min(100, Math.floor(options.limit ?? 50) || 50)); const cursor = decodeEventCursor(options.cursor); + // Compare ingestion timestamps as instants, never lexicographically: + // migrated v1 rows keep their original timestamp as `ingestedAt`, + // including UTC offsets and missing fractional seconds, and string + // order disagrees with instant order for those (Codex P2, PR #5266). const snapshotAt = cursor?.snapshotAt ?? events.reduce( - (latest, event) => event.ingestedAt > latest ? event.ingestedAt : latest, + (latest, event) => Date.parse(event.ingestedAt) > Date.parse(latest) ? event.ingestedAt : latest, "1970-01-01T00:00:00.000Z", ); + const snapshotMs = Date.parse(snapshotAt); const visible = events.filter((event) => - event.ingestedAt <= snapshotAt && (!cursor || compareEventOrder(event, cursor) > 0), + Date.parse(event.ingestedAt) <= snapshotMs && (!cursor || compareEventOrder(event, cursor) > 0), ); const page = visible.slice(0, limit); const last = page.at(-1); diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index 476ecb3ee2..9f4bb7e74a 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -1181,7 +1181,14 @@ async function handler(req: Request): Promise { const epicOptions = [...epics.entries()] .map(([value, label]) => option(value, label, url.searchParams.get("epic") ?? "")) .join(""); - const preservedRefs = refs.slice(1).map((ref) => ``).join(""); + // Every ref filter is a visible, editable input: hidden preserved + // refs could not be removed, so clearing the visible Ref field + // still restricted results to the item's linked refs (Codex P2, + // PR #5266). A cleared input submits ref="", which filterEvents + // ignores, so clearing an input is removing that ref. + const refInputs = (refs.length ? refs : [""]) + .map((ref, index) => ``) + .join(""); const nextUrl = page.nextCursor ? new URL(url) : null; if (nextUrl && page.nextCursor) nextUrl.searchParams.set("cursor", page.nextCursor); const apiUrl = new URL(url); @@ -1198,7 +1205,7 @@ async function handler(req: Request): Promise { `` + `` + `` + - `${preservedRefs}` + + refInputs + `` + `` + `` + diff --git a/pm-stack/aggregator/test/boot.test.ts b/pm-stack/aggregator/test/boot.test.ts index 311d0eef29..e2ccf24fe5 100644 --- a/pm-stack/aggregator/test/boot.test.ts +++ b/pm-stack/aggregator/test/boot.test.ts @@ -252,4 +252,19 @@ describe("server boots from fixtures", () => { expect(api.activity.freshness.status).toBe("unknown"); expect(Array.isArray(api.activity.coverage)).toBe(true); }); + + test("events page renders every ref filter as a visible editable input", async () => { + // Codex P2 on PR #5266: refs beyond the first used to ride along as + // hidden inputs, so they could not be edited or removed and + // clearing the visible Ref field still restricted the river. + const query = new URLSearchParams(); + query.append("ref", "developing-today/code#3323"); + query.append("ref", "developing-today/code#3321"); + const page = await fetch(`http://127.0.0.1:${port}/events?${query}`); + expect(page.status).toBe(200); + const html = await page.text(); + expect(html).not.toContain('type="hidden" name="ref"'); + expect(html).toContain('name="ref" value="developing-today/code#3323"'); + expect(html).toContain('name="ref" value="developing-today/code#3321"'); + }); }); diff --git a/pm-stack/aggregator/test/events.test.ts b/pm-stack/aggregator/test/events.test.ts index 2019ac0795..1d92b6136b 100644 --- a/pm-stack/aggregator/test/events.test.ts +++ b/pm-stack/aggregator/test/events.test.ts @@ -211,6 +211,30 @@ describe("events store (#1739)", () => { expect(second.events.map((event) => event.id)).not.toContain("late-event"); }); + test("pageEvents compares ingestion timestamps as instants, not strings", () => { + // Migrated v1 rows keep offset timestamps as ingestedAt: the first + // row below is 07:00Z even though its string sorts after the native + // 08:00Z row. Lexicographic comparison would pick the wrong + // snapshot and wrongly exclude the migrated row from later pages. + const mk = (id: string, at: string, ingestedAt: string) => ({ + ...base, + version: 2 as const, + id, + at, + ingestedAt, + attribution: { confidence: "unknown" as const, asserted: false }, + source: { identity: "test" }, + prevHash: "", + hash: "", + }); + const migrated = mk("migrated", "2026-11-04T06:00:00.000Z", "2026-11-04T15:00:00+08:00"); + const native = mk("native", "2026-11-04T07:30:00.000Z", "2026-11-04T08:00:00.000Z"); + const first = pageEvents([native, migrated], { limit: 1 }); + expect(first.snapshotAt).toBe("2026-11-04T08:00:00.000Z"); + const second = pageEvents([native, migrated], { limit: 1, cursor: first.nextCursor }); + expect(second.events.map((event) => event.id)).toEqual(["migrated"]); + }); + test("identities the action-result contract accepts are valid events", async () => { // byRun may carry punctuation (stored as appliedByRun); objectRef // may run to 300 chars (isObjectRef). Neither may be lost here.