@sentry/junior 0.310.0 → 0.312.0

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.
Files changed (157) hide show
  1. package/dist/{adapter-context-BhKpjpGD.js → adapter-context-BRjEWRy1.js} +2 -2
  2. package/dist/adapter-iIq7ihf7.js +259 -0
  3. package/dist/{admin-tgZEZAk2.js → admin-DhInw5K9.js} +1 -2
  4. package/dist/{agent-runner-D9cvNlQl.js → agent-runner-C9iDurwX.js} +6507 -7721
  5. package/dist/api/schema.d.ts +2 -2
  6. package/dist/api/schema.js +7 -6
  7. package/dist/api.d.ts +21 -3
  8. package/dist/api.js +1625 -535
  9. package/dist/{app-B_7Wn0en.d.ts → app-DRFrC8Mw.d.ts} +14 -10
  10. package/dist/app.d.ts +2 -2
  11. package/dist/app.js +454 -994
  12. package/dist/{background-compaction-queue-BGHqkhkY.js → background-compaction-queue-DrKi7w3d.js} +10 -85
  13. package/dist/callback-mFlTUWWx.js +75 -0
  14. package/dist/{catalog-runtime-BxwzbLKY.js → catalog-runtime-D7xapBAX.js} +1 -1
  15. package/dist/channel-access-CJGfNTdn.js +221 -0
  16. package/dist/child-message-DcsritGf.js +179 -0
  17. package/dist/cli/chat.js +18 -19
  18. package/dist/cli/check.js +23 -29
  19. package/dist/cli/init.js +1 -7
  20. package/dist/cli/main.js +3 -7
  21. package/dist/cli/plugins.js +8 -7
  22. package/dist/cli/run.d.ts +1 -2
  23. package/dist/cli/run.js +1 -2
  24. package/dist/cli/snapshot-create.js +5 -5
  25. package/dist/cli/upgrade.d.ts +1 -1
  26. package/dist/cli/upgrade.js +3 -3
  27. package/dist/{config-Dkt2Le2b.js → config-kXB2Y5tl.js} +294 -28
  28. package/dist/{continue-in-slack-BWVwePKD.js → continue-in-slack-O6pV5004.js} +7 -7
  29. package/dist/{conversation-feed-Ci6YD1N-.js → conversation-feed-uNOv_x68.js} +87 -24
  30. package/dist/{conversation-privacy-C39g8BY4.js → conversation-privacy-L4ja1_W6.js} +1 -1
  31. package/dist/{conversation-turn-CBlZIH02.js → conversation-turn-CeLbHqdw.js} +56 -49
  32. package/dist/{credential-sync-vGnrB0BY.js → credential-sync-I8VBGk05.js} +16 -16
  33. package/dist/{projection-jZSlEAXG.js → credentialed-Cb6E2phL.js} +16268 -16821
  34. package/dist/{db-B4Hjxr-u.d.ts → db-BbC5stfa.d.ts} +13 -6
  35. package/dist/{db-CFZggNoy.js → db-LAyyX8tk.js} +1698 -1046
  36. package/dist/{executor-BPkZDx5-.js → executor-SCub-fAq.js} +552 -181
  37. package/dist/{html-2r2KmLwi.js → html-BCZ3Xtb_.js} +6 -6
  38. package/dist/{session-stop-BfY4rhJs.js → ingest-BDf3D50j.js} +2134 -2553
  39. package/dist/{install-C-oE6C_u.js → install-DCFJFkC0.js} +2 -2
  40. package/dist/instrumentation.js +4 -4
  41. package/dist/{lineage-CsvrEFQe.js → lineage-B_m-4TJw.js} +2 -2
  42. package/dist/{stop-DYzjRf2U.js → list-CN2QA2R9.js} +1656 -685
  43. package/dist/{logging-D5gkyvnK.js → logging-dQ9ZRGQ8.js} +47 -9
  44. package/dist/media-CYm1QD8T.js +2356 -0
  45. package/dist/{message-DwvJ-I3w.js → message-DSXGj1hM.js} +19 -29
  46. package/dist/{model-input-MAq2881y.js → model-input--TrP9hYV.js} +3 -3
  47. package/dist/nitro.d.ts +1 -1
  48. package/dist/nitro.js +4 -3
  49. package/dist/{oauth-callback-server-DIF6Li06.js → oauth-callback-server-DHCZC6B4.js} +2 -2
  50. package/dist/{oauth-relay-DPE-wrwO.js → oauth-relay-pPMGnDZt.js} +1 -1
  51. package/dist/{registry-BBkWFCl8.js → registry-CZOzddwu.js} +5 -8
  52. package/dist/{resolve-B38MkHXE.js → resolve-cKOQ14Dh.js} +3 -3
  53. package/dist/{result-BaqSZcJb.js → result-DcvEOe1r.js} +119 -93
  54. package/dist/result-event-type-BdIJuZxg.js +48 -0
  55. package/dist/rule-DAxQY-1h.js +20 -0
  56. package/dist/{runner-11h8PrHh.js → runner-DBfUW44l.js} +14 -16
  57. package/dist/{sandbox-egress-signals-CTcACAtJ.js → sandbox-egress-signals-BVF_xAm1.js} +1 -1
  58. package/dist/{schema-DriSvB40.d.ts → schema-BEHKxr4I.d.ts} +861 -298
  59. package/dist/{schema-obw5jvR4.js → schema-Bk9Nm2E8.js} +344 -153
  60. package/dist/{service-account-Bx93N1n1.js → service-account-CVYsFjty.js} +3 -3
  61. package/dist/{service-account-Zc5bUcIJ.js → service-account-Ts4ulcrV.js} +68 -68
  62. package/dist/{skills-C8Npu5zO.js → skills-VTnhAJWm.js} +2 -2
  63. package/dist/{slack-conversation-unfurl-DlRVA02H.js → slack-conversation-unfurl-fuLnF1jE.js} +9 -11
  64. package/dist/{spawn-CXr58R0x.js → spawn-vxAarlX5.js} +6 -6
  65. package/dist/start-conversation-CEn2KH1A.js +941 -0
  66. package/dist/{state-CGrGVeQC.js → state-C1P3_Ywk.js} +4 -4
  67. package/dist/statuses-_cRJHXK7.js +150 -0
  68. package/dist/store-DFZaN-Ix.js +492 -0
  69. package/dist/task-queue-Cx4Lmjyk.js +90 -0
  70. package/dist/task-runner-CbTwFA6k.js +1432 -0
  71. package/dist/{thread-context-Dyj1KWaY.js → thread-context-BkAZDTX2.js} +13 -11
  72. package/dist/thread-state-DhPndWi1.js +5625 -0
  73. package/dist/{validation-DxVNIxA0.js → validation-nIzMtAVJ.js} +1 -1
  74. package/dist/{task-queue-CaZffYaH.js → vercel-queue-hW90XzbG.js} +93 -172
  75. package/dist/{version-Cr7Z71yG.js → version-Brbtz4Qf.js} +1 -1
  76. package/dist/version.js +1 -1
  77. package/dist/{warmup-C6LOZ2d2.js → warmup-BDA5myRK.js} +5832 -4567
  78. package/dist/web-message-id-C6P83ans.js +10 -0
  79. package/dist/{worker-CUBtu1Li.js → worker-D63RcaVD.js} +20 -8
  80. package/migrations/0126_artifact_drop_public.sql +8 -0
  81. package/migrations/0127_artifact_path.sql +4 -0
  82. package/migrations/0128_artifact_path_index.sql +1 -0
  83. package/migrations/0129_review_item_answered_index.sql +1 -0
  84. package/migrations/0130_review_item_status_index.sql +1 -0
  85. package/migrations/0131_brief_outcome_status.sql +1 -0
  86. package/migrations/0132_brief_outcome_status_backfill.sql +7 -0
  87. package/migrations/0133_brief_created_at_index.sql +1 -0
  88. package/migrations/0134_slack_person_search_index.sql +1 -0
  89. package/migrations/0135_code_change_size.sql +3 -0
  90. package/migrations/0136_merge_conflict_notice_dismiss.sql +16 -0
  91. package/migrations/0137_inbox_snoozes.sql +27 -0
  92. package/migrations/0138_code_change_search_index.sql +2 -0
  93. package/migrations/0139_review_item_owner.sql +22 -0
  94. package/migrations/0140_review_item_owner_index.sql +1 -0
  95. package/migrations/0141_memory_core_adoption.sql +89 -0
  96. package/migrations/0142_memory_core_indexes.sql +17 -0
  97. package/migrations/0143_todos.sql +14 -0
  98. package/migrations/0144_inbox_items.sql +32 -0
  99. package/migrations/0145_todo_changed_by_agent.sql +1 -0
  100. package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
  101. package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
  102. package/migrations/0148_authorization_request_index.sql +1 -0
  103. package/migrations/0149_conversation_metadata.sql +10 -0
  104. package/migrations/0150_conversation_metadata_fill.sql +39 -0
  105. package/migrations/0151_conversation_search_index.sql +1 -0
  106. package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
  107. package/migrations/0153_artifact_expiry.sql +1 -0
  108. package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
  109. package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
  110. package/migrations/0156_conversation_kind_lead.sql +6 -0
  111. package/migrations/0157_conversation_lead_actor_index.sql +1 -0
  112. package/migrations/meta/0126_snapshot.json +5488 -0
  113. package/migrations/meta/0127_snapshot.json +5519 -0
  114. package/migrations/meta/0128_snapshot.json +5519 -0
  115. package/migrations/meta/0129_snapshot.json +5547 -0
  116. package/migrations/meta/0130_snapshot.json +5563 -0
  117. package/migrations/meta/0131_snapshot.json +5569 -0
  118. package/migrations/meta/0132_snapshot.json +5569 -0
  119. package/migrations/meta/0133_snapshot.json +5590 -0
  120. package/migrations/meta/0134_snapshot.json +5606 -0
  121. package/migrations/meta/0135_snapshot.json +5624 -0
  122. package/migrations/meta/0136_snapshot.json +5624 -0
  123. package/migrations/meta/0137_snapshot.json +5864 -0
  124. package/migrations/meta/0138_snapshot.json +5894 -0
  125. package/migrations/meta/0139_snapshot.json +5898 -0
  126. package/migrations/meta/0140_snapshot.json +5919 -0
  127. package/migrations/meta/0141_snapshot.json +6429 -0
  128. package/migrations/meta/0142_snapshot.json +6457 -0
  129. package/migrations/meta/0143_snapshot.json +6434 -0
  130. package/migrations/meta/0144_snapshot.json +6434 -0
  131. package/migrations/meta/0145_snapshot.json +6440 -0
  132. package/migrations/meta/0146_snapshot.json +6446 -0
  133. package/migrations/meta/0147_snapshot.json +6452 -0
  134. package/migrations/meta/0148_snapshot.json +6474 -0
  135. package/migrations/meta/0149_snapshot.json +6490 -0
  136. package/migrations/meta/0150_snapshot.json +6490 -0
  137. package/migrations/meta/0151_snapshot.json +6505 -0
  138. package/migrations/meta/0152_snapshot.json +6505 -0
  139. package/migrations/meta/0153_snapshot.json +6511 -0
  140. package/migrations/meta/0154_snapshot.json +6533 -0
  141. package/migrations/meta/0155_snapshot.json +6511 -0
  142. package/migrations/meta/0156_snapshot.json +6511 -0
  143. package/migrations/meta/0157_snapshot.json +6527 -0
  144. package/migrations/meta/_journal.json +224 -0
  145. package/package.json +7 -8
  146. package/skills/design-automation-skill/SKILL.md +108 -0
  147. package/dist/briefs-DKxkoruh.js +0 -395
  148. package/dist/conversation-M9KZ5JxF.js +0 -1024
  149. package/dist/prompt-CaMyeCpA.js +0 -910
  150. package/dist/schedule-DWxZ3kja.js +0 -1146
  151. package/dist/store-D4FQ1Nml.js +0 -335
  152. package/dist/task-runner-Dm7BHbGp.js +0 -287
  153. package/dist/turn-session-routing-CD0BRCex.js +0 -263
  154. package/dist/turn-user-message-9IxeEv5v.js +0 -364
  155. package/dist/users-CaUAYMb3.js +0 -181
  156. package/dist/viewer-AHldghAD.js +0 -212
  157. package/dist/web-message-id-BT8Mg8LL.js +0 -418
@@ -0,0 +1,10 @@
1
+ // src/chat/conversations/web-message-id.ts
2
+ /**
3
+ * Build the retry-stable Message id shared by web ingress and browser sends.
4
+ * Keep the existing hash and prefix so retries still address stored Messages.
5
+ */
6
+ async function webMessageId(args) {
7
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${args.conversationId}\u0000${args.idempotencyKey}`));
8
+ return `api-msg:${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 24)}`;
9
+ }
10
+ export { webMessageId as t };
@@ -1,12 +1,10 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { Ct as countPendingConversationMessages, Nt as isFinalAttempt, Pt as isInvalidConversationRecordError, jt as hasConversationStop } from "./projection-jZSlEAXG.js";
3
- import { i as getChatConfig, nt as isProviderRetryError } from "./config-Dkt2Le2b.js";
4
- import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging-D5gkyvnK.js";
5
- import { t as getConversationStoppedAtMs } from "./session-stop-BfY4rhJs.js";
6
- import { g as getTurnRequestDeadline } from "./task-queue-CaZffYaH.js";
7
- import { _ as ConversationQueueMessageRejectedError, b as nudgeIdempotencyKey } from "./background-compaction-queue-BGHqkhkY.js";
8
- import { C as requestAnotherSlice, S as releaseConversationWork, T as startConversationWork, _ as getConversationWorkState, b as recordAttemptFailure, c as clearConsumedConversationWake, d as completeConversationWork, f as deadLetterAttempt, h as ensureConversationWake, i as beginConversationResume, o as checkInConversationWork, p as drainConversationMailbox, t as ackMessages, u as completeConversationStop, x as recordConversationRetry } from "./store-D4FQ1Nml.js";
9
- import { Ln as isAttemptInterrupt, Rn as selectAttemptMessages } from "./warmup-C6LOZ2d2.js";
2
+ import { ft as isProviderRetryError, r as getChatConfig } from "./config-kXB2Y5tl.js";
3
+ import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging-dQ9ZRGQ8.js";
4
+ import { A as saveHeldInput, D as getConversationStoppedAtMs } from "./ingest-BDf3D50j.js";
5
+ import { n as getTurnRequestDeadline } from "./callback-mFlTUWWx.js";
6
+ import { i as ConversationQueueMessageRejectedError, s as nudgeIdempotencyKey } from "./vercel-queue-hW90XzbG.js";
7
+ import { A as requestAnotherSlice, D as recordAttemptFailure, M as startConversationWork, O as recordConversationRetry, S as ensureConversationWake, _ as completeConversationStop, an as isInvalidConversationRecordError, b as drainConversationMailbox, en as countPendingConversationMessages, f as checkInConversationWork, h as clearConsumedConversationWake, in as isFinalAttempt, k as releaseConversationWork, mn as selectAttemptMessages, nn as hasConversationStop, p as claimConversationAttempt, pn as isAttemptInterrupt, s as ackMessages, u as beginConversationResume, v as completeConversationWork, w as getConversationWorkState, y as deadLetterAttempt } from "./thread-state-DhPndWi1.js";
10
8
  // src/chat/task-execution/lost-lease.ts
11
9
  /**
12
10
  * Count a slice that lost its Conversation Lease as a failed attempt, then
@@ -367,6 +365,20 @@ async function processConversationWorkInContext(message, options) {
367
365
  }
368
366
  }
369
367
  attemptMessageIds = attemptMessages.map((message) => message.inboundMessageId);
368
+ if (attemptMessageIds.length > 0) {
369
+ const claim = await claimConversationAttempt({
370
+ conversationId,
371
+ inboundMessageIds: attemptMessageIds,
372
+ leaseToken: lease.leaseToken,
373
+ nowMs: now(options),
374
+ state: options.state
375
+ });
376
+ if (claim.status === "held") {
377
+ await saveHeldInput(conversationId, claim.messages);
378
+ if (claim.pendingCount === 0 && !resumePending) break;
379
+ }
380
+ if (claim.status !== "claimed") continue;
381
+ }
370
382
  attemptSelectedMessageIds = new Set(attemptMessageIds);
371
383
  const ack = async () => {
372
384
  if (!await ackMessages({
@@ -0,0 +1,8 @@
1
+ -- 0124 and 0125 (Junior 0.310.0) moved every reader and writer to
2
+ -- `visibility` and the public-row index. This drops what only older runtimes
3
+ -- used. A host that upgrades from before 0.310.0 straight past this release
4
+ -- fails image publishes and public artifact reads until the new runtime serves.
5
+ DROP INDEX "junior_artifacts_conversation_sha_uidx";--> statement-breakpoint
6
+ -- A write that omits `visibility` gets the narrowest audience, never public.
7
+ ALTER TABLE "junior_artifacts" ALTER COLUMN "visibility" SET DEFAULT 'conversation';--> statement-breakpoint
8
+ ALTER TABLE "junior_artifacts" DROP COLUMN "public";
@@ -0,0 +1,4 @@
1
+ ALTER TABLE "junior_artifacts" ADD COLUMN "path" text;--> statement-breakpoint
2
+ -- Every existing row is a public frozen copy with no path. NOT VALID skips
3
+ -- the scan under lock and still checks every new write.
4
+ ALTER TABLE "junior_artifacts" ADD CONSTRAINT "junior_artifacts_path_visibility_check" CHECK (("junior_artifacts"."path" is null) = ("junior_artifacts"."visibility" = 'public')) NOT VALID;
@@ -0,0 +1 @@
1
+ CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "junior_artifacts_conversation_path_uidx" ON "junior_artifacts" USING btree ("conversation_id","path");
@@ -0,0 +1 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_review_items_answered_idx" ON "junior_review_items" USING btree ("added_by_conversation_id","closed_by_user_id","closed_at") WHERE "junior_review_items"."answer" is not null;
@@ -0,0 +1 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_review_items_open_action_added_by_idx" ON "junior_review_items" USING btree ("added_by_conversation_id") WHERE "junior_review_items"."status" = 'open' and "junior_review_items"."kind" = 'action';
@@ -0,0 +1 @@
1
+ ALTER TABLE "junior_conversation_briefs" ADD COLUMN "outcome_status" text;
@@ -0,0 +1,7 @@
1
+ -- Rows that the runtime before this release writes during the rollout keep a
2
+ -- null status, and readers fall back to the content. This runs in its own
3
+ -- transaction, after the one that adds the column, so it holds no table lock
4
+ -- that blocks Brief reads or new Brief versions.
5
+ -- junior:bounded-backfill: Brief versions are append-only, so no app write changes these rows; only a cascade delete of a Conversation waits.
6
+ UPDATE "junior_conversation_briefs"
7
+ SET "outcome_status" = "content"->'outcome'->>'status';
@@ -0,0 +1 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_briefs_created_at_idx" ON "junior_conversation_briefs" USING btree ("created_at","conversation_id");
@@ -0,0 +1 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_identities_slack_person_search_idx" ON "junior_identities" USING gin (to_tsvector('simple', coalesce("display_name", '') || ' ' || coalesce("handle", ''))) WHERE "junior_identities"."provider" = 'slack' AND "junior_identities"."kind" = 'user';
@@ -0,0 +1,3 @@
1
+ ALTER TABLE "junior_code_changes" ADD COLUMN "additions" integer;--> statement-breakpoint
2
+ ALTER TABLE "junior_code_changes" ADD COLUMN "changed_files" integer;--> statement-breakpoint
3
+ ALTER TABLE "junior_code_changes" ADD COLUMN "deletions" integer;
@@ -0,0 +1,16 @@
1
+ -- The GitHub plugin now asks to resume merge conflict fixes with an action
2
+ -- item that has a Resume button. The old notices have no button, so this
3
+ -- dismisses the ones that are still open. The next check of a pull request
4
+ -- that is still stopped adds the new item. Like a dismiss when no agent can
5
+ -- act, it sends no message and does not change the Slack cards. A click on
6
+ -- an old card finds the item closed and updates the card.
7
+ -- junior:bounded-backfill: only open GitHub merge conflict notices, at most one per open Junior pull request, among open items, which the status index finds.
8
+ UPDATE "junior_review_items"
9
+ SET
10
+ "status" = 'dismissed',
11
+ "closed_at" = now(),
12
+ "close_reason" = 'Replaced by an item with a Resume button.',
13
+ "updated_at" = now()
14
+ WHERE "status" = 'open'
15
+ AND "kind" = 'notice'
16
+ AND "dedupe_key" LIKE 'plugin:github:merge-conflict:%';
@@ -0,0 +1,27 @@
1
+ CREATE TABLE "junior_inbox_snooze_triggers" (
2
+ "snooze_id" text NOT NULL,
3
+ "outcome" text NOT NULL,
4
+ "namespace" text NOT NULL,
5
+ "identifier" text NOT NULL,
6
+ "event_type" text NOT NULL,
7
+ "match" jsonb,
8
+ CONSTRAINT "junior_inbox_snooze_triggers_outcome_check" CHECK ("junior_inbox_snooze_triggers"."outcome" in ('wake', 'resolve'))
9
+ );
10
+ --> statement-breakpoint
11
+ CREATE TABLE "junior_inbox_snoozes" (
12
+ "id" text PRIMARY KEY NOT NULL,
13
+ "user_id" text NOT NULL,
14
+ "review_item_id" text NOT NULL,
15
+ "state" text NOT NULL,
16
+ "created_at" timestamp with time zone NOT NULL,
17
+ CONSTRAINT "junior_inbox_snoozes_state_check" CHECK ("junior_inbox_snoozes"."state" in ('snoozed', 'woken', 'cancelled'))
18
+ );
19
+ --> statement-breakpoint
20
+ ALTER TABLE "junior_inbox_snooze_triggers" ADD CONSTRAINT "junior_inbox_snooze_triggers_snooze_id_junior_inbox_snoozes_id_fk" FOREIGN KEY ("snooze_id") REFERENCES "public"."junior_inbox_snoozes"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
21
+ ALTER TABLE "junior_inbox_snoozes" ADD CONSTRAINT "junior_inbox_snoozes_user_id_junior_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."junior_users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
22
+ ALTER TABLE "junior_inbox_snoozes" ADD CONSTRAINT "junior_inbox_snoozes_review_item_id_junior_review_items_id_fk" FOREIGN KEY ("review_item_id") REFERENCES "public"."junior_review_items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
23
+ CREATE INDEX "junior_inbox_snooze_triggers_event_idx" ON "junior_inbox_snooze_triggers" USING btree ("namespace","identifier","event_type");--> statement-breakpoint
24
+ CREATE INDEX "junior_inbox_snooze_triggers_snooze_idx" ON "junior_inbox_snooze_triggers" USING btree ("snooze_id");--> statement-breakpoint
25
+ CREATE UNIQUE INDEX "junior_inbox_snoozes_snoozed_uidx" ON "junior_inbox_snoozes" USING btree ("user_id","review_item_id") WHERE "junior_inbox_snoozes"."state" = 'snoozed';--> statement-breakpoint
26
+ CREATE INDEX "junior_inbox_snoozes_settled_idx" ON "junior_inbox_snoozes" USING btree ("created_at") WHERE "junior_inbox_snoozes"."state" <> 'snoozed';--> statement-breakpoint
27
+ CREATE INDEX "junior_inbox_snoozes_review_item_idx" ON "junior_inbox_snoozes" USING btree ("review_item_id");
@@ -0,0 +1,2 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_code_changes_search_idx" ON "junior_code_changes" USING gin (to_tsvector('simple', "number"::text || ' ' || coalesce("title", '')));--> statement-breakpoint
2
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_code_repositories_search_idx" ON "junior_code_repositories" USING gin (to_tsvector('simple', translate("name", '/', ' ')));
@@ -0,0 +1,22 @@
1
+ -- A Review item now names its owner: a Conversation, as before, or an
2
+ -- Automation for an Automation alert. Every existing item belongs to the
3
+ -- Conversation that added it, so the old column becomes the owner id, and
4
+ -- the default of the new kind column fills existing rows with
5
+ -- 'conversation'. A constant default writes no row. The owner id has no
6
+ -- foreign key, because it can name more than one table. Conversations are
7
+ -- never deleted, so no cascade is lost. An older runtime cannot write
8
+ -- Review items once this runs, until the new runtime serves.
9
+ ALTER TABLE "junior_review_items" RENAME COLUMN "added_by_conversation_id" TO "owner_id";--> statement-breakpoint
10
+ ALTER TABLE "junior_review_items" DROP CONSTRAINT "junior_review_items_added_by_conversation_id_junior_conversations_conversation_id_fk";--> statement-breakpoint
11
+ ALTER TABLE "junior_review_items" ADD COLUMN "owner_kind" text DEFAULT 'conversation' NOT NULL;--> statement-breakpoint
12
+ -- The index keeps its definition on the renamed column.
13
+ ALTER INDEX "junior_review_items_open_action_added_by_idx" RENAME TO "junior_review_items_open_action_owner_idx";--> statement-breakpoint
14
+ ALTER TABLE "junior_review_items" DROP CONSTRAINT "junior_review_items_kind_check";--> statement-breakpoint
15
+ -- Both checks hold for every existing row: each is a Conversation item, and
16
+ -- agents and plugins use no `automation:` key. NOT VALID skips the scan
17
+ -- under lock and still checks every new write.
18
+ ALTER TABLE "junior_review_items" ADD CONSTRAINT "junior_review_items_owner_check" CHECK (("junior_review_items"."owner_kind" = 'conversation' and "junior_review_items"."dedupe_key" not like 'automation:%') or ("junior_review_items"."owner_kind" = 'automation' and "junior_review_items"."dedupe_key" like 'automation:%')) NOT VALID;--> statement-breakpoint
19
+ ALTER TABLE "junior_review_items" ADD CONSTRAINT "junior_review_items_kind_check" CHECK (("junior_review_items"."kind" = 'notice' and "junior_review_items"."request" is null and "junior_review_items"."answer" is null) or ("junior_review_items"."kind" = 'action' and ("junior_review_items"."request" is not null or (("junior_review_items"."dedupe_key" like 'plugin:%' or "junior_review_items"."dedupe_key" like 'automation:%') and "junior_review_items"."answer" is null)))) NOT VALID;--> statement-breakpoint
20
+ -- A person's dismiss hides an Automation's alerts until core sees it
21
+ -- recover. Existing Automations have no dismissed alert, so null is right.
22
+ ALTER TABLE "junior_automations" ADD COLUMN "alert_recovered_at_ms" bigint;
@@ -0,0 +1 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_review_items_owner_idx" ON "junior_review_items" USING btree ("owner_kind","owner_id");
@@ -0,0 +1,89 @@
1
+ -- Memory moved from the @sentry/junior-memory plugin into core. A database
2
+ -- that ran the plugin already has these tables. This migration keeps their
3
+ -- data and the plugin journal unchanged, and adds only the schema of plugin
4
+ -- migrations 0015 and 0016, which change no data. A fresh database gets the
5
+ -- final Memory schema. Columns keep the order that the plugin migrations made.
6
+ -- Stop on a database that did not run the plugin migrations through 0014, the
7
+ -- last one that changes data, so that those changes never run out of order.
8
+ -- The journal query is dynamic because PL/pgSQL plans a static query before
9
+ -- the to_regclass check runs.
10
+ DO $$
11
+ DECLARE
12
+ plugin_complete boolean;
13
+ BEGIN
14
+ IF to_regclass('drizzle.__drizzle_memory_c064fbca') IS NULL THEN
15
+ RETURN;
16
+ END IF;
17
+ EXECUTE 'SELECT EXISTS (
18
+ SELECT 1
19
+ FROM drizzle.__drizzle_memory_c064fbca
20
+ WHERE created_at >= 1793829580242
21
+ )' INTO plugin_complete;
22
+ IF NOT plugin_complete THEN
23
+ RAISE EXCEPTION 'The Memory plugin migrations are not complete. Run junior upgrade with @sentry/junior 0.310.0 and @sentry/junior-memory 0.310.0 first.';
24
+ END IF;
25
+ END $$;
26
+ --> statement-breakpoint
27
+ CREATE EXTENSION IF NOT EXISTS btree_gin;
28
+ --> statement-breakpoint
29
+ CREATE TABLE IF NOT EXISTS "junior_memory_memories" (
30
+ "id" text PRIMARY KEY NOT NULL,
31
+ "scope" text NOT NULL,
32
+ "scope_key" text NOT NULL,
33
+ "type" text NOT NULL,
34
+ "subject_type" text NOT NULL,
35
+ "subject_key" text,
36
+ "content" text NOT NULL,
37
+ "source_platform" text NOT NULL,
38
+ "source_key" text NOT NULL,
39
+ "idempotency_key" text,
40
+ "observed_at_ms" bigint NOT NULL,
41
+ "created_at_ms" bigint NOT NULL,
42
+ "expires_at_ms" bigint,
43
+ "superseded_at_ms" bigint,
44
+ "superseded_by_id" text,
45
+ "archived_at_ms" bigint,
46
+ "archive_reason" text,
47
+ "search_vector" "tsvector" GENERATED ALWAYS AS (to_tsvector('english', "content")) STORED,
48
+ "location_id" text,
49
+ "conversation_id" text,
50
+ CONSTRAINT "junior_memory_memories_scope_check" CHECK ("junior_memory_memories"."scope" IN ('private', 'public')),
51
+ CONSTRAINT "junior_memory_memories_kind_check" CHECK ("junior_memory_memories"."type" IN ('preference', 'procedure', 'knowledge')),
52
+ CONSTRAINT "junior_memory_memories_subject_type_check" CHECK ("junior_memory_memories"."subject_type" IN ('user', 'conversation', 'general')),
53
+ CONSTRAINT "junior_memory_memories_subject_key_check" CHECK (("junior_memory_memories"."subject_type" = 'general' AND "junior_memory_memories"."subject_key" IS NULL) OR ("junior_memory_memories"."subject_type" IN ('user', 'conversation') AND "junior_memory_memories"."subject_key" IS NOT NULL AND length("junior_memory_memories"."subject_key") > 0)),
54
+ CONSTRAINT "junior_memory_memories_source_platform_check" CHECK ("junior_memory_memories"."source_platform" IN ('slack', 'local', 'web'))
55
+ );
56
+ --> statement-breakpoint
57
+ CREATE TABLE IF NOT EXISTS "junior_memory_embeddings" (
58
+ "memory_id" text NOT NULL,
59
+ "provider" text NOT NULL,
60
+ "model" text NOT NULL,
61
+ "dimensions" integer NOT NULL,
62
+ "metric" text NOT NULL,
63
+ "content_hash" text NOT NULL,
64
+ "embedding" vector NOT NULL,
65
+ "created_at_ms" bigint NOT NULL,
66
+ CONSTRAINT "junior_memory_embeddings_memory_id_provider_model_pk" PRIMARY KEY("memory_id","provider","model"),
67
+ CONSTRAINT "junior_memory_embeddings_memory_id_junior_memory_memories_id_fk" FOREIGN KEY ("memory_id") REFERENCES "public"."junior_memory_memories"("id") ON DELETE cascade ON UPDATE no action,
68
+ CONSTRAINT "junior_memory_embeddings_metric_check" CHECK ("junior_memory_embeddings"."metric" IN ('cosine')),
69
+ CONSTRAINT "junior_memory_embeddings_dimensions_check" CHECK ("junior_memory_embeddings"."dimensions" IN (1024, 1536) AND vector_dims("junior_memory_embeddings"."embedding") = "junior_memory_embeddings"."dimensions")
70
+ );
71
+ --> statement-breakpoint
72
+ CREATE TABLE IF NOT EXISTS "junior_memory_signals" (
73
+ "memory_id" text NOT NULL,
74
+ "signal" text NOT NULL,
75
+ "idempotency_key" text NOT NULL,
76
+ "conversation_id" text,
77
+ "observed_at_ms" bigint NOT NULL,
78
+ CONSTRAINT "junior_memory_signals_memory_id_signal_idempotency_key_pk" PRIMARY KEY("memory_id","signal","idempotency_key"),
79
+ CONSTRAINT "junior_memory_signals_memory_id_junior_memory_memories_id_fk" FOREIGN KEY ("memory_id") REFERENCES "public"."junior_memory_memories"("id") ON DELETE cascade ON UPDATE no action,
80
+ CONSTRAINT "junior_memory_signals_signal_check" CHECK ("junior_memory_signals"."signal" IN ('duplicate', 'contradicted', 'superseded'))
81
+ );
82
+ --> statement-breakpoint
83
+ -- Plugin migration 0015 widened this check. Replace it here, so a database
84
+ -- that ran the plugin only through 0014 gets the same check, and every
85
+ -- database ends with the same constraint. The new check only allows more
86
+ -- values, so NOT VALID skips the scan and still checks every new write.
87
+ ALTER TABLE "junior_memory_signals" DROP CONSTRAINT IF EXISTS "junior_memory_signals_signal_check";
88
+ --> statement-breakpoint
89
+ ALTER TABLE "junior_memory_signals" ADD CONSTRAINT "junior_memory_signals_signal_check" CHECK ("junior_memory_signals"."signal" IN ('duplicate', 'contradicted', 'superseded')) NOT VALID;
@@ -0,0 +1,17 @@
1
+ -- The Memory indexes. A database that ran the Memory plugin has them already,
2
+ -- and IF NOT EXISTS skips them without a lock that blocks app writes.
3
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_memory_embeddings_model_idx" ON "junior_memory_embeddings" USING btree ("provider","model","dimensions","metric");
4
+ --> statement-breakpoint
5
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_memory_embeddings_embedding_1024_hnsw_idx" ON "junior_memory_embeddings" USING hnsw (("embedding"::vector(1024)) vector_cosine_ops) WITH (m=16,ef_construction=64) WHERE "junior_memory_embeddings"."dimensions" = 1024;
6
+ --> statement-breakpoint
7
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_memory_memories_visible_idx" ON "junior_memory_memories" USING btree ("scope","scope_key","created_at_ms" DESC NULLS LAST,"id") WHERE "junior_memory_memories"."archived_at_ms" IS NULL AND "junior_memory_memories"."superseded_at_ms" IS NULL AND "junior_memory_memories"."superseded_by_id" IS NULL;
8
+ --> statement-breakpoint
9
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_memory_memories_expiration_idx" ON "junior_memory_memories" USING btree ("expires_at_ms") WHERE "junior_memory_memories"."archived_at_ms" IS NULL AND "junior_memory_memories"."expires_at_ms" IS NOT NULL;
10
+ --> statement-breakpoint
11
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_memory_memories_search_idx" ON "junior_memory_memories" USING gin ("scope","scope_key","search_vector") WHERE "junior_memory_memories"."archived_at_ms" IS NULL AND "junior_memory_memories"."superseded_at_ms" IS NULL AND "junior_memory_memories"."superseded_by_id" IS NULL;
12
+ --> statement-breakpoint
13
+ CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "junior_memory_memories_idempotency_idx" ON "junior_memory_memories" USING btree ("scope","scope_key","idempotency_key") WHERE "junior_memory_memories"."idempotency_key" IS NOT NULL AND "junior_memory_memories"."archived_at_ms" IS NULL AND "junior_memory_memories"."superseded_at_ms" IS NULL AND "junior_memory_memories"."superseded_by_id" IS NULL;
14
+ --> statement-breakpoint
15
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_memory_memories_archived_idempotency_idx" ON "junior_memory_memories" USING btree ("scope","scope_key","idempotency_key") WHERE "junior_memory_memories"."idempotency_key" IS NOT NULL AND "junior_memory_memories"."archived_at_ms" IS NOT NULL AND "junior_memory_memories"."archive_reason" <> 'expired';
16
+ --> statement-breakpoint
17
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_memory_signals_observed_idx" ON "junior_memory_signals" USING btree ("memory_id","signal","observed_at_ms");
@@ -0,0 +1,14 @@
1
+ ALTER SEQUENCE "public"."junior_plan_item_version_seq" RENAME TO "junior_todo_version_seq";--> statement-breakpoint
2
+ ALTER TABLE "junior_plan_items" RENAME TO "junior_todos";--> statement-breakpoint
3
+ DROP INDEX "junior_plan_items_in_progress_uidx";--> statement-breakpoint
4
+ ALTER TABLE "junior_todos" DROP CONSTRAINT "junior_plan_items_status_check";--> statement-breakpoint
5
+ -- junior:bounded-backfill: Each Conversation has only a few To-dos.
6
+ UPDATE "junior_todos" SET "status" = CASE "status" WHEN 'in_progress' THEN 'in_progress' WHEN 'done' THEN 'done' WHEN 'cancelled' THEN 'dropped' ELSE 'open' END;--> statement-breakpoint
7
+ -- The update above maps every existing row. NOT VALID skips the scan under
8
+ -- lock and still checks every new write.
9
+ ALTER TABLE "junior_todos" ADD CONSTRAINT "junior_todos_status_check" CHECK ("junior_todos"."status" in ('open', 'in_progress', 'done', 'dropped')) NOT VALID;--> statement-breakpoint
10
+ ALTER TABLE "junior_todos" RENAME CONSTRAINT "junior_plan_items_assignee_check" TO "junior_todos_assignee_check";--> statement-breakpoint
11
+ ALTER TABLE "junior_todos" RENAME CONSTRAINT "junior_plan_items_pk" TO "junior_todos_pk";--> statement-breakpoint
12
+ ALTER TABLE "junior_todos" RENAME CONSTRAINT "junior_plan_items_assignee_user_id_junior_users_id_fk" TO "junior_todos_assignee_user_id_junior_users_id_fk";--> statement-breakpoint
13
+ ALTER TABLE "junior_todos" RENAME CONSTRAINT "junior_plan_items_changed_by_user_id_junior_users_id_fk" TO "junior_todos_changed_by_user_id_junior_users_id_fk";--> statement-breakpoint
14
+ ALTER TABLE "junior_todos" RENAME CONSTRAINT "junior_plan_items_conversation_id_fk" TO "junior_todos_conversation_id_fk";
@@ -0,0 +1,32 @@
1
+ ALTER TABLE "junior_review_items" RENAME TO "junior_inbox_items";--> statement-breakpoint
2
+ ALTER TABLE "junior_review_item_assignees" RENAME TO "junior_inbox_item_assignees";--> statement-breakpoint
3
+ ALTER TABLE "junior_review_item_conversations" RENAME TO "junior_inbox_item_conversations";--> statement-breakpoint
4
+ ALTER TABLE "junior_review_item_slack_cards" RENAME TO "junior_inbox_item_slack_cards";--> statement-breakpoint
5
+ ALTER TABLE "junior_inbox_snoozes" RENAME COLUMN "review_item_id" TO "inbox_item_id";--> statement-breakpoint
6
+ ALTER INDEX "junior_inbox_snoozes_review_item_idx" RENAME TO "junior_inbox_snoozes_inbox_item_idx";--> statement-breakpoint
7
+ ALTER TABLE "junior_inbox_snoozes" RENAME CONSTRAINT "junior_inbox_snoozes_review_item_id_junior_review_items_id_fk" TO "junior_inbox_snoozes_inbox_item_id_junior_inbox_items_id_fk";--> statement-breakpoint
8
+ ALTER INDEX "junior_review_item_assignees_user_idx" RENAME TO "junior_inbox_item_assignees_user_idx";--> statement-breakpoint
9
+ ALTER TABLE "junior_inbox_item_assignees" RENAME CONSTRAINT "junior_review_item_assignees_item_id_junior_review_items_id_fk" TO "junior_inbox_item_assignees_item_id_junior_inbox_items_id_fk";--> statement-breakpoint
10
+ ALTER TABLE "junior_inbox_item_assignees" RENAME CONSTRAINT "junior_review_item_assignees_user_id_junior_users_id_fk" TO "junior_inbox_item_assignees_user_id_junior_users_id_fk";--> statement-breakpoint
11
+ ALTER TABLE "junior_inbox_item_assignees" RENAME CONSTRAINT "junior_review_item_assignees_item_id_user_id_pk" TO "junior_inbox_item_assignees_item_id_user_id_pk";--> statement-breakpoint
12
+ ALTER INDEX "junior_review_item_conversations_conversation_idx" RENAME TO "junior_inbox_item_conversations_conversation_idx";--> statement-breakpoint
13
+ ALTER TABLE "junior_inbox_item_conversations" RENAME CONSTRAINT "junior_review_item_conversations_item_id_junior_review_items_id_fk" TO "junior_inbox_item_conversations_item_id_junior_inbox_items_id_fk";--> statement-breakpoint
14
+ ALTER TABLE "junior_inbox_item_conversations" RENAME CONSTRAINT "junior_review_item_conversations_conversation_id_junior_conversations_conversation_id_fk" TO "junior_inbox_item_conversations_conversation_id_junior_conversations_conversation_id_fk";--> statement-breakpoint
15
+ ALTER TABLE "junior_inbox_item_conversations" RENAME CONSTRAINT "junior_review_item_conversations_item_id_conversation_id_pk" TO "junior_inbox_item_conversations_item_id_conversation_id_pk";--> statement-breakpoint
16
+ ALTER TABLE "junior_inbox_item_slack_cards" RENAME CONSTRAINT "junior_review_item_slack_cards_item_id_junior_review_items_id_fk" TO "junior_inbox_item_slack_cards_item_id_junior_inbox_items_id_fk";--> statement-breakpoint
17
+ ALTER TABLE "junior_inbox_item_slack_cards" RENAME CONSTRAINT "junior_review_item_slack_cards_conversation_id_junior_conversations_conversation_id_fk" TO "junior_inbox_item_slack_cards_conversation_id_junior_conversations_conversation_id_fk";--> statement-breakpoint
18
+ ALTER TABLE "junior_inbox_item_slack_cards" RENAME CONSTRAINT "junior_review_item_slack_cards_item_id_conversation_id_pk" TO "junior_inbox_item_slack_cards_item_id_conversation_id_pk";--> statement-breakpoint
19
+ ALTER INDEX "junior_review_items_open_dedupe_uidx" RENAME TO "junior_inbox_items_open_dedupe_uidx";--> statement-breakpoint
20
+ ALTER INDEX "junior_review_items_status_idx" RENAME TO "junior_inbox_items_status_idx";--> statement-breakpoint
21
+ ALTER INDEX "junior_review_items_subject_idx" RENAME TO "junior_inbox_items_subject_idx";--> statement-breakpoint
22
+ ALTER INDEX "junior_review_items_owner_idx" RENAME TO "junior_inbox_items_owner_idx";--> statement-breakpoint
23
+ ALTER INDEX "junior_review_items_open_action_owner_idx" RENAME TO "junior_inbox_items_open_action_owner_idx";--> statement-breakpoint
24
+ ALTER INDEX "junior_review_items_automation_idx" RENAME TO "junior_inbox_items_automation_idx";--> statement-breakpoint
25
+ ALTER INDEX "junior_review_items_answered_idx" RENAME TO "junior_inbox_items_answered_idx";--> statement-breakpoint
26
+ ALTER TABLE "junior_inbox_items" RENAME CONSTRAINT "junior_review_items_kind_check" TO "junior_inbox_items_kind_check";--> statement-breakpoint
27
+ ALTER TABLE "junior_inbox_items" RENAME CONSTRAINT "junior_review_items_owner_check" TO "junior_inbox_items_owner_check";--> statement-breakpoint
28
+ ALTER TABLE "junior_inbox_items" RENAME CONSTRAINT "junior_review_items_status_check" TO "junior_inbox_items_status_check";--> statement-breakpoint
29
+ ALTER TABLE "junior_inbox_items" RENAME CONSTRAINT "junior_review_items_tenant_check" TO "junior_inbox_items_tenant_check";--> statement-breakpoint
30
+ ALTER TABLE "junior_inbox_items" RENAME CONSTRAINT "junior_review_items_visibility_check" TO "junior_inbox_items_visibility_check";--> statement-breakpoint
31
+ ALTER TABLE "junior_inbox_items" RENAME CONSTRAINT "junior_review_items_automation_id_junior_automations_id_fk" TO "junior_inbox_items_automation_id_junior_automations_id_fk";--> statement-breakpoint
32
+ ALTER TABLE "junior_inbox_items" RENAME CONSTRAINT "junior_review_items_closed_by_user_id_junior_users_id_fk" TO "junior_inbox_items_closed_by_user_id_junior_users_id_fk";
@@ -0,0 +1 @@
1
+ ALTER TABLE "junior_todos" ADD COLUMN "changed_by_conversation_id" text;
@@ -0,0 +1 @@
1
+ ALTER TABLE "junior_inbox_items" ADD COLUMN "subject_title_parts" jsonb;
@@ -0,0 +1 @@
1
+ ALTER TABLE "junior_inbox_snoozes" ADD COLUMN "wake_reason" jsonb;
@@ -0,0 +1 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_authorization_request_idx" ON "junior_conversation_events" USING btree ("conversation_id","created_at") WHERE "junior_conversation_events"."type" = 'authorization_requested';
@@ -0,0 +1,10 @@
1
+ ALTER TABLE "junior_conversation_embeddings" DROP CONSTRAINT "junior_conversation_embeddings_brief_fk";
2
+ --> statement-breakpoint
3
+ ALTER TABLE "junior_conversation_embeddings" ALTER COLUMN "brief_version" DROP NOT NULL;--> statement-breakpoint
4
+ ALTER TABLE "junior_conversation_embeddings" ADD COLUMN "through_seq" integer;--> statement-breakpoint
5
+ ALTER TABLE "junior_conversations" ADD COLUMN "summary" text;--> statement-breakpoint
6
+ ALTER TABLE "junior_conversations" ADD COLUMN "metadata_through_seq" integer;--> statement-breakpoint
7
+ -- Every embedding belonged to a Brief of an existing Conversation, so every
8
+ -- row passes. NOT VALID skips the scan under lock and still checks every new
9
+ -- write.
10
+ ALTER TABLE "junior_conversation_embeddings" ADD CONSTRAINT "junior_conversation_embeddings_conversation_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."junior_conversations"("conversation_id") ON DELETE cascade ON UPDATE no action NOT VALID;
@@ -0,0 +1,39 @@
1
+ -- Copy the latest Brief of each Conversation into its Conversation metadata,
2
+ -- and point the Conversation embedding of that Brief at the copied metadata.
3
+ -- Purge already deleted the Briefs of purged private Conversations. A Brief
4
+ -- that an older worker stores during the rollout is not copied; the next
5
+ -- Turn of that Conversation writes its metadata.
6
+ -- junior:bounded-backfill: runs once and changes each Conversation that has a Brief once. Most of these Conversations are idle, and the update sets only new columns.
7
+ WITH "latest" AS (
8
+ SELECT DISTINCT ON ("conversation_id")
9
+ "conversation_id",
10
+ "version",
11
+ "through_seq",
12
+ "content"
13
+ FROM "junior_conversation_briefs"
14
+ ORDER BY "conversation_id", "version" DESC
15
+ )
16
+ UPDATE "junior_conversations" AS "conversations"
17
+ SET
18
+ "summary" = "latest"."content"->>'summary',
19
+ "metadata_through_seq" = "latest"."through_seq",
20
+ "detail_version" = "conversations"."detail_version" + 1
21
+ FROM "latest"
22
+ WHERE "latest"."conversation_id" = "conversations"."conversation_id"
23
+ AND "conversations"."metadata_through_seq" IS NULL;
24
+ --> statement-breakpoint
25
+ -- junior:bounded-backfill: only the metadata task writes Conversation embeddings, and the update sets only a new column.
26
+ WITH "latest" AS (
27
+ SELECT DISTINCT ON ("conversation_id")
28
+ "conversation_id",
29
+ "version",
30
+ "through_seq"
31
+ FROM "junior_conversation_briefs"
32
+ ORDER BY "conversation_id", "version" DESC
33
+ )
34
+ UPDATE "junior_conversation_embeddings" AS "embeddings"
35
+ SET "through_seq" = "latest"."through_seq"
36
+ FROM "latest"
37
+ WHERE "latest"."conversation_id" = "embeddings"."conversation_id"
38
+ AND "latest"."version" = "embeddings"."brief_version"
39
+ AND "embeddings"."through_seq" IS NULL;
@@ -0,0 +1 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversations_search_idx" ON "junior_conversations" USING gin (to_tsvector('english', coalesce("title", '') || ' ' || coalesce("summary", '')));
@@ -0,0 +1,21 @@
1
+ -- Before 0139 reserved the `automation:` dedupe key prefix for Automation
2
+ -- alerts, agents used it for their own items, such as
3
+ -- `automation:<id>:rewrite` for a question about an Automation. 0139 added
4
+ -- the owner check as NOT VALID because it assumed that no such row existed.
5
+ -- These rows are Conversation items with an `automation:` key, so they break
6
+ -- the check, and each update to them fails: a person cannot dismiss, answer,
7
+ -- or take them. The runtime also reads the prefix as an Automation alert, so
8
+ -- an answer goes to core and not to the agent that asked.
9
+ -- The new key holds the item id, which is unique, so it matches no other
10
+ -- open item. Since 0139, agents cannot use the old keys, so no add looks for
11
+ -- them.
12
+ -- junior:bounded-backfill: only Conversation items that agents added with an `automation:` key before 0139 reserved the prefix, about a dozen rows.
13
+ UPDATE "junior_inbox_items"
14
+ SET
15
+ "dedupe_key" = 'ask:' || "id",
16
+ "updated_at" = now()
17
+ WHERE "owner_kind" = 'conversation'
18
+ AND "dedupe_key" LIKE 'automation:%';--> statement-breakpoint
19
+ -- Now every row meets the check. VALIDATE proves it, so no row that breaks
20
+ -- the check stays until a person's click finds it.
21
+ ALTER TABLE "junior_inbox_items" VALIDATE CONSTRAINT "junior_inbox_items_owner_check";
@@ -0,0 +1 @@
1
+ ALTER TABLE "junior_artifacts" ADD COLUMN "expires_at" timestamp with time zone;
@@ -0,0 +1 @@
1
+ CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "junior_artifacts_permanent_sha_uidx" ON "junior_artifacts" USING btree ("conversation_id","sha256") WHERE "junior_artifacts"."visibility" = 'public' and "junior_artifacts"."expires_at" is null;
@@ -0,0 +1,3 @@
1
+ -- 0154 built the index that replaces this one, so an artifact upsert always
2
+ -- has a unique index to match.
3
+ DROP INDEX "junior_artifacts_public_sha_uidx";
@@ -0,0 +1,6 @@
1
+ -- NOT VALID: the widened checks accept every existing row, so they skip the
2
+ -- scan and still hold for every new write.
3
+ ALTER TABLE "junior_conversations" DROP CONSTRAINT "junior_conversations_kind_check";--> statement-breakpoint
4
+ ALTER TABLE "junior_conversations" DROP CONSTRAINT "junior_conversations_kind_parent_check";--> statement-breakpoint
5
+ ALTER TABLE "junior_conversations" ADD CONSTRAINT "junior_conversations_kind_check" CHECK ("junior_conversations"."kind" in ('root', 'automation', 'lead', 'thread', 'task')) NOT VALID;--> statement-breakpoint
6
+ ALTER TABLE "junior_conversations" ADD CONSTRAINT "junior_conversations_kind_parent_check" CHECK ("junior_conversations"."kind" is null or (("junior_conversations"."kind" in ('root', 'automation', 'lead')) = ("junior_conversations"."parent_conversation_id" is null))) NOT VALID;
@@ -0,0 +1 @@
1
+ CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversations_lead_actor_idx" ON "junior_conversations" USING btree ("actor_identity_id") WHERE "junior_conversations"."kind" = 'lead';