Skip to content

feat(pm-stack): outcome attribution projector over the GitHub hot list (#2072 slice 4) - #12709

Merged
dezren39 merged 1 commit into
mainfrom
felix/2072-outcome-attribution
Nov 22, 2026
Merged

dezren39 merged 1 commit into
mainfrom
felix/2072-outcome-attribution

Conversation

@dezren39

@dezren39 dezren39 commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Implements the first landable piece of the #10910 design spec (slice 4 of #2072, req 4 outcome attribution). Task 20799, which carried this piece, was blocked as a packet defect on 2026-11-18 (a small_fix packet against an effort/l scope); this PR lands the piece directly.

What it does

  • projectOutcomeAttribution — deterministic projector from normalized impl(observability): GitHub webhook ingestion + hot list (#2072 slice 2) #5204 hot-list rows (GithubHotEvent) to append-only outcome facts: issue created, PR created, comment/review submitted, description edited, commit pushed, and other for everything else the projector emits (nothing is silently dropped). Every fact keeps the original hot-list event_id and the canonical source link (reusing githubHotEventDelivery's validation and link derivation), so every aggregate drills back to its exact GitHub evidence.
  • Attribution discipline — job (queue task id; schedule/job id preserved separately), session (with root/parent), and provider/model identities attach only through caller-supplied authoritative bindings. Everything else is an explicit unattributed fact with reason no-binding. A model is never inferred from the GitHub actor.
  • Honest counts — per-commit push rows count exactly; the zero-commit fallback push row counts once with coverage: "partial" and surfaces in partialCoverage, never as an exact commit count. A missing/failed source produces a source-gap fact and totalByKind: null — unknown, not a zero-activity sweep. Malformed rows throw the activity contract's invalid_hot_event_* errors.
  • OutcomeFactStore — append-only JSONL ledger with stable fact-id dedupe (replay adds no count), a cursor persisted (tmp + rename) only after the batch is durably written and never advanced on a failed sweep, and an explicit outcome_fact_store_corrupt error on a corrupt line. rollupOutcomeFacts is the single counting path for live projections and ledger rebuilds, and counts only the current attribution version, so a re-projection supersedes rather than double-counts.

Evidence

  • Fail-before on pristine origin/main: the new suite errors with Cannot find module '../src/outcome-attribution.ts'.
  • Pass-after (sandbox): test/outcome-attribution.test.ts 8/8 (103 expects) — fixture rows map to expected fact ids/kinds/links and exact totals; duplicate replay adds no count; a bound event rolls up by job/model/session while the other 11 stay unattributed; missing source is distinguishable from an empty successful sweep.
  • Neighbours: spend-attribution + activity suites 66/66. Full aggregator suite 3179 pass / 4 fail — the known pre-existing environmental set, identical at pristine main (charges-feed-gate, curation-1497, deriveEpicEta under load, phase-mapping without planning/ materialized). tsc --noEmit: no errors in the touched files (only the known sparse-worktree grist/roadmap.json set). Biome-formatted; git diff --check clean.
  • No new dependencies.

Remainder on #10910 after this: live cadence wiring (a consumer on the aggregator's sweep next to GithubHotListConsumer, feeding real binding records) and the outcome/rollup view with drill-through.


Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

#2072 slice 4)

Implements the first landable piece of the #10910 design spec: a
versioned append-only outcome-fact contract and deterministic
projector for the supported #5204 hot-list event kinds.

- projectOutcomeAttribution maps normalized hot-list rows to outcome
  facts (issue/PR created, comment or review submitted, description
  edited, commit pushed, other) with the original event id and
  canonical source link on every fact, so each aggregate drills back
  to its exact GitHub evidence.
- Identities (queue task, schedule job, session/root/parent session,
  provider/model) attach only through caller-supplied authoritative
  bindings; everything else is explicitly unattributed with a reason.
  A model is never inferred from the GitHub actor.
- A push row that exposes no commit list counts once with partial
  coverage instead of inventing an exact commit count.
- A missing/failed source yields a source-gap fact and null totals:
  unknown, never a zero-activity sweep.
- OutcomeFactStore persists facts as append-only JSONL with fact-id
  dedupe (replay adds no count) and a cursor that advances only after
  the batch is durably written; rollupOutcomeFacts is the single
  counting path for projections and ledger rebuilds alike.
- Malformed hot-list rows throw the activity contract's
  invalid_hot_event_* errors instead of minting facts.

Tests: test/outcome-attribution.test.ts, 8 tests / 103 expects —
fixture rows map to expected fact ids/kinds/links and exact totals;
duplicate replay adds no count; missing source is distinguishable
from an empty successful sweep. Full aggregator suite: 3179 pass,
4 fail (the known pre-existing environmental set, identical at
pristine main: charges-feed-gate, curation-1497, deriveEpicEta under
load, phase-mapping without planning/ materialized).

No new dependencies. Live cadence wiring (a consumer on the
aggregator's sweep, next to GithubHotListConsumer) and the outcome
view are the follow-on pieces on #10910.
@dezren39
dezren39 requested a review from a team as a code owner November 22, 2026 23:27
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 9 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 27b531c7-d557-4a58-b229-5a645d0a47dd
Commits

Reviewing files that changed from the base of the PR and between 1402855 and beaa3cd.

Files selected for processing: 2

  • pm-stack/aggregator/src/outcome-attribution.ts
  • pm-stack/aggregator/test/outcome-attribution.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T23:31:53.882548Z beaa3cd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit ed19070 into main Nov 22, 2026
2 checks passed
@dezren39
dezren39 deleted the felix/2072-outcome-attribution branch November 22, 2026 23:28

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: beaa3cd7b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const perCommit = event.event_id.split(":").includes("commit");
return perCommit
? { outcomeKind: "commit-pushed", subjectKind: "commit", coverage: "complete" }
: { outcomeKind: "commit-pushed", subjectKind: "push", coverage: "partial" };

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 Avoid counting empty pushes as committed work

For branch/tag deletions and other pushes with an empty commit list, this fallback adds one commit-pushed outcome even though no commits were pushed. In pm-stack/projector/src/projector.ts:400-407, the producer emits a push:<after> row whenever commits.length === 0, not only when commit information is unavailable. Marking the count as partial does not satisfy the documented lower-bound contract: one is not a lower bound on zero. Preserve these rows as push/other outcomes or represent their commit quantity as unknown rather than incrementing the commit count.

Useful? React with 👍 / 👎.

Comment on lines +383 to +385
const projection = projectOutcomeAttribution(input);
const existing = new Set((await this.readFacts()).map((fact) => fact.factId));
const fresh = projection.facts.filter((fact) => !existing.has(fact.factId));

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 replay projections consistent with persisted attribution

If an event is first persisted without a binding and then replayed with an authoritative binding, the new projection contains attributed byJob/byModel/bySession counts, but the fact-ID dedupe discards that updated fact. applySweep() therefore reports attribution that cannot be rebuilt from its ledger, which still contains the original unattributed fact. The immutable-by-version policy can remain intact, but existing IDs need to resolve to their stored attribution or explicitly require a correction/version change instead of returning an unpersisted projection.

Useful? React with 👍 / 👎.

Comment on lines +384 to +389
const existing = new Set((await this.readFacts()).map((fact) => fact.factId));
const fresh = projection.facts.filter((fact) => !existing.has(fact.factId));
const cursor = await this.cursor();
if (fresh.length > 0) {
await mkdir(dirname(this.file), { recursive: true });
await appendFile(this.file, fresh.map((fact) => `${JSON.stringify(fact)}\n`).join(""), "utf8");

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 Serialize the complete sweep persistence operation

When two applySweep() calls overlap on the same store, both can read the ledger before either appends and classify the same fact as fresh. Both then append it, and rollupOutcomeFacts() counts both copies, permanently inflating reconstructed totals. Overlapping checkpoint writes also share the same .state.json.tmp path, so they can interfere or fail during rename. Serialize the entire read/dedupe/append/checkpoint operation, as the sibling IngestionStore.ingest() does in activity.ts:619-631; serializing only individual writes would leave the duplicate-count race intact.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant