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
Original file line number Diff line number Diff line change
Expand Up @@ -1238,3 +1238,50 @@ stays open). What a session is waiting on the owner for comes from the
dashboard's own tiers, not from labels, and is still the laptop's.
Whether the edge's token can see all four repositories has not been
seen in service; if it cannot, the screen names the ones it cannot.

## 2026-11-24T06:55Z Update: seen in service, and the dashboard's census put right (#14103)

**Seen in service.** At 06:45:48Z the edge's hourly check of its own
reads ran with the new read in it: `selfCheck.kinds.census` is `ok`,
`refused` is empty, and `github.kept` went from 3 to 11, one for each of
the eight lists. All four repositories are readable by the edge's
token, so the list the app shows is whole.

**The dashboard's census.** `pm-stack/aggregator/src/needs-drew.ts`
asked GitHub's search for `repo:<repo> state:open label:"<label>"`,
which GitHub answers 422 to. It now asks each repository's own list of
open issues by label, as the edge does: the same items, on the core
allowance, with no index to lag behind. An answer under a 200 that is
not a list is a failed query, never an empty queue (the list has no
"incomplete results" flag to say so itself). A test stands in for
GitHub as it answers today, refusing the old form with a 422, and
fails on the census as it was. The console's test that holds the two
readings to each other now also holds them to asking for the same
pages.

**The repositories, named two ways.** The console's list of where to
look (`needsRepos`) named two forks and a repository by names they no
longer have. The dashboard's list was repointed when they changed (the
two forks to another organisation on 2026-11-04, the third renamed on
2026-11-08, #5595); the console's, written on 2026-11-22, took the old
names. Nothing was seen to fail: all eight lists answered the edge
under the old names, and asking git where each name leads gives the
same commit for both of each pair, two of them pushed within hours, so
GitHub answers the old names with the present repositories. But an item
was `developing-today/opencode#5` in the app and
`developing-today-forks/opencode#5` on the dashboard, and the console
takes a reply only for an item in a repository on its list: a reply
from the app to an item the dashboard had named would have been refused
as "not an item on the Needs me list". Whether an answer by way of an
old name costs a second request against the allowance was not measured.
The console's default is the dashboard's list now, and a test holds the
two to each other.

