Skip to content

aggregator: versioned item-history capture for forecasting (#3981 slice 1) - #5133

Merged
dezren39 merged 2 commits into
mainfrom
queue/8751-3981-item-history
Nov 3, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/8751-3981-item-history

Conversation

@dezren39

@dezren39 dezren39 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Slice 1 of #3981 (forecasting slice 1): the versioned item-history source the forecasting design (doc/2026-11-01T21-07-00Z_design_pm-stack_forecasting.md §1/§3/§5) names as its prerequisite — one reusable history seam for #1281 flow analytics and forecasting, not a second collector/store.

  • New module pm-stack/aggregator/src/item-history.ts:
    • ItemHistoryCutoff (schema v1): at each weekly cutoff, the observed item scope — ref/repo/number, GitHub state, Project Status (kept distinct from GitHub state), effort/*, parent/epic membership, sorted blocker edges — plus a coverage block (source, fetchedAt, complete, unavailable).
    • captureItemHistory(pool, coverage, cutoffAt): pure capture from the live ProjectPoolItem projection the aggregator already fetches; the coverage weekly anchor is the natural clock for whoever wires the writer.
    • ItemHistoryStore: append-only JSONL, one cutoff per line, deduped by cutoffAt, malformed lines skipped on read; file location via ITEM_HISTORY_FILE or the aggregator data dir. Ownership/retention documented in the module header (13-month raw retention per the snapshots.ts precedent).
    • Pure derivations: weeklyTransitions / weeklyCompletions (observed transitions between consecutive complete cutoffs only) and blockerFirstObserved (first-observed edge with a labelled lower-bound age — no fabricated exact event times).
  • Honesty rules from the acceptance criteria, enforced in the shape: an unavailable source is recorded as unavailable: true, complete: false and is excluded from derivations — distinct from a complete zero-completion week, which is preserved as a real 0. A reopened item leaves the completed count until it closes again.
  • Tests (test/item-history.test.ts, 7 tests, all passing locally with bun test): capture mapping incl. membership change, reopen cycle, zero-week preservation, missing-source exclusion, first-observed blocker lower bound, store round-trip/dedupe/bad-line resilience.

Not in this slice

Evidence

  • Local (laptop) run: bun test test/item-history.test.ts — 7 pass, 0 fail. Full typecheck runs in CI (a fresh worktree has no node_modules, so bunx tsc cannot resolve bun types locally).

Refs #3981 (slice 1; the issue stays open for the writer wiring).


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

@dezren39
dezren39 requested a review from a team as a code owner November 3, 2026 20:48
@coderabbitai

coderabbitai Bot commented Nov 3, 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 7 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: c07d7564-f603-4f03-a0c8-c7708bf12b60
Commits

Reviewing files that changed from the base of the PR and between 9310db4 and 8ea49db.

Files selected for processing: 2
  • pm-stack/aggregator/src/item-history.ts
  • pm-stack/aggregator/test/item-history.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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T21:28:09.838167Z 8ea49db New commits
ℹ️ 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.

@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: a06bc4ac47

ℹ️ 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".

Comment on lines +114 to +117
effort: effortOf(item.labels),
blockedBy: [...(item.blockedBy ?? [])].sort(),
};
if (item.parentRef) captured.parentRef = item.parentRef;

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 Preserve issue-versus-PR identity in captured history

When the project pool contains both issues and PRs, capture discards ProjectPoolItem.contentKind, and weeklyCompletions subsequently counts every open-to-closed/merged transition. An issue closure plus its merged PR therefore produces two completed units, while even an unmerged PR closure counts as delivery. The forecasting design’s §1 defines the unit as a native child issue and explicitly excludes PRs. Preserve the content kind in stored items and filter the forecasting completion series accordingly; otherwise readers cannot reliably recover the intended unit from this history.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 8ea49db: capture now stores kind from ProjectPoolItem.contentKind on every item (structural gate accepts "issue"/"pr", absent treated as issue for pre-kind lines), and weeklyTransitions skips PR items entirely — a merged or unmerged-closed PR is never a completed unit and an issue + its PR cannot double-count. New test: "PR transitions never count as completed units".

Comment thread pm-stack/aggregator/src/item-history.ts Outdated
Comment on lines +231 to +234
const complete = cutoffs.filter((c) => c.coverage.complete && !c.coverage.unavailable);
const weeks: WeeklyTransitions[] = [];
for (let i = 1; i < complete.length; i++) {
const before = new Map(complete[i - 1]!.items.map((item) => [item.ref, item.state]));

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 Exclude intervals that cross missing weekly observations

When a complete W1 cutoff is followed by an unavailable W2 cutoff and a complete W3 cutoff, filtering first makes W1 and W3 adjacent. Every closure observed across those two weeks is then returned as W3’s single weekly completion bucket. The existing missing-source test explicitly exercises this case. This does not merely exclude a missing week: it attributes potentially missing-week completions to a supposedly complete week, corrupting the weekly throughput distribution required by design §1. Keep the gap as an unknown interval and resume weekly buckets only when both bounding observations cover an uninterrupted week.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 8ea49db: weeklyTransitions now only forms a week from two consecutive stored cutoffs that are both complete. An incomplete cutoff breaks the chain; the next complete cutoff becomes a fresh baseline, so a closure spanning the gap is attributed to no week rather than to the next complete bucket. The missing-source test now asserts exactly this (gap closure uncounted; buckets resume at the first uninterrupted pair).

Comment thread pm-stack/aggregator/src/item-history.ts Outdated
Comment on lines +275 to +279
for (const cutoff of ordered) {
const item = cutoff.items.find((i) => i.ref === ref);
if (item && item.blockedBy.includes(blockerRef)) {
const last = ordered[ordered.length - 1]!;
const ageMs = Date.parse(last.cutoffAt) - Date.parse(cutoff.cutoffAt);

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 Reset blocker age after an observed edge removal

If an edge exists at W1, is absent at a complete W2 cutoff, and is added again at W3, this scan returns W1 and a 14-day lower-bound age for the newly added edge. That is not a lower bound on the current blocking episode and can incorrectly satisfy the design’s seven-day unresolved-blocker stall signal. Determine the first observation of the current episode, resetting it when a complete cutoff establishes that the edge was absent, rather than using the earliest occurrence across all history.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 8ea49db: blockerFirstObserved now ages the current episode — a complete cutoff that observes the item without the edge resets the episode start, so a re-added edge is first-observed at its re-observation, and an edge absent at the last complete cutoff returns null. New tests cover the reset (W1 present → W2 absent → W3 re-added: age runs from W3) and the removed-edge null case.

Three Codex findings on PR #5133, all fixed: (1) capture ProjectPoolItem.contentKind as ItemHistoryItem.kind and count only issue items as completed units — a merged/closed PR no longer counts, and an issue plus its PR cannot double-count; (2) weeklyTransitions only forms a week from two consecutive complete cutoffs — an incomplete cutoff breaks the chain, so transitions spanning a missing week are attributed to no week instead of the next complete bucket; (3) blockerFirstObserved ages the current episode — a complete cutoff observing the item without the edge resets the episode, and an edge gone at the last complete cutoff returns null. Tests: missing-source expectation corrected, new PR-units test, new episode-reset tests; bun test test/item-history.test.ts 10 pass.
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