@catalyst-cloud/schema 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catalyst-cloud/schema",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "description": "Typed Drizzle schema = single source of truth for the per-tenant Mirror DO SQLite store (CTC-13 / ADR-0002). Shared by the mirror Worker, the host-sync replica, and the browser OPFS replica.",
6
6
  "license": "MIT",
@@ -30,7 +30,7 @@
30
30
  "drizzle-orm": "0.44.7"
31
31
  },
32
32
  "devDependencies": {
33
- "@catalyst-cloud/typescript-config": "0.0.0",
33
+ "@catalyst-cloud/typescript-config": "workspace:*",
34
34
  "@types/node": "^25.9.3",
35
35
  "drizzle-kit": "^0.31.0",
36
36
  "prettier": "^3.8.4",
package/src/index.ts CHANGED
@@ -34,6 +34,7 @@ import {
34
34
  agent_activities,
35
35
  fleet_activity_pruned,
36
36
  pull_sweeps,
37
+ pr_review_backfill,
37
38
  } from "./mirror.js";
38
39
 
39
40
  export * from "./mirror.js";
@@ -86,6 +87,9 @@ export const mirrorSchema = {
86
87
  // migration bundle must produce) but DELIBERATELY ABSENT from `mirrorEntityTables` below — see the
87
88
  // no-feed arithmetic on the table definition in ./mirror.ts.
88
89
  pull_sweeps,
90
+ // CTC-575: the closed/merged-PR review-body backfill marker. Same posture as pull_sweeps — a real
91
+ // table, deliberately absent from mirrorEntityTables (see the doc on the table itself).
92
+ pr_review_backfill,
89
93
  // CTC-393: the fleet_activity anti-resurrection tombstone. Same posture as pull_sweeps — a real
90
94
  // table the DO creates, but pure internal bookkeeping that must NEVER ride the change-feed (a
91
95
  // consumer has no use for "a row was once terminal here"; see the doc on the table itself).
@@ -151,6 +151,13 @@ export const MIRROR_MIGRATIONS = {
151
151
  tag: "0019_mushy_sinister_six",
152
152
  breakpoints: true,
153
153
  },
154
+ {
155
+ idx: 20,
156
+ version: "6",
157
+ when: 1786856395245,
158
+ tag: "0020_wealthy_snowbird",
159
+ breakpoints: true,
160
+ },
154
161
  ],
155
162
  },
156
163
  migrations: {
@@ -192,5 +199,7 @@ export const MIRROR_MIGRATIONS = {
192
199
  "CREATE TABLE `agent_activities` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`session_id` text NOT NULL,\n\t`type` text,\n\t`body` text,\n\t`signal` text,\n\t`created_at` integer,\n\t`updated_at` integer,\n\t`raw` text\n);\n--> statement-breakpoint\nCREATE INDEX `idx_agent_activities_session_created` ON `agent_activities` (`session_id`,`created_at`);--> statement-breakpoint\nCREATE TABLE `agent_sessions` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`issue_id` text,\n\t`status` text,\n\t`app_user_id` text,\n\t`creator_id` text,\n\t`created_at` integer,\n\t`updated_at` integer,\n\t`removed_at` integer,\n\t`raw` text\n);\n--> statement-breakpoint\nCREATE INDEX `idx_agent_sessions_issue` ON `agent_sessions` (`issue_id`,`updated_at`);",
193
200
  "0019_mushy_sinister_six":
194
201
  "ALTER TABLE `agent_sessions` ADD `archived_at` integer;--> statement-breakpoint\nALTER TABLE `agent_sessions` ADD `dismissed_at` integer;--> statement-breakpoint\nALTER TABLE `agent_sessions` ADD `dismissed_by` text;",
202
+ "0020_wealthy_snowbird":
203
+ "CREATE TABLE `pr_review_backfill` (\n\t`repo_id` text NOT NULL,\n\t`pr_number` integer NOT NULL,\n\t`backfilled_at` integer NOT NULL,\n\tPRIMARY KEY(`repo_id`, `pr_number`)\n);\n--> statement-breakpoint\nALTER TABLE `reviews` ADD `body` text;",
195
204
  },
196
205
  } as const;
package/src/mirror.ts CHANGED
@@ -438,6 +438,12 @@ export const reviews = sqliteTable("reviews", {
438
438
  user_id: text("user_id"),
439
439
  state: text("state"),
440
440
  submitted_at: integer("submitted_at"),
441
+ // CTC-575: the review's text. GitHub always sends it; it was destructured away at the type boundary
442
+ // in three places (github/queries.ts, normalize/github.ts ×2) before this. ⛔ `reviews` has NO
443
+ // updated_at, so upsertRow's last-write-wins guard is inert here — the reconcile's hand-rolled
444
+ // read-before-emit (github-reconcile.ts) is the ONLY thing that decides whether an edited body
445
+ // re-emits a change_log delta, and it must compare `body` too or an edit never propagates.
446
+ body: text("body"),
441
447
  });
442
448
 
443
449
  // ── Mirror infra (not domain entities — never ride the change-feed) ─────────────────────────────────
@@ -621,3 +627,41 @@ export const pull_sweeps = sqliteTable(
621
627
  },
622
628
  (t) => [primaryKey({ columns: [t.repo_id, t.pr_number] })],
623
629
  );
630
+
631
+ /**
632
+ * CTC-575 — a marker that a CLOSED/MERGED PR's reviews have been swept AT LEAST ONCE for `body`.
633
+ *
634
+ * ⛔ WHY THIS EXISTS. `reconcileGithub`'s open-PR walk sweeps reviews only for PRs whose `state` is
635
+ * still `open` — a closed/merged PR's reviews are frozen at whatever the last webhook or open-PR sweep
636
+ * wrote, which for every review that predates this ticket is `body: null` (the column did not exist).
637
+ * Nothing else ever revisits a closed PR, so without a dedicated backfill leg every historical review
638
+ * body on every already-closed PR would stay null forever.
639
+ *
640
+ * ⛔ WHY A MARKER PER PR, NOT A SINGLE RESUME CURSOR. PR numbers are monotonic by CREATION order, not
641
+ * by CLOSE order — PR #5 can close well after PR #50 already did. A single "highest number backfilled"
642
+ * watermark (the `resumeEntity`/`mergeableEntity` pattern above) would permanently skip a low-numbered
643
+ * PR that closes late, once the watermark has already passed its number. A per-(repo_id, pr_number)
644
+ * marker is checked independently, so a PR is swept exactly once, whenever it happens to close.
645
+ *
646
+ * ⛔ DELIBERATELY NOT `pull_sweeps`. That table's three-state decode (no row / SHA-mismatch / count-or-
647
+ * error) is a documented invariant for the OPEN-PR CI-enrichment receipt (check_runs/commit_statuses),
648
+ * and this backfill sweeps reviews ONLY for a closed PR — writing a `pull_sweeps` row with
649
+ * check_run_count/commit_status_count left null and no *_error set would forge a fourth, undocumented
650
+ * state indistinguishable from "the checks fetch failed". A dedicated table keeps the two receipts'
651
+ * invariants independently true.
652
+ *
653
+ * ⛔ HUB-READ-ONLY, same posture as `pull_sweeps` / `fleet_activity_pruned`: never rides the change
654
+ * feed (absent from mirrorEntityTables / SNAPSHOT_TABLES / GITHUB_ENTITIES, no appendChange) — a
655
+ * consumer has no use for "we once swept this PR's reviews", and self-limiting at |closed PRs in the
656
+ * repo| (one row per PR, written once, never revisited).
657
+ */
658
+ export const pr_review_backfill = sqliteTable(
659
+ "pr_review_backfill",
660
+ {
661
+ repo_id: text("repo_id").notNull(),
662
+ pr_number: integer("pr_number").notNull(),
663
+ /** When the backfill swept this PR's reviews (ms). */
664
+ backfilled_at: integer("backfilled_at").notNull(),
665
+ },
666
+ (t) => [primaryKey({ columns: [t.repo_id, t.pr_number] })],
667
+ );