Skip to content

Durable change-event journal for pull requests and epic queues #3483

Closed

Description

@integry

Problem

The only subscribable stream is Socket.IO fed by Redis pub/sub: fire-and-forget, no cursor, no replay, and MCP tokens cannot connect. The only durable journal with a cursor is goal_events. Pull request changes (opened, new head, review scored, Ultrafix ended, merged, closed) and epic queue changes (advanced, blocked, completed) are not published anywhere, so a coordinator has to poll many reads and diff them.

What to build

A durable, append-only journal in the database, written at the points where these changes are already persisted. This issue adds the table, the writer and the call sites only; the read/wait interface is the next issue.

Table repository_events

seq (INTEGER PRIMARY KEY AUTOINCREMENT, the cursor), repository (owner/repo), domain (pull_request | epic_queue | plan_issue), type, entity_id (PR number, epic execution id, or plan issue id as text), pr_number (nullable), issue_number (nullable), plan_id (nullable), head_sha (nullable), payload (JSON, small), dedupe_key (nullable, unique per repository), occurred_at. Indexes on (repository, seq) and (repository, domain, entity_id, seq).

Event types

  • pull_request: opened, head_changed, review_scored (payload: score, goal, goalReached, source, cycle, reviewerModel), ultrafix_started, ultrafix_ended (payload: outcome goal_reached|cycles_exhausted|stopped|failed, finalScore, reason), auto_merge_decision (payload: the existing autoMergeDecision metadata), merged, closed.
  • epic_queue: started, advanced (payload: from issue, to issue, cursor), blocked (payload: head issue, blockedReason), completed.
  • plan_issue: status_changed (payload: from, to).

Payloads carry identifiers and small scalars only: no PR bodies, comment text, diffs or log excerpts.

Writer

appendRepositoryEvent(db, event) in core. It must:

  • be idempotent through dedupe_key (for example pr:{n}:review_scored:{review_scores.id}, pr:{n}:merged, pr:{n}:head:{sha}), so webhook redelivery and retries do not duplicate events;
  • never throw into its caller: a failed append is logged and counted, and the underlying operation proceeds;
  • when the triggering change is itself a database write, append in the same transaction where that is practical.

Call sites (use the existing persistence points)

  • review score recorded: recordReviewScores (packages/core/src/services/reviewScoreStore.ts);
  • merged / closed: recordPullRequestOutcome (same file) and the notification_pull_request_state writer in notificationService.ts;
  • Ultrafix start and end: ultrafixOrchestrationService.ts (completeLoop, stopLoop), mapping the free-text completion reason to the coded outcome already defined in packages/api/mcp/commandProgress.ts (move the outcome type to shared/core rather than duplicating it);
  • auto-merge decision: recordAutoMergeDecisionEvent (packages/core/src/services/autoMergeGate.ts);
  • PR opened / head changed: the pull_request webhook handling for opened and synchronize;
  • epic queue: advanceEpicQueue and the blocked/complete transitions in packages/core/src/services/taskPlanning/epicExecutionQueue.ts;
  • plan issue status: packages/core/src/config/planIssueManager.ts where it already publishes the plan activity event.

If another change has already introduced an epic-queue blocked event or per-issue queue state (issues #3472, #3474), emit the journal event from that same code path instead of adding a parallel one.

Retention

Prune rows older than 30 days in the existing daemon maintenance sweep. Record the lowest retained seq so a reader can tell an expired cursor from an empty result.

Realtime

Add a pull_request domain to the activity envelope (packages/shared/src/activityEvents.ts) and publish a bare activity event after each append so the web UI can react. The journal, not pub/sub, is the source of truth.

Acceptance criteria

  • Migration creates the table and indexes; down migration drops them.
  • Each event type above is appended by a test that drives the real call site.
  • Replaying the same trigger twice yields one row.
  • A forced append failure does not fail the review-score write, the merge handling or the queue advance.
  • Events are ordered by seq and scoped by repository.
  • Retention prunes old rows and records the floor.
  • Architecture docs gain a short page describing the journal, the event types and payloads.

Implementation

  1. Migration + packages/core/src/services/repositoryEventJournal.ts (types, appendRepositoryEvent, listRepositoryEvents(db, {repository, afterSeq, domains?, entityId?, limit}), pruneRepositoryEvents). Export from the core index and put the shared event type definitions in packages/shared.
  2. Wire the call sites listed in the issue, each behind the non-throwing wrapper.
  3. Activity envelope: add the pull_request domain and publish after append.
  4. Daemon sweep: retention.
  5. Tests in packages/core/test/ for the journal (ordering, dedupe, failure isolation, pruning) and per call site next to the existing tests (reviewScorePersistence.test.ts, epicExecutionQueue.test.ts, ultrafixOrchestrationService.test.ts, autoMergeGate.test.ts).
  6. Docs page under docs/docs/architecture/.

Notes

goal_events (packages/core/src/db/migrations/20261004000000_create_goal_events.js) is the model for a cursor journal, but it uses SQLite triggers that must be recreated on table rebuilds. Use explicit application-level appends here, not triggers.

Activity

  1. propr-dev commented on Nov 12, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3483/claude-opus-5-5-durable-change-event-jour-20261112-1601-vhp
    • Base Branch: 3482-epic-integration-signals-100
    • Worktree: issue-3483-20261112-1601-claude-opus-5-5-vhp

    🔍 Track Task Execution

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions