Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pm-stack/aggregator/src/derive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface ExecutionStrip {
unknown: RefKey[];
}

const IMPLEMENTING_LABELS = new Set(["status:in-progress", "in-progress", "ready-for-agent"]);
const IMPLEMENTING_LABELS = new Set(["status:in-progress", "in-progress"]);

export function executionStrip(links: Link[], items: Map<RefKey, GhItem>): ExecutionStrip {
const strip: ExecutionStrip = {
Expand Down
12 changes: 11 additions & 1 deletion pm-stack/aggregator/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,8 @@ export interface ItemExtras {
epicRollup?: EpicRollup;
/** Project-pool briefs for linked refs (#1279). */
briefs?: Map<RefKey, ItemBrief>;
/** Real ready-for-agent dispatch state for explicitly labelled linked issues. */
dispatchStates?: { ref: RefKey; state: string; provenance: { source: string; observedAt: string } }[];
/** The shared audit stream, scoped to the item's canonical refs. */
activity?: { events: AuditEvent[]; globalHref: string; gaps: GapRecord[]; coverage?: readonly ActivityCoverage[] };
}
Expand Down Expand Up @@ -1871,12 +1873,20 @@ export function renderItem(
? `<p>Live services: ${extras.serviceLinks.map((s) => `<a href="${esc(s.url)}">${esc(s.label)} ↗</a>`).join(" · ")}</p>`
: "";
const epicRollup = extras?.epicRollup ? epicRollupHtml(extras.epicRollup) : "";
const dispatchSection = extras?.dispatchStates?.length
? `<section><h2>ready-for-agent dispatch</h2><ul>${extras.dispatchStates
.map(
(entry) =>
`<li><a href="https://github.com/${esc(entry.ref.replace("#", "/issues/"))}">${esc(entry.ref)}</a>: <strong>${esc(entry.state)}</strong> <span class="muted">· ${esc(entry.provenance.source)} checked ${esc(entry.provenance.observedAt)}</span></li>`,
)
.join("")}</ul></section>`
: "";
const activitySection = extras?.activity
? `<h2>Activity stream</h2><p><a href="${esc(extras.activity.globalHref)}">View these events in the global river</a></p><p class="muted"><strong>Freshness: unknown.</strong> 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.</p>${eventTableHtml(extras.activity.events)}<h3>Known activity gaps</h3><p class="muted">Gap records are source-scoped and do not currently identify affected item refs, so this is the global known-gap list.</p><div class="tblwrap">${gapsHtml(extras.activity.gaps)}</div><h3>Activity source coverage</h3><div class="tblwrap">${activityCoverageHtml(extras.activity.coverage)}</div>`
: "";
return layout(
title,
`<h1>${esc(title)}</h1><p class="muted">subject: <code>${esc(subject)}</code></p>${epicRollup}${svcLinks}${stripHtml(items, links)}
`<h1>${esc(title)}</h1><p class="muted">subject: <code>${esc(subject)}</code></p>${epicRollup}${svcLinks}${dispatchSection}${stripHtml(items, links)}
${
extras?.briefs
? briefPanelsForRefs(
Expand Down
60 changes: 57 additions & 3 deletions pm-stack/aggregator/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,51 @@ import type { Source } from "./source.ts";
import { fixtureSource } from "./sources/fixtures.ts";
import { liveSource } from "./sources/live.ts";
import { buildQueueView, queueInputsStale } from "./queue-view.ts";
import { dispatchStateFor, fetchRfaState, RFA_NOT_PICKED_UP } from "./sources/ready-for-agent.ts";

const cfg = loadConfig();
const commentsStore = new CommentsStore(cfg.commentsFile);
const roadmapAnnotationsStore = new RoadmapAnnotationsStore(cfg.roadmapAnnotationsFile);
const coverageStore = new CoverageSnapshotStore(cfg.coverageSnapshotFile);

async function readyAgentDispatchStates(items: Map<RefKey, GhItem>) {
const targets = [...items.values()].filter((item) =>
item.labels.some((label) => label.toLowerCase() === "ready-for-agent") && /#\d+$/.test(item.ref),
);
if (!targets.length) return [];
const observedAt = new Date().toISOString();
if (cfg.source !== "live") {
// #4969 (Codex on PR #5283): fixtures mode must never read the live
// harness — deterministic fixture dispatch data, mirroring the
// health.ts fixtures boundary. The canned set has no picked-up
// work item, so every labelled fixture item is honestly
// "not picked up".
return targets.map((item) => ({
ref: item.ref,
state: RFA_NOT_PICKED_UP,
provenance: { source: "ready-for-agent", observedAt, repository: item.ref.split("#")[0], mode: "fixtures" },
}));
}
try {
const state = await fetchRfaState(cfg.readyForAgent.baseUrl);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep fixture-mode dispatch reads off the live harness

When PM_AGG_SOURCE=fixtures (the default), opening the fixture dispatch-trial item now performs real GraphQL requests against the configured harness and attaches live dispatch state to canned issue data. Without a running harness, the same fixture instead reports unavailable, making this surface environment-dependent. The existing harness integration in health.ts explicitly skips live reads in fixtures mode. Apply the same boundary here and supply deterministic fixture dispatch data; the new boot test currently accepts unavailable because it only checks that the state is truthy.

Useful? React with 👍 / 👎.

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.

Fixed in 66db0aa: fixtures mode (cfg.source !== live) no longer calls fetchRfaState — readyAgentDispatchStates returns deterministic fixture data (RFA_NOT_PICKED_UP with mode=fixtures provenance), mirroring the health.ts boundary. The boot test now asserts the exact state "not picked up" instead of any truthy state.

return targets.map((item) => {
const match = /^(.*)#(\d+)$/.exec(item.ref);
if (!match) return null;
return {
ref: item.ref,
state: dispatchStateFor(state, match[1], Number(match[2])) || RFA_NOT_PICKED_UP,
provenance: { source: "ready-for-agent", observedAt, repository: match[1] },
};
}).filter((entry): entry is NonNullable<typeof entry> => entry !== null);
} catch {
return targets.map((item) => ({
ref: item.ref,
state: "unavailable",
provenance: { source: "ready-for-agent", observedAt, repository: item.ref.split("#")[0], error: "harness read failed" },
}));
}
}

/** #1220: the coverage snapshot behind the /projects panel — computed
* from the feed's items + the Project pool, rotated weekly by
* nextCoverageSnapshot, persisted only when it actually changes. */
Expand Down Expand Up @@ -2127,12 +2166,15 @@ async function handler(req: Request): Promise<Response> {
return json(body);
}

const itemJsonMatch = /^\/api\/item\/(.+)\.json$/.exec(path);
const itemMatch = /^\/item\/(.+)$/.exec(path);
if (itemMatch) {
const matchedItemPath = itemJsonMatch ?? itemMatch;
if (matchedItemPath) {
Comment on lines +2171 to +2172

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Return a JSON error for unresolved API item IDs

When /api/item/<id>.json references an unknown or deleted item, this shared handler falls through to the existing HTML Not found response rather than returning JSON. A machine consumer parsing the JSON endpoint's response therefore receives a parsing error instead of a structured 404. Handle the API miss separately, using the existing notFoundResponse(path) helper or a JSON error response, while preserving the HTML response for /item/<id>.

Useful? React with 👍 / 👎.

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.

Fixed in 66db0aa: an unresolved /api/item/.json now returns notFoundResponse(path) (structured JSON 404) while /item/ keeps the HTML 404. Covered by a new boot test asserting JSON 404 + content-type for the API path and HTML 404 for the page path.

// #2748: same guard as /discuss — JSON 400 on malformed encoding.
const id = decodePathSegment(itemMatch[1]);
const encodedId = matchedItemPath[1];
const id = decodePathSegment(encodedId);
if (id === null) {
return json({ error: `malformed percent-encoding in path segment: ${itemMatch[1]}` }, 400);
return json({ error: `malformed percent-encoding in path segment: ${encodedId}` }, 400);
}
const [board, rows] = await Promise.all([source.board().catch(() => []), source.roadmap().catch(() => [])]);
const roadmapRow = rows.find((r) => r.subject === id);
Expand Down Expand Up @@ -2175,6 +2217,14 @@ async function handler(req: Request): Promise<Response> {
// item page carries the status-request control for that pool item.
const pooled = pool.find((p) => refs.includes(p.ref));
const epicRollup = pooled?.kind === "Epic" ? buildEpicRollups(pool).get(pooled.ref) : undefined;
const dispatchStates = await readyAgentDispatchStates(items);
if (itemJsonMatch) {
return json({
subject,
linkedItems: [...items.values()],
dispatchStates,
});
}
const extras = {
dashComments,
...(roadmapRow ? { roadmapAnnotations } : {}),
Expand All @@ -2194,6 +2244,7 @@ async function handler(req: Request): Promise<Response> {
: {}),
...(epicRollup ? { epicRollup } : {}),
briefs,
...(dispatchStates.length ? { dispatchStates } : {}),
activity: {
events: itemEvents,
globalHref: `/events?${activityQuery.toString()}`,
Expand All @@ -2203,6 +2254,9 @@ async function handler(req: Request): Promise<Response> {
};
return html(renderItem(title, id, links, items, comments, prov(), extras));
}
// #4969 (Codex on PR #5283): an unresolved /api/item/<id>.json id
// gets the structured JSON 404, not the HTML page response.
if (itemJsonMatch) return notFoundResponse(path);
return html(
`<h1>Not found</h1><p class="muted">no board item or roadmap row with subject <code>${esc(id)}</code></p>`,
404,
Expand Down
30 changes: 30 additions & 0 deletions pm-stack/aggregator/test/boot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ describe("server boots from fixtures", () => {
expect(body.source.board).toBe("fixtures");
});

test("item JSON exposes ready-for-agent dispatch state and provenance", async () => {
const id = "kaneo:code/fx0dispatchtrial0000107";
const res = await fetch(`http://127.0.0.1:${port}/api/item/${encodeURIComponent(id)}.json`);
expect(res.status).toBe(200);
const body = (await res.json()) as {
linkedItems: { ref: string; labels: string[] }[];
dispatchStates: { ref: string; state: string; provenance: { source: string; observedAt: string } }[];
};
expect(body.linkedItems.find((item) => item.ref === "developing-today/code#762")?.labels).toContain("ready-for-agent");
expect(body.dispatchStates).toHaveLength(1);
// Fixtures mode is deterministic and never reads the live harness:
// the canned dispatch-trial item has no work item, so its state is
// exactly "not picked up" — never an environment-dependent
// "unavailable".
expect(body.dispatchStates[0].state).toBe("not picked up");
expect(body.dispatchStates[0].provenance.source).toBe("ready-for-agent");
expect(body.dispatchStates[0].provenance.observedAt).toBeTruthy();
});

test("unknown item JSON id returns a structured JSON 404", async () => {
const res = await fetch(`http://127.0.0.1:${port}/api/item/${encodeURIComponent("kaneo:code/no-such-item-4969")}.json`);
expect(res.status).toBe(404);
expect(res.headers.get("content-type")).toContain("application/json");
const body = (await res.json()) as { error: string };
expect(body.error).toBe("not found");
const page = await fetch(`http://127.0.0.1:${port}/item/${encodeURIComponent("kaneo:code/no-such-item-4969")}`);
expect(page.status).toBe(404);
expect(page.headers.get("content-type")).toContain("text/html");
});

test("front door renders the overview, board lives at /board (#1134)", async () => {
const root = await fetch(`http://127.0.0.1:${port}/`);
expect(root.status).toBe(200);
Expand Down
23 changes: 21 additions & 2 deletions pm-stack/aggregator/test/render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ describe("execution strip", () => {
expect(strip.merged.map((i) => i.ref)).toContain("developing-today/code#752");
expect(strip.review.map((i) => i.ref)).toContain("developing-today/code#763");
expect(strip.implementing.map((i) => i.ref)).toContain("developing-today/code#900");
// #762 is labelled ready-for-agent, so it counts as implementing.
expect(strip.implementing.map((i) => i.ref)).toContain("developing-today/code#762");
// The label alone is not evidence that the harness picked the issue up.
expect(strip.queued.map((i) => i.ref)).toContain("developing-today/code#762");
});
test("records unresolved refs", () => {
const strip = executionStrip([{ ref: "nowhere/repo#9999", relation: "tracks" }], items);
Expand Down Expand Up @@ -304,6 +304,25 @@ describe("render smoke (fixtures)", () => {
expect(html).not.toContain("Planning notes");
expect(html).not.toContain("PM-stack design & phase plan");
});
test("item page shows explicit harness dispatch state with provenance", () => {
const item = FIXTURE_BOARD[0];
const html = renderItem(item.title, item.id, item.links, items, [], fixtureSource().provenance(), {
dashComments: [],
formRef: item.id,
formOpts: { identities: [] },
sessions: [],
dispatchStates: [
{
ref: "developing-today/code#762",
state: "not picked up",
provenance: { source: "ready-for-agent fixture state", observedAt: "2026-11-04T00:00:00Z" },
},
],
});
expect(html).toContain("ready-for-agent dispatch");
expect(html).toContain("not picked up");
expect(html).toContain("ready-for-agent fixture state checked 2026-11-04T00:00:00Z");
});
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;
Expand Down
Loading