The edge is told the list by the laptop, which is the larger fault: the
laptop's checkout is behind main (#13833), so the edge goes on asking
by the old names until the laptop runs this. Which repositories the
platform looks in should be the platform's own to hold, not whatever
the last machine to connect was running (#14163).

**Not seen.** The laptop's dashboard itself: it gets this when its
checkout follows main again (#13833).
66 changes: 45 additions & 21 deletions pm-stack/aggregator/src/needs-drew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
// system of record for "waits on Drew", and this module reconciles them
// into the aggregator's attention view as a read-only source. It censuses
// OPEN issues and PRs carrying user/review or user/escalated across the
// four repos via the GitHub search API (paginated), deduplicates items
// four repos, from each repository's own list of open issues by label
// (paginated; that list carries pull requests too), deduplicates items
// carrying both labels, and reports per-source failures and freshness
// honestly — a failed repo/label query is named in `sources`, never
// silently rendered as "nothing waiting".
//
// It asked the search API until #14103. GitHub answers a search of
// issues that names neither `is:issue` nor `is:pull-request` with a
// 422, so every query of the census failed and none of what waited
// was shown. The list has no such rule, is on the core allowance (the
// search has its own, thirty a minute), does not lag behind an index,
// and is what the PM console's edge reads for the same lists (#14112).
//
// Reconciliation direction (#1226): labels are the INPUT to the page.
// The aggregator never writes labels back; the orchestrator remains the
// only label writer.
Expand Down Expand Up @@ -76,10 +84,11 @@ export interface NeedsDrewSourceStatus {
/** True when the page cap stopped the census early — the count is a
* floor, and the census says so instead of looking complete. */
truncated?: boolean;
/** True when any page of this query came back with GitHub's
* `incomplete_results: true` (search timed out / partially indexed).
* The count is then a floor even when it equals `total_count`, so the
* census must never present it as authoritative (Codex P2 on #3970). */
/** True when a page of this query said its results were incomplete.
* That was the search API's `incomplete_results` (Codex P2 on #3970);
* the repository list this census asks now (#14103) has no such
* flag, so nothing sets this today. Kept because a census that
* carries it must still never be presented as authoritative. */
incomplete?: boolean;
}

Expand All @@ -98,12 +107,14 @@ export type NeedsDrewFetchPage = (url: string) => Promise<{ ok: boolean; json: u
const PER_PAGE = 100;
const MAX_PAGES = 10;

export function needsDrewSearchUrl(repo: string, label: NeedsDrewLabel, page: number): string {
const q = `repo:${repo} state:open label:"${label}"`;
return `https://api.github.com/search/issues?q=${encodeURIComponent(q)}&per_page=${PER_PAGE}&page=${page}`;
/** One page of a repository's open issues and pull requests carrying a
* label, as the REST API lists them. Not the search: see the note at
* the top of this file (#14103). */
export function needsDrewListUrl(repo: string, label: NeedsDrewLabel, page: number): string {
return `https://api.github.com/repos/${repo}/issues?state=open&labels=${encodeURIComponent(label)}&per_page=${PER_PAGE}&page=${page}`;
}

interface RawSearchItem {
interface RawListItem {
number?: unknown;
title?: unknown;
html_url?: unknown;
Expand Down Expand Up @@ -182,6 +193,19 @@ export function needsDrewWaitCounts(census: NeedsDrewCensus): Record<NeedsDrewWa
return counts;
}

/** How long a completed sweep stays fresh. A sweep is one request for
* each repository and label (eight), on GitHub's core allowance. With
* a token that is nothing against five thousand an hour, and five
* minutes is as fresh as the page needs. Without one GitHub allows an
* address sixty requests an hour, which a sweep every five minutes
* (ninety-six) would use up by itself: it is then made every ten
* minutes (forty-eight), which still leaves little for anything else.
* (The search this census asked until #14103 was counted apart, by the
* minute, so a missing token did not show there.) */
export function needsDrewSweepTtlMs(hasToken: boolean): number {
return hasToken ? 300_000 : 600_000;
}

export interface NeedsDrewSweeperOptions {
/** How long a completed sweep stays fresh. */
ttlMs?: number;
Expand Down Expand Up @@ -251,21 +275,18 @@ export async function buildNeedsDrewCensus(
const status: NeedsDrewSourceStatus = { repo, label, ok: true, count: 0, fetchedAt };
try {
let page = 1;
let total = Number.POSITIVE_INFINITY;
while (page <= MAX_PAGES) {
const res = await fetchPage(needsDrewSearchUrl(repo, label, page));
const res = await fetchPage(needsDrewListUrl(repo, label, page));
if (!res.ok) {
const j = res.json as { status?: unknown; error?: unknown } | null;
throw new Error(typeof j?.status === "number" ? `HTTP ${j.status}` : String(j?.error ?? "fetch failed"));
}
const payload = res.json as { total_count?: unknown; items?: unknown; incomplete_results?: unknown };
if (typeof payload?.total_count === "number") total = payload.total_count;
// GitHub returns 200 + incomplete_results for a search that
// timed out or is only partially indexed. Ignoring the flag
// would let a truncated sweep look complete — worst case an
// authoritative empty queue (Codex P2 on #3970).
if (payload?.incomplete_results === true) status.incomplete = true;
const rawItems = Array.isArray(payload?.items) ? (payload.items as RawSearchItem[]) : [];
// The list answers an array. Anything else under a 200 (an
// error object, a payload of another shape) is a failed
// query: read as "no items" it would be an authoritative
// empty queue.
if (!Array.isArray(res.json)) throw new Error("the answer was not a list");
const rawItems = res.json as RawListItem[];
for (const raw of rawItems) {
// Defensive: the query asks for state:open, but a stale or
// hand-built payload must never leak a closed item in.
Expand Down Expand Up @@ -295,10 +316,13 @@ export async function buildNeedsDrewCensus(
hands: extractNeedsDrewHands(raw.body),
});
}
if (rawItems.length < PER_PAGE || status.count >= total) break;
// A page that is not full is the last. A full one is followed
// by another; if the cap on pages is reached with the last
// page still full, there may be more, and the count is a floor.
if (rawItems.length < PER_PAGE) break;
if (page === MAX_PAGES) status.truncated = true;
page++;
}
if (status.count < total) status.truncated = true;
} catch (err) {
status.ok = false;
status.error = err instanceof Error ? err.message : String(err);
Expand Down
36 changes: 21 additions & 15 deletions pm-stack/aggregator/src/sources/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import {
import { mergeChargeRows } from "../charges-collect.ts";
import type { CloudflareExportDoc } from "../saas-extract.ts";
import { poolItemToGhItem } from "../projects.ts";
import { createNeedsDrewSweeper, type NeedsDrewCensus } from "../needs-drew.ts";
import { createNeedsDrewSweeper, needsDrewSweepTtlMs, type NeedsDrewCensus } from "../needs-drew.ts";
import { INITIAL_STANDING_AUTO, sanitizeTierItemExtensions, withUserFallbacks } from "../tier-items.ts";
import { assembleWorkItems } from "../work-items.ts";
import {
Expand Down Expand Up @@ -861,20 +861,26 @@ export function liveSource(
let laptopFailureAt = 0;
let laptopInFlight: Promise<MappedSessions | null> | null = null;
const LAPTOP_FAILURE_CACHE_MS = 15_000;
// #1226: the Needs-Drew label census hits the GitHub search API
// (8 queries per sweep). The sweeper caches for 5 minutes and shares
// one in-flight sweep between concurrent callers, so the three
// attention fragments rendering together do not each pay that cost or
// burn the search rate limit (#3970).
const needsDrewSweep = createNeedsDrewSweeper((url) => {
const token = process.env.PM_AGG_GITHUB_TOKEN ?? process.env.GITHUB_TOKEN;
const headers: Record<string, string> = {
Accept: "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
...(token ? { Authorization: "Bearer " + token } : {}),
};
return getJson(url, headers);
});
// #1226: the Needs-Drew label census asks each repository's list of
// open issues by label (8 requests per sweep; the search API until
// #14103, which GitHub came to refuse in the form it was asked). The
// sweeper caches for 5 minutes and shares one in-flight sweep between
// concurrent callers, so the three attention fragments rendering
// together do not each pay that cost (#3970).
const needsDrewSweep = createNeedsDrewSweeper(
(url) => {
const token = process.env.PM_AGG_GITHUB_TOKEN ?? process.env.GITHUB_TOKEN;
const headers: Record<string, string> = {
Accept: "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
...(token ? { Authorization: "Bearer " + token } : {}),
};
return getJson(url, headers);
},
{},
// Half as often with no token: see needsDrewSweepTtlMs.
{ ttlMs: needsDrewSweepTtlMs(Boolean(process.env.PM_AGG_GITHUB_TOKEN ?? process.env.GITHUB_TOKEN)) },
);
// #9922: the Path to Phase 12 body feed — one GraphQL read of
// #1235's body, cached for 5 minutes and shared in-flight (same
// discipline as the Needs-Drew sweeper above), fail-soft to the
Expand Down
Loading
Loading