Skip to content

impl(pm-stack): cost-anomaly detection to Needs-you via the alert throat (#1259 slice 4) #4825

Todo

Description

@dezren39

Part of epic #1184; implementation follow-up of design issue #1259 (spend rollups). Design note: doc/spend-rollups-design-1259.md. Depends on the rollup-store slice of #1259.

Scope

Detect cost anomalies from the spend rollups and surface them through the existing alert throat (pm-stack/aggregator/src/alerts.ts, #3676) into Needs-you (/attention) and the Today/brief summary — no new notification path.

Anomaly classes (v1, thresholds are named constants with tests, per the design note)

  • Burn without progress: an epic/project consumes spend in a window while closing zero child issues in the same window.
  • Single-session dominance: one root session accounts for more than the threshold share of an epic's window spend.
  • Unattributed growth: the unattributed share of total spend rises window-over-window beyond the threshold.
  • Charge without activity: a matched PAYG charge for a service with no corresponding session/quota activity in its period.

Rules

  • Missing or partial data suppresses the anomaly, never fabricates it: an anomaly needs a complete window on both sides of its comparison.
  • Each surfaced anomaly names its evidence: scope, window, the two compared values, and a link to the rollup/drill-down.
  • Delivery class: page + ledger (warning) in v1; no push, per the alerts design (warnings never push in v1).

Acceptance criteria

Checks

  • bun test and bunx tsc --noEmit in pm-stack/aggregator pass (CI on the PR).

Activity

  1. added
    kind/feature
    priority/normal
    effort/m
    app/pm-stack
    on Nov 3, 2026
  2. added
    queue/queued
    source/creator
    status/needs-triage
    task/triage
    on Nov 3, 2026
  3. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: triaged (coverage pass)
    Coverage pass 2026-11-03: reviewed in the fleet-wide per-issue pass (drift / overlap / already-handled / stale / blockers / ordering). Verdict: still live; queued in repo-health-code-pilot as triage at priority 40 (priority/normal). If this is already handled at current main, the triage closes it with evidence; if it needs splitting, the triage files the split.
    Found via: coverage pass 2026-11-03

  4. added
    work/assigned
    queue/claimed
    and removed
    status/needs-triage
    queue/queued
    on Nov 3, 2026
  5. 129 remaining items

  6. developing-today-fleet commented on Nov 29, 2026

    @developing-today-fleet
    Contributor

    Census 2026-11-29 (Felix):

  7. developing-today-fleet commented on Nov 30, 2026

    @developing-today-fleet
    Contributor

    Claim — lane 0052-I (Archer, bravo SUSTAIN 2026-11-30 00:52 CST): the production-caller slice of #4825.

    Premise checked firsthand this lane: issue + all comments read; the detector, warning-only intake, evidence producer and all certified source seams are already on main (pm-stack/aggregator/COST-ANOMALY.md: "This does not complete #4825"). The named remainder is: (1) a production caller that injects the evidence loader into runAlertTick (AlertTickOptions.costAnomalyEvidence), built from the producer + certified sources over the rollup store, explicitly opt-in (default off — the doc bars turning a producer on merely because tests pass); (2) production rollup ingestion wiring if the store reader already exists in-repo.

    Taking that bounded slice: wire the opt-in production caller in the aggregator server wiring, add tests proving default-off (no evidence read, no alert-store call) and enabled (store → producer → intake → ledger) behaviour, update COST-ANOMALY.md, verify, merge. Queue broker down (#16762) — claim rests on this comment.

  8. added 7 commits that reference this issue on Nov 30, 2026
  9. added a commit that references this issue on Nov 30, 2026
  10. developing-today-fleet commented on Nov 30, 2026

    @developing-today-fleet
    Contributor

    Resolution — lane 0322-E (Archer, delta PRESS 2026-11-30): the #4825 production-caller slice has landed.

    PR #17128 #17128 was MERGED 2026-11-30T08:17:06Z (merge commit 94e7883, head 4281523) by lane 0212-P (xaltha), whose verify-then-merge diff-read note is on the PR (comment 2026-11-30T08:16:53Z).

    This lane (0322-E, the staged primary for #17128 after 0152-K → 0237-G/X → 0252-D → 0307-E all ended transport-blocked) independently re-verified post-merge on recovery: two agreeing reads (GraphQL + REST) confirm state MERGED, 7 commits, 7 files +227/−11; full diff read against #4825's stated purpose — new pm-stack/aggregator/src/cost-anomaly-activation.ts (opt-in gate: only explicit 1/true builds a loader), server-wiring.ts loader over spendRollupStore.readAll() with auxiliary certified seams deliberately unsupplied (those classes stay suppressed, never fabricated), alerts.ts optional AlertTickOptions pass-through (default behaviour unchanged), server.ts wiring, COST-ANOMALY.md updated, new test/cost-anomaly-activation-4825.test.ts (5 tests). Diff is exactly the stated purpose, no scope creep.

    #4825 stays OPEN for the remainder the PR itself names: production rollup ingestion + census data producers for the auxiliary certified seams. Claim released.

  11. developing-today-fleet commented on Nov 30, 2026

    @developing-today-fleet
    Contributor

    Disposition — lane 0900-BL (xaltha, wave 0900 surplus leads, 2026-11-30): remainder mapped firsthand; not lane-shaped as one slice. No claim taken.

    Release check first: the true latest state is Archer lane 0322-E's release (comment 7274506513, 2026-11-30T09:39:24Z) after PR #17128 (production caller, opt-in) merged — no live claim stands. This lane re-read the body, all 58 comments, COST-ANOMALY.md, and the code on current main.

    What is landed (verified in code, not just comments): detector + thresholds (src/cost-anomaly.ts), alert-tick intake (runAlertTick + AlertTickOptions.costAnomalyEvidence), evidence producer (src/cost-anomaly-producer.ts), all certified source seams (src/cost-anomaly-sources.ts, src/cost-anomaly-rollup-sources.ts), pre-activation reconciliation/presentation tests (PR #16533), and the opt-in production caller (src/cost-anomaly-activation.ts, PR #17128; default OFF via PM_COST_ANOMALY_ENABLED).

    Remainder, precisely:

    1. Production rollup ingestion. buildSpendRollups + SpendRollupStore.append exist (src/spend-rollups.ts) but nothing in production calls either (grep-verified this lane: the only references are tests and the reader side in server-wiring.ts). Ingestion needs SpendRollupEvents, whose production source per the design(pm-stack): spend rollups — token and dollar attribution per project and per epic, rendered on Projects/Roadmap #1259 design is the per-session usage export (pm-stack/opencode-usage-export/) run through spend attribution (src/spend-attribution.ts) — and attribution itself has NO production caller either (grep-verified: no server module imports it). Its inputs are session records, lane bindings (session→task→issue), and pool items; the bindings live in the fleet queue's database, which the aggregator does not read today. So ingestion is not "wire one caller": it first needs a decided route for bindings + export files into the aggregator's runtime — a design decision spanning two systems, not a bounded lane slice.
    2. Census data producers. Every certified seam is census-fed by design (closure census, root-session census, source-population census, service-activity census — caller-supplied arrays). No production process produces any of these censuses. Each producer must also honestly certify whole-window ok coverage; certifying from a partial source would break the issue's core rule (partial data suppresses, never fabricates), so a producer cannot be written against a source whose completeness is unestablished.

    Why this is a disposition, not a claim: the next step is a design/decision slice (name the bindings + export route into the aggregator, and the completeness source for each census), after which ingestion and each census producer become bounded slices in the shape of the earlier ones. Until that route is named, any single-lane "ingestion" PR would either invent a data path or certify coverage it cannot prove.

    Wake: a comment on this issue naming the bindings/export route (or a design record under #1259) → ingestion becomes a bounded slice; each census producer becomes drawable as its source's completeness is established. Issue stays OPEN; priority/normal stands.

  12. developing-today-fleet commented on Nov 30, 2026

    @developing-today-fleet
    Contributor

    🤖 P3.1 reparenting — Felix lane 0640-XW (plan: #17071). This issue was an open sub-issue under closed parent #1259. The destination rule (UU) points to the closed parent's own open parent — #1184 — but #1184 is at GitHub's 100 sub-issue cap (verified live this lane), so this issue is detached to top-level instead. GraphQL removeSubIssue, verified parent: null. No state, labels, or priority band changed.

  13. developing-today-fleet commented on Dec 1, 2026

    @developing-today-fleet
    Contributor

    Design/decision slice — lane 2037-G (alpha DRIVE 2026-11-30), discharging 0900-BL's wake. FULL claim-scan firsthand (body + all 60 comments): no live claim stands (0322-E released after PR #17128 merged; 0900-BL took no claim). 0900-BL's disposition named the next step exactly: a design/decision slice naming (a) the bindings + export route into the aggregator and (b) the completeness source for each census. This comment is that slice; the route below follows the repo's existing patterns and invents no new coupling.

    Decision: file-export route, producer-side exporters, aggregator-side ingestion

    Attribution's input contract is already fixed in code (pm-stack/aggregator/src/spend-attribution.ts): SpendAttributionInput { sourceStatus, sessions, bindings: SpendLaneBinding[], pool: ProjectPoolItem[], … }. The three inputs get to the aggregator the same way session usage already does — as versioned export files (the pm-stack/opencode-usage-export/ precedent: a small standalone exporter with service/timer on the host that owns the data):

    1. Sessions — the existing opencode usage export (already in production shape; no change).
    2. Bindings — a new queue-side bindings exporter, owned by the fleet queue (the system that holds session→task→issue bindings), emitting a versioned JSON export of SpendLaneBinding[] for a stated window. The aggregator never reads the queue database — the queue DB stays behind its owner's exporter, exactly as OpenCode session data stays behind the usage exporter.
    3. Pool — a pool export of ProjectPoolItem[] from the same queue-side exporter family (pool items are queue-owned data too).

    Ingestion (the bounded follow-on slice): an aggregator module that, on the existing tick cadence and behind an opt-in flag in the shape of PM_COST_ANOMALY_ENABLED (default off), reads the three exports from configured paths, runs spend-attribution → buildSpendRollups → SpendRollupStore.append (pm-stack/aggregator/src/spend-rollups.ts). That is the whole slice: three file readers, the already-written pure pipeline, one store append, tests for default-off / missing-export / happy path.

    Completeness sources (one per census; the issue's core rule governs)

    Every export carries a coverage block: window start/end + the producer's whole-window ok assertion. Missing, stale, or error exports map to sourceStatus != "ok" → attribution reconciled = null → anomalies suppress, never fabricate. No producer certifies beyond its coverage block.

    • Root-session census — derived from the usage export itself (sessions carry parentId; roots are enumerable from the same file). Completeness source: the usage export's coverage block.
    • Source-population census — the pool export's item set for the window. Completeness source: the pool export's coverage block.
    • Closure census — the aggregator's own GitHub issue reads over the window (it already reads GitHub for other boards). Completeness source: the read's window + pagination-exhausted marker; a truncated read is partial, not ok.
    • Service-activity census — the aggregator's existing charges collection (charges-collect/charges-match). Completeness source: the collection run's stated window and success/failure per source.

    What this unblocks

    Key: 2037-G

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/pm-stackeffort/mepic/pm-stackkind/featurepriority/normalsource/creatorstatus/waiting-dependencytask/triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions