From b0079303abc56776cb670675f63751df8482ab9a Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 00:38:59 -0600 Subject: [PATCH] fix(pm-stack): prompts appear at once, board-sync links are not replies, and five review findings Found on the host - A prompt sent a second ago was missing from Ask: the list came from GitHub's search index, which runs about a minute behind. It is read from the issue list now. - The board-sync bot's link comment counted as the fleet answering, so a new prompt showed "Answered" and would have raised a notification. Bot comments are not replies. Review findings on #12452, all real - doc/fleet-schedule-registry.md lists pm-console-expose.timer and the console's two process loops. - scripts/demo.ts exits 2 on any argument it does not take. - Choices ticked on a many-answer question survive a background redraw. - "Accept all recommended" sends at most 200 answers a request (the dashboard takes 256), so a large set is accepted whole. - A prompt thread past 100 comments is read from its last page. Tests: 57 bun tests; the new cases cover a 450-question set, a 250-comment thread and a bot comment. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01YLT5K1QVuzZjfWGFhXSSNF --- doc/fleet-schedule-registry.md | 9 +++-- pm-stack/console/public/app.js | 8 +++-- pm-stack/console/scripts/demo.ts | 7 +++- pm-stack/console/src/work.ts | 58 +++++++++++++++++------------- pm-stack/console/test/work.test.ts | 52 +++++++++++++++++++++------ 5 files changed, 94 insertions(+), 40 deletions(-) diff --git a/doc/fleet-schedule-registry.md b/doc/fleet-schedule-registry.md index a182501f5a..60edcad260 100644 --- a/doc/fleet-schedule-registry.md +++ b/doc/fleet-schedule-registry.md @@ -256,7 +256,7 @@ Execution route/pool is recorded separately from work scope: the repo-health que | `aea12c82-c5af-4e5a-9b66-f8e360f87177` | Queue lane (scheduled) - code | `*/40 * * * *` | True | `~/.config/openchamber/projects/path_L2hvbWUvdXNlci9naXQvY29kZQ.json` | not recorded | not recorded | not recorded | not recorded | 2026-11-03 | | `f1b4a33b-14d5-4a69-9ad6-d221e42e3ac9` | Opencode lane claimant/executor - #3026 | `*/10 * * * *` | True | `~/.config/openchamber/projects/path_L2hvbWUvdXNlci9naXQvY29kZQ.json` | opencode-route / workhorse | not recorded | not recorded | not recorded | 2026-11-03 | -### 2b. Laptop systemd user timers (44 listed: 40 enabled, 1 installed-but-disabled; 4 Nix-configured pending deployment) +### 2b. Laptop systemd user timers (45 listed: 41 enabled, 1 installed-but-disabled; 4 Nix-configured pending deployment) The OS-timer half of surface 2. Cadence is the unit's own `OnCalendar`/`OnUnitActiveUSec` spec, read live from `systemctl --user show`. Specs are recorded **complete** — the full effective calendar expression, date **and** time components (e.g. `*-*-* *:*:00`); never truncate a spec to a date-only prefix, because a bare `*-*-*` normalizes to daily at midnight and misstates the cadence (issue #5313). Prompt/brief pointer is the unit file in `~/.config/systemd/user/` (or its Nix store target for linked units). Installed-but-disabled timer units ARE listed in this table and marked `(disabled)` after the unit name: the registry inventories what is installed on the laptop, not only what is currently scheduled, so a disabled unit stays visible until it is uninstalled (reconciled 2026-11-04, issue #5661). @@ -295,6 +295,7 @@ The OS-timer half of surface 2. Cadence is the unit's own `OnCalendar`/`OnUnitAc | `pm-apps-health.timer` (Nix-configured system timer; not yet loaded) | `OnUnitActiveSec=1min,OnBootSec=2min` (not live-verified) | `pm-apps-health.service` | laptop (system systemd; NixOS pm-apps readiness probe, code#8940) | not recorded | not recorded | 2026-11-12 | 2026-11-12 | | `pm-dashboard-backup.timer` | `OnCalendar=*-*-* 04:30:00` | `pm-dashboard-backup.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | | `pm-digest-daily.timer` | `OnCalendar=*-*-* 07:00:00` | `pm-digest-daily.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | +| `pm-console-expose.timer` | `OnUnitActiveUSec=15min,OnBootUSec=5min` | `pm-console-expose.service` | laptop (user systemd; code#12452; runs `pm-stack/console/scripts/expose.py`: keeps the public address as declared, turns Google sign-in on once its secrets exist) | not recorded | not recorded | 2026-11-22 | 2026-11-22 | | `pm-digest-weekly.timer` | `OnCalendar=Mon *-*-* 07:05:00` | `pm-digest-weekly.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | | `pm-git-sync.timer` | `OnUnitActiveUSec=30s,OnBootUSec=30s` | `pm-git-sync.service` | laptop (user systemd) | not recorded | not recorded | not recorded | 2026-11-04 | | `pm-host-health.timer` | `OnCalendar=*-*-* *:00/5:00,OnBootUSec=1min` | `pm-host-health.service` | laptop (user systemd; code#10141) | not recorded | not recorded | 2026-11-14 | 2026-11-14 | @@ -374,15 +375,17 @@ registered. The primary user's repos are maintained by git's own per-user launchd agents, which `git maintenance start` installs outside Nix; they are not recorded here until a review reads them on the Mac. -## Surface 6 — PM-stack process intervals (1 entry) +## Surface 6 — PM-stack process intervals (3 entries) -Recurring loops owned by the PM-stack aggregator process. These are not +Recurring loops owned by PM-stack processes (aggregator, console). These are not external scheduler surfaces; this inventory records timers that run only while the service is alive. | name/id | repo/scope | cadence | state | owner / scope | prompt/brief pointer | budget | kill criteria | created | last review | | --------------------------- | --------------------- | ---------------- | ---------------------------- | ------------- | -------------------------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ---------- | ----------- | | SLO journal sampler (#9988) | developing-today/code | every 60 seconds | live aggregator process only | issue #9988 | `pm-stack/aggregator/src/server.ts` (`SLO_SAMPLE_INTERVAL_MS`) | not recorded | Remove/disable if the health view or append-only journal becomes unavailable; sampler is unref'd and does not keep the process alive | 2026-11-18 | 2026-11-18 | +| Console state refresh | developing-today/code | every 5 seconds | live console process only | PR #12452 | `pm-stack/console/src/docs.ts` (`Docs.start`) | not recorded | Reads only while the app was opened in the last 10 minutes; remove if state is no longer served from memory | 2026-11-22 | 2026-11-22 | +| Console notifier | developing-today/code | every 60 seconds | live console process only | PR #12452 | `pm-stack/console/src/notify.ts` (`Notifier.start`) | not recorded | Reads only while a device is subscribed; remove if notifications move to another sender | 2026-11-22 | 2026-11-22 | ## Surface 7 — Cloudflare Worker cron triggers (1 entry) diff --git a/pm-stack/console/public/app.js b/pm-stack/console/public/app.js index 2a0af5783d..974cb8b7d1 100644 --- a/pm-stack/console/public/app.js +++ b/pm-stack/console/public/app.js @@ -369,6 +369,8 @@ function needCounts() { let shown = 12; const pending = new Map(); +/** Choices ticked on a many-answer question, kept across redraws. */ +const picks = new Map(); /** Answer after a short pause, so a slip of the thumb can be undone. */ function later(key, label, send) { @@ -398,6 +400,7 @@ async function sendAnswer(kind, args, key) { try { const { result } = await api("act", { kind, args }); if (result?.refused?.length) toast(`Not recorded: ${result.refused[0].why}`, true); + picks.delete(key); if (docs.questions?.questions) { const open = docs.questions.questions.open.filter((q) => `${q.set}|${q.ledger}|${q.qid}` !== key); docs.questions.questions.total = open.length; @@ -438,7 +441,8 @@ function questionCard(q) { const key = `${q.set}|${q.ledger}|${q.qid}`; if (pending.has(key)) return null; const id = { set: q.set, ledger: q.ledger, qid: q.qid }; - const picked = new Set(); + const picked = picks.get(key) ?? new Set(); + picks.set(key, picked); const choose = (o) => later(key, `Answered: ${o.label.slice(0, 60)}`, () => sendAnswer("question.answer", { ...id, option: o.id }, key)); const options = q.options.map((o) => { const rec = q.recommended.includes(o.id); @@ -446,7 +450,7 @@ function questionCard(q) { "button", { class: `option${rec ? " rec" : ""}`, - "aria-pressed": q.multi ? "false" : null, + "aria-pressed": q.multi ? String(picked.has(o.id)) : null, onclick: (e) => { if (!q.multi) return choose(o); const b = e.currentTarget; diff --git a/pm-stack/console/scripts/demo.ts b/pm-stack/console/scripts/demo.ts index 9ceacbe78d..a69414375a 100644 --- a/pm-stack/console/scripts/demo.ts +++ b/pm-stack/console/scripts/demo.ts @@ -353,7 +353,12 @@ const table = new Proxy({} as Record>, { has: () => true, getOwnPropertyDescriptor: () => ({ configurable: true, enumerable: true, value: done({}) }), }); -const port = Number(process.argv[2] ?? 4899); +const extra = process.argv.slice(2); +if (extra.length > 1 || (extra[0] !== undefined && !/^[1-9][0-9]{1,4}$/.test(extra[0]))) { + console.error("usage: bun run scripts/demo.ts [port]"); + process.exit(2); +} +const port = Number(extra[0] ?? 4899); Bun.serve({ hostname: "127.0.0.1", port, diff --git a/pm-stack/console/src/work.ts b/pm-stack/console/src/work.ts index a679676914..a55b9839c4 100644 --- a/pm-stack/console/src/work.ts +++ b/pm-stack/console/src/work.ts @@ -26,6 +26,7 @@ const ASK_NOTE = const SET_ID = /^[A-Za-z0-9._:-]{1,160}$/; const REF = /^([A-Za-z0-9._-]+\/[A-Za-z0-9._-]+)#([1-9][0-9]{0,8})$/; const LEANS = ["none", "skeptical", "approve"] as const; +const SUBMIT_BATCH = 200; function clip(value: unknown, max: number): string { const s = typeof value === "string" ? value : ""; @@ -374,7 +375,14 @@ export class Work { } } if (subs.length === 0) throw new OpError(409, "no open question in that set has a recommendation"); - return this.submit(setId, subs); + // The dashboard takes at most 256 answers in one request. + const total = { set: String(setId), applied: 0, refused: [] as { qid: string; why: string }[] }; + for (let at = 0; at < subs.length; at += SUBMIT_BATCH) { + const part = await this.submit(setId, subs.slice(at, at + SUBMIT_BATCH)); + total.applied += part.applied; + total.refused.push(...part.refused); + } + return total; } private ref(value: unknown): { repo: string; number: number } { @@ -411,26 +419,22 @@ export class Work { async asks() { const label = this.ops.cfg.promptLabel; - const found = (await this.ops.gh([ - "-X", - "GET", - "search/issues", - "-f", - `q=repo:${this.repo} is:issue label:"${label}" sort:updated-desc`, - "-f", - "per_page=20", + // The issue list, not the search index: a prompt sent a second ago + // must already be here, and the index runs a minute behind. + const listed = (await this.ops.gh([ + `repos/${this.repo}/issues?labels=${encodeURIComponent(label)}&state=all&sort=updated&direction=desc&per_page=20`, ])) as { - items: { - number: number; - title: string; - body: string | null; - html_url: string; - state: string; - created_at: string; - updated_at: string; - comments: number; - }[]; - }; + number: number; + title: string; + body: string | null; + html_url: string; + state: string; + created_at: string; + updated_at: string; + comments: number; + pull_request?: unknown; + }[]; + const found = { items: listed.filter((i) => !i.pull_request) }; // The newest task for each prompt's issue, by the key the task was filed under. const keys = found.items.map((i) => `repo-health:v1:triage:${this.repo}:issue:${i.number}`); const tasks = keys.length @@ -448,10 +452,16 @@ export class Work { for (const i of found.items) { let thread = this.replies.get(i.number); if (i.comments > 0 && thread?.updated !== i.updated_at) { - const comments = (await this.ops.gh([`repos/${this.repo}/issues/${i.number}/comments?per_page=100`])) as { - body: string | null; - created_at: string; - }[]; + // The newest comments are on the last page. Bots that only link the + // issue elsewhere (the board sync) are not the fleet answering. + const page = Math.max(1, Math.ceil(i.comments / 100)); + const comments = ( + (await this.ops.gh([`repos/${this.repo}/issues/${i.number}/comments?per_page=100&page=${page}`])) as { + body: string | null; + created_at: string; + user?: { type?: string } | null; + }[] + ).filter((c) => c.user?.type !== "Bot"); thread = { updated: i.updated_at, replies: comments.slice(-6).map((c) => ({ diff --git a/pm-stack/console/test/work.test.ts b/pm-stack/console/test/work.test.ts index 7ae3914020..e0fac4bcf9 100644 --- a/pm-stack/console/test/work.test.ts +++ b/pm-stack/console/test/work.test.ts @@ -297,6 +297,19 @@ describe("questions waiting on the owner", () => { { ledgerId: "L1", qid: "c", kind: "answered", optionIds: ["opt-1", "opt-2"] }, ]); await expect(work.acceptRecommended("nope")).rejects.toThrow(/not in the store/); + // The dashboard takes at most 256 answers a request: a large set goes in parts, and all of it goes. + const large = JSON.parse(store()); + const template = large.sets[1].items[0].questions[0]; + large.sets[1].items[0].questions = Array.from({ length: 450 }, (_, n) => ({ ...template, qid: `q${n}`, order: n })); + const big = world({ + dash: (_p, body) => ({ + outcomes: (body as { submissions: { qid: string }[] }).submissions.map((x) => ({ qid: x.qid, applied: true })), + }), + }); + expect((await new Work(big.ops, async () => JSON.stringify(large)).acceptRecommended("new-set")).applied).toBe(450); + const sizes = big.dashed.map((d) => (d.body as { submissions: unknown[] }).submissions.length); + expect(sizes).toEqual([200, 200, 50]); + expect(Math.max(...sizes)).toBeLessThanOrEqual(256); const none = JSON.parse(store()); none.sets[1].items[0].questions = none.sets[1].items[0].questions.filter((q: { qid: string }) => q.qid === "norec"); await expect(new Work(w.ops, async () => JSON.stringify(none)).acceptRecommended("new-set")).rejects.toThrow( @@ -506,16 +519,16 @@ describe("what the owner asks for in his own words", () => { let commentReads = 0; const w = world({ commands: (argv) => { - if (argv.includes("search/issues")) - return JSON.stringify({ - items: [ - found(1, "closed", 1), - found(2, "open", 1), - found(3, "open", 0), - found(4, "open", 2), - found(5, "open", 0), - ], - }); + // The issue list (not the search index, which lags), newest change first. + if (argv[3] === `repos/${REPO}/issues?labels=owner%2Fprompt&state=all&sort=updated&direction=desc&per_page=20`) + return JSON.stringify([ + found(1, "closed", 1), + found(2, "open", 1), + found(3, "open", 0), + { ...found(99, "open", 0), pull_request: {} }, // a labelled pull request is not a prompt + found(4, "open", 2), + found(5, "open", 0), + ]); commentReads++; const n = Number(/issues\/(\d+)\/comments/.exec(argv[3])?.[1]); return JSON.stringify( @@ -543,6 +556,25 @@ describe("what the owner asks for in his own words", () => { [5, "waiting", null, "words 5", []], ]); expect(asks[3].replies[1].text).toBe("and I say"); + // A long thread is read from its last page, and a bot that only links + // the issue somewhere else is not the fleet answering. + const long = world({ + commands: (argv) => + argv[3].includes("/issues?labels=") + ? JSON.stringify([found(7, "open", 250)]) + : JSON.stringify([ + { body: "the real answer", created_at: "2026-11-22T02:00:00Z", user: { type: "User" } }, + { + body: "[CODE-1](https://kaneo.example/task/1)", + created_at: "2026-11-22T02:01:00Z", + user: { type: "Bot" }, + }, + ]), + }); + const [thread] = await new Work(long.ops).asks(); + expect(long.gh()[1]).toEqual([`repos/${REPO}/issues/7/comments?per_page=100&page=3`]); + expect(thread.replies.map((r) => r.text)).toEqual(["the real answer"]); + expect(thread.status).toBe("answered"); // Threads are read again only when the issue has changed. await work.asks(); expect(commentReads).toBe(3);