Skip to content

feat(pm-stack): publish durable freshness invalidations - #5720

Merged
dezren39 merged 2 commits into
mainfrom
queue/8963-3977-freshness-invalidation-journal
Nov 5, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/8963-3977-freshness-invalidation-journal

Conversation

@dezren39

@dezren39 dezren39 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Summary

GitHub webhook ─┐
Kaneo acceptance ├─> source hooks ─> bounded v1 freshness journal/outbox ─> replay cursor
Fleet feed ─────┘   (after durable write)    (idempotent, retryable)

Evidence

  • bun test test/freshness.test.ts test/collect-fleet-feed-publication.test.ts — 14 pass, 0 fail.
  • bun test test/webhook-delivery-id.test.ts — 5 pass, 0 fail.
  • git diff --check origin/main — pass.
  • Existing package typecheck still has the previously recorded unrelated GhKind resolution error in unchanged src/item-history.ts; not rerun in this pass.

Merge Danger

Door: Two-way; the publisher/journal path can be disabled or rolled back without changing source-of-truth data.

Blast Radius: Medium — local PM-stack freshness signals and replay state; no external schedules or production routes are enabled here.


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 5, 2026 00:33
@coderabbitai

coderabbitai Bot commented Nov 5, 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 59 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: adfc1be6-0e37-4a5d-aa78-fd759590f0c8
Commits

Reviewing files that changed from the base of the PR and between cddb887 and b83c18b.

Files selected for processing: 13

  • nixos/services/pm-stack/default.nix
  • pm-stack/aggregator/scripts/collect-fleet-feed.ts
  • pm-stack/aggregator/src/config.ts
  • pm-stack/aggregator/src/freshness-ipc.ts
  • pm-stack/aggregator/src/freshness.ts
  • pm-stack/aggregator/src/server.ts
  • pm-stack/aggregator/src/sources/live.ts
  • pm-stack/aggregator/test/activity-live-3321.test.ts
  • pm-stack/aggregator/test/collect-fleet-feed-publication.test.ts
  • pm-stack/aggregator/test/freshness-ipc.test.ts
  • pm-stack/aggregator/test/freshness.test.ts
  • pm-stack/projector/src/server.ts
  • pm-stack/projector/test/webhook-delivery-id.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 5, 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-05T00:40:26.179350Z b83c18b 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.

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

ℹ️ 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 +162 to +166
// Append before recording this delivery as applied. If the
// aggregator is unavailable, GitHub's retry re-applies the
// projection and retries the same stable delivery id; an
// already-applied row must never hide a missing invalidation.
await publishFreshness(env, {

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 Persist failed GitHub invalidations for automatic retry

When the aggregator is unavailable, applyEvent() has already committed the projection, but this publication throws and the catch only records a delivery error; there is no durable pending invalidation or replay worker. The assumed upstream retry does not occur: GitHub documents that failed webhook deliveries are not automatically redelivered. Inspection of pm-stack, scripts, .github, and nixos found no redelivery automation. Consequently, even a brief aggregator restart can permanently lose these notices unless someone manually redelivers the webhooks. Persist the pending notice locally and retry it independently of GitHub.

Useful? React with 👍 / 👎.

}
try {
const result = await applyEvent(libsqlStore(db), event, payload, repos(env), deliveryId);
if (result.wrote && result.refs.length > 0) {

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 Publish invalidations for successful push deliveries

For a push webhook, applyEvent() writes the push record and commit hot-list entries, sets wrote = true, but returns an empty refs array (projector.ts:300–335). This guard therefore suppresses freshness publication for every push while the following code records the delivery as applied, so those changes never enter the freshness journal, including on redelivery. Publish a repository/ref-scoped notice for successful writes without item refs instead of requiring a nonempty item-ref list.

Useful? React with 👍 / 👎.

// is unavailable, the next poll retries; no raw card payload is
// persisted and only canonical data is reread by consumers.
await opts.onFreshness({
eventId: `kaneo:${digest}`,

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 Distinguish recurring Kaneo states from repeated polls

If the board returns to an earlier snapshot within the journal's retention window, this content-only ID matches the earlier notice and FreshnessStore.publish() returns it as a duplicate without advancing the cursor. For example, an empty board followed by a populated board and then another empty board loses the final invalidation, regardless of card timestamps; undated status cycles have the same problem. Consumers that processed the intervening state receive no notice to reread the board. Keep retries of the current accepted snapshot idempotent, but give a new transition back to previous content a new event identity.

Useful? React with 👍 / 👎.

Comment on lines +2243 to +2246
const freshnessIpcServer = Bun.serve({
hostname: "127.0.0.1",
port: cfg.freshnessPort,
fetch: createFreshnessIpcHandler(freshnessStore),

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 Isolate the publisher listener in real-server test instances

When the deployed aggregator already owns port 4871, starting another instance with an isolated PM_AGG_PORT now fails at this unconditional second bind. Existing real-server harnesses such as test/boot.test.ts and test/error-boundary-1211.test.ts override only PM_AGG_PORT, so they can no longer run alongside the service; separately launched test instances also contend for the same publisher port. Make the listener disableable for isolated instances or update the server harnesses to allocate independent freshness ports.

Useful? React with 👍 / 👎.

Comment on lines +966 to +968
const freshnessUrl = process.env.PM_AGG_FRESHNESS_URL ?? "http://127.0.0.1:4871/publish";
await publishFleetFeedWithInvalidation(outPath, JSON.stringify(feed, null, 2), feed.generatedAt, async (input) => {
const response = await fetch(freshnessUrl, {

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 standalone collection for the manual feed-push path

On the sandbox host, the retained manual/emergency scripts/push-fleet-feed.sh collects into a temporary file at line 78 before uploading it to the laptop, but this new default requires a publisher on the sandbox's own loopback address. Without that local aggregator, collection now exits unsuccessfully despite writing the file, and the wrapper's set -e stops the upload (Bash's help set describes -e as “Exit immediately if a command exits with a non-zero status”). Make notification optional for standalone collection and publish after the wrapper replaces the actual laptop feed, rather than requiring a local sink when producing a temporary artifact.

Useful? React with 👍 / 👎.

Comment on lines +269 to +271
entry = normalizeOutboxEntry(JSON.parse(line) as unknown);
} catch {
throw new Error("invalid freshness outbox; original file left untouched");

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 Recover interrupted outbox appends without blocking the journal

When a fallback outbox append is interrupted by a process crash or a partial disk-full write, the final JSONL record can be incomplete because appendOutbox() writes directly into the live log. This parser then rejects the entire outbox on restart, so load() blocks both publishing and replaying even previously fsynced, acknowledged entries after the underlying storage problem is resolved. Recover complete records while discarding or truncating only an incomplete, unacknowledged trailing record, or replace the outbox atomically.

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