From c46c7df3acc97d31bed0efa89911ac23a39b357a Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 3 Nov 2026 11:29:37 -0600 Subject: [PATCH] quota: gather meta + opendesign by asking OpenCode (Drew, 2026-11-03) Meta: the gatherer never asked the quota module for meta \u2014 listConfiguredQuotaProviders filters providers whose session door is disabled, and the deployed config disables the direct meta door (sessions reach the pool through model routes). The board then had no Meta pool at all: the collector filtered meta:high-usage at assembly for the same reason. The only Meta read left was the dev.meta.ai console scrape (file-export), dark since the console tab closed. - gather-quota.ts: explicit Meta module ask (runMetaModule), ClinePass-style one-run discipline; the Meta file-export producer is retired (FILE_EXPORTS empty, convention kept). - quota-gather-map.ts: serviceIdFor maps meta -> meta:high-usage and opendesign -> opendesign:go (mirrors the pool ids). - quota-extract.ts: FILTER_EXEMPT_POOL_IDS \u2014 meta:high-usage stays on the board despite its disabled direct door (ruled standard report member, Drew 2026-11-03); opendesign shell note now names the gatherer as its live source. OpenDesign: the module read was already landing every tick under serviceId "opendesign"; the pool is opendesign:go, so the overlay never matched and the shell showed healthy with no windows. The serviceId mapping fixes the landing. Tests: full aggregator suite 1376 pass. (bunx tsc shows one pre-existing error in test/overview.test.ts on origin/main, unrelated.) --- pm-stack/aggregator/scripts/gather-quota.ts | 92 ++++++++++++++++--- pm-stack/aggregator/src/quota-extract.ts | 28 +++++- pm-stack/aggregator/src/quota-gather-map.ts | 4 + .../aggregator/test/quota-gather-map.test.ts | 2 + pm-stack/aggregator/test/quota.test.ts | 18 ++-- 5 files changed, 121 insertions(+), 23 deletions(-) diff --git a/pm-stack/aggregator/scripts/gather-quota.ts b/pm-stack/aggregator/scripts/gather-quota.ts index 0ea2a790fa..aa1426fb2a 100755 --- a/pm-stack/aggregator/scripts/gather-quota.ts +++ b/pm-stack/aggregator/scripts/gather-quota.ts @@ -22,12 +22,14 @@ // itself uses. // 3. The Turso org usage API (#1049): usage + subscription over // the verified route, token from Bitwarden by name. -// 2. File exports (the Meta Phase-1 convention, #1301): producers -// the module cannot reach write latest.json documents on the -// laptop (v1: Meta, ~/atlas/meta-quota-export/latest.json); +// 2. File exports (the Phase-1 convention, #1301): producers the +// module cannot reach write latest.json documents on the laptop; // the gatherer ingests them in the same tick. A document older // than 30 minutes means the producer is unreachable — an error -// entry, never zeros. +// entry, never zeros. The v1 producer (Meta's dev.meta.ai +// console scrape) was retired 2026-11-03: Drew's ruling is that +// quota is gathered by asking OpenCode — family 5 below is its +// replacement, and the producer list is empty today. // 4. The native ClinePass token adapter (#1159, src/clinepass- // adapter.ts on the #1153 framework): fills the ClinePass row // when the OpenChamber module did not already produce a fresh @@ -35,6 +37,14 @@ // a credential reference on this host. An expired token is // session-expired / re-login with the last-known row retained // (#1268) — never a 0% row. +// 5. The Meta module ask (2026-11-03): the provider listing +// (family 1) filters providers whose session door is disabled +// in the opencode config, and `meta` is disabled as a direct +// door — sessions reach the pool through model routes — so the +// listing never names it. The gatherer asks the module for meta +// explicitly (runMetaModule): the read runs through OpenCode's +// own credential machinery, which is what gathering quota by +// asking OpenCode means for a route-only pool. // // Outputs: // - quota-current.json — the latest-state contract (model.ts @@ -65,7 +75,7 @@ // OPENCODE_DB_PATH (~/.local/share/opencode/opencode.db), // QUOTA_CURRENT_PATH, QUOTA_HEARTBEAT_PATH, // QUOTA_GATHERER_STATE_PATH, QUOTA_SNAPSHOTS_DIR (./snapshots), -// USAGE_SNAPSHOT_OUTBOX_PATH, META_QUOTA_EXPORT_PATH, +// USAGE_SNAPSHOT_OUTBOX_PATH, // QUOTA_GATHER_TIMEOUT_MS (15000), // QUOTA_GATHER_CONCURRENCY (6), TURSO_API_TOKEN (else the // Bitwarden secret turso.platform-api-token-muse-cli, resolved @@ -135,14 +145,16 @@ const timeoutMs = Number(process.env.QUOTA_GATHER_TIMEOUT_MS ?? 15_000); const gatherConcurrency = Number(process.env.QUOTA_GATHER_CONCURRENCY ?? 6); const OBSERVED_BY = "quota-gatherer"; -/** File-export producers ingested each tick (the #1301 convention). */ -const FILE_EXPORTS = [ - { - key: "meta", - path: process.env.META_QUOTA_EXPORT_PATH ?? join(HOME, "atlas/meta-quota-export/latest.json"), - staleMs: 30 * 60_000, - }, -]; +/** + * File-export producers ingested each tick (the #1301 convention). + * The v1 producer — Meta, ~/atlas/meta-quota-export/latest.json, a + * dev.meta.ai console scrape — was retired 2026-11-03: quota is + * gathered by asking OpenCode (Drew's ruling), and the module's own + * Meta provider replaced the scrape (see runMetaModule). The list + * stays, empty, for the next producer the module cannot reach; + * entryFromFileExport keeps the convention's mapping tested. + */ +const FILE_EXPORTS: { key: string; path: string; staleMs: number }[] = []; interface QuotaModule { listConfiguredQuotaProviders: (opts?: { includeDisabled?: boolean }) => Promise; @@ -420,6 +432,46 @@ async function runClinePass(tickIso: string): Promise { }; } +/** + * The Meta module ask (2026-11-03, Drew's ask-OpenCode ruling): the + * quota module's provider listing filters out providers whose + * session door is disabled in the opencode config, and `meta` is + * disabled as a direct door (sessions reach the pool through model + * routes), so the listing never names it and the plain tick never + * asked — the board's Meta row went dark even though OpenCode holds + * the pool's credential and the module's Meta provider reads the + * plan's own usage endpoint with it. The gatherer asks explicitly, + * the same out-of-band registration pattern as the native ClinePass + * adapter. No outer timeout wraps the ask: the provider self-times + * out per request (15s), and its account-token fallback is a second + * request — clipping the pair at the generic 15s cap could turn a + * slow success into a false error row. + */ +async function runMetaModule(quota: QuotaModule, tickIso: string): Promise { + const t0 = Date.now(); + try { + const results = await quota.fetchQuotaForProviderInstances("meta"); + const entries = results.map((r) => entryFromResult(r, tickIso)); + const anyOk = entries.some((e) => e.state === "ok"); + const firstBad = entries.find((e) => e.state !== "ok"); + return { + id: "meta", + state: anyOk ? "ok" : "error", + ms: Date.now() - t0, + entries, + ...(!anyOk && firstBad?.error ? { error: firstBad.error } : {}), + }; + } catch (err) { + return { + id: "meta", + state: "error", + ms: Date.now() - t0, + entries: [], + error: safeProviderReason(err instanceof Error ? err.message : String(err)), + }; + } +} + interface ProviderRun { id: string; state: "ok" | "error"; @@ -559,6 +611,20 @@ async function main(): Promise { } } + // 2026-11-03: the Meta module ask (see runMetaModule). Exactly one + // meta run survives, mirroring the ClinePass discipline above: a + // fresh listed run (the door re-enabled someday) wins and the ask + // is skipped; otherwise the ask replaces the listed run, or is + // appended when the listing never named meta. + const metaIdx = runs.findIndex((r) => r.id === "meta"); + if (metaIdx !== -1 && runs[metaIdx].entries.some((e) => e.state === "ok")) { + console.log("quota-gatherer: meta ok via provider listing - explicit module ask skipped"); + } else { + const metaRun = await runMetaModule(quota, tickAt); + if (metaIdx === -1) runs.push(metaRun); + else runs[metaIdx] = metaRun; + } + // The Claude auth source exposes an expiry timestamp. Persist only that // metadata and its source class, never the credential object or values. const claudeRun = runs.find((run) => run.id === "claude"); diff --git a/pm-stack/aggregator/src/quota-extract.ts b/pm-stack/aggregator/src/quota-extract.ts index 7560a5c748..4ea60378a9 100644 --- a/pm-stack/aggregator/src/quota-extract.ts +++ b/pm-stack/aggregator/src/quota-extract.ts @@ -559,7 +559,7 @@ const SHELL_POOLS: QuotaPool[] = [ plan: "Go", state: "healthy", windows: [], - note: "Usage uninstrumented — no current read. API route verified; a manual dashboard read is required for a percentage.", + note: "No dated read. Live windows arrive through the quota gatherer (the OpenCode opendesign credential, read by the OpenChamber quota module) and are overlaid onto this pool by overlayQuotaCurrent.", }, { id: "deepseek:api", @@ -621,6 +621,28 @@ export function poolFilteredByDisabled(poolId: string, disabledProviderIds: Read return poolProviderIds(poolId).every((id) => disabledProviderIds.has(id)); } +/** + * Pools that stay on the board even when every door provider is + * disabled — #1114's filter yields to this list. The filter exists so + * the board never presents a pool nobody can burn; an exempt pool IS + * burned (through the route layer, not the disabled direct door) and + * its quota is measured through OpenCode's credential machinery, so + * hiding it would leave a live pool unreported. Drew, 2026-11-03: + * meta and opendesign are standard report members and must show real + * quotas gathered by asking OpenCode. Today the list holds only + * meta:high-usage: the deployed config disables the `meta` provider + * as a direct session door, which otherwise filtered the pool at + * assembly and left the board with no Meta row at all, while the + * gatherer's module read (serviceId meta:high-usage) had no pool to + * land on. + */ +export const FILTER_EXEMPT_POOL_IDS: ReadonlySet = new Set(["meta:high-usage"]); + +/** True when the disabled-door filter must not drop this pool. */ +export function poolFilterExempt(poolId: string): boolean { + return FILTER_EXEMPT_POOL_IDS.has(poolId); +} + /** * Extract every pool's freshest dated read from the quota view text. * @@ -644,7 +666,7 @@ export function extractQuotaPools( ): QuotaPool[] { const pools: QuotaPool[] = []; for (const spec of POOL_SPECS) { - if (poolFilteredByDisabled(spec.id, disabledProviderIds)) { + if (!poolFilterExempt(spec.id) && poolFilteredByDisabled(spec.id, disabledProviderIds)) { onFiltered?.(spec.id, poolProviderIds(spec.id).join(",")); continue; } @@ -683,7 +705,7 @@ export function extractQuotaPools( pools.push(pool); } const shells = SHELL_POOLS.filter((p) => { - if (!poolFilteredByDisabled(p.id, disabledProviderIds)) return true; + if (poolFilterExempt(p.id) || !poolFilteredByDisabled(p.id, disabledProviderIds)) return true; onFiltered?.(p.id, poolProviderIds(p.id).join(",")); return false; }); diff --git a/pm-stack/aggregator/src/quota-gather-map.ts b/pm-stack/aggregator/src/quota-gather-map.ts index cf50063cda..26bc0b60f8 100644 --- a/pm-stack/aggregator/src/quota-gather-map.ts +++ b/pm-stack/aggregator/src/quota-gather-map.ts @@ -74,6 +74,10 @@ export function serviceIdFor(providerId: string): string { return "cline-pass:cline-pass"; case "deepseek": return "deepseek:api"; + case "meta": + return "meta:high-usage"; + case "opendesign": + return "opendesign:go"; default: return providerId; } diff --git a/pm-stack/aggregator/test/quota-gather-map.test.ts b/pm-stack/aggregator/test/quota-gather-map.test.ts index 028fe819d3..86e9af8192 100644 --- a/pm-stack/aggregator/test/quota-gather-map.test.ts +++ b/pm-stack/aggregator/test/quota-gather-map.test.ts @@ -532,6 +532,8 @@ describe("serviceIdFor", () => { test("known pools map to hub ids; others pass through", () => { expect(serviceIdFor("codex")).toBe("openai:codex"); expect(serviceIdFor("deepseek")).toBe("deepseek:api"); + expect(serviceIdFor("meta")).toBe("meta:high-usage"); + expect(serviceIdFor("opendesign")).toBe("opendesign:go"); expect(serviceIdFor("openai.alternate")).toBe("openai.alternate"); }); }); diff --git a/pm-stack/aggregator/test/quota.test.ts b/pm-stack/aggregator/test/quota.test.ts index 1869148955..0392a49ba3 100644 --- a/pm-stack/aggregator/test/quota.test.ts +++ b/pm-stack/aggregator/test/quota.test.ts @@ -372,16 +372,20 @@ describe("disabled_providers enforcement (#1114)", () => { const pools = extractQuotaPools(VIEW, NOW, disabled, (poolId, providerId) => filtered.push([poolId, providerId])); const ids = pools.map((p) => p.id); expect(ids).not.toContain("openai:codex"); - expect(ids).not.toContain("meta:high-usage"); - expect(filtered).toEqual([ - ["meta:high-usage", "meta"], - ["openai:codex", "openai"], - ]); + expect(filtered).toEqual([["openai:codex", "openai"]]); const choices = computeChoices(pools, NOW.getTime()); const named = [...choices.hasHeadroom, ...choices.burnBeforeReset, ...choices.doNotStart]; expect(named).not.toContain("openai:codex"); - expect(named).not.toContain("meta:high-usage"); - for (const id of named) expect(disabled.has(poolProviderId(id))).toBe(false); + // The one exemption (Drew, 2026-11-03): meta:high-usage is a + // standard report member whose quota is gathered by asking + // OpenCode; its disabled entry is the direct session door only, + // so the pool stays on the board — and in guidance — while + // every other named pool still answers to an enabled door. + expect(ids).toContain("meta:high-usage"); + for (const id of named) { + if (id === "meta:high-usage") continue; + expect(disabled.has(poolProviderId(id))).toBe(false); + } }); test("the Claude pool's door is claude-code: disabling it filters anthropic:claude-pro", () => {