@sentry/junior 0.293.0 → 0.295.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 (85) hide show
  1. package/dist/{admin-uuecrKuD.js → admin-ifgjyfpF.js} +2 -2
  2. package/dist/{agent-runner-DHq1pjUg.js → agent-runner-DjMTPWEO.js} +192 -100
  3. package/dist/api/schema.d.ts +2 -2
  4. package/dist/api/schema.js +5 -5
  5. package/dist/api.d.ts +1 -1
  6. package/dist/api.js +73 -29
  7. package/dist/{app-fWzCHFIb.d.ts → app-uiTzRbvq.d.ts} +5 -3
  8. package/dist/app.d.ts +2 -2
  9. package/dist/app.js +64 -74
  10. package/dist/{automation-BE3z19VN.js → automation-yJX3C7i3.js} +3 -3
  11. package/dist/{background-compaction-queue-D7ncdEa6.js → background-compaction-queue-DUkHZjmL.js} +7 -9
  12. package/dist/{briefs-NpgMEFh1.js → briefs-CbNYM-q2.js} +3 -3
  13. package/dist/{catalog-runtime-DwbTyNRD.js → catalog-runtime-DgouZKZm.js} +1 -1
  14. package/dist/cli/chat.d.ts +1 -1
  15. package/dist/cli/chat.js +15 -15
  16. package/dist/cli/check.js +3 -3
  17. package/dist/cli/init.js +2 -0
  18. package/dist/cli/main.js +3 -3
  19. package/dist/cli/plugins.d.ts +1 -1
  20. package/dist/cli/plugins.js +4 -4
  21. package/dist/cli/snapshot-create.js +4 -4
  22. package/dist/cli/upgrade.d.ts +2 -2
  23. package/dist/cli/upgrade.js +7 -74
  24. package/dist/{config-B4b-NXH5.js → config-DvnTPCfp.js} +58 -7
  25. package/dist/{connections-Dz_AQg5p.js → connections-CWaIVl_1.js} +6 -6
  26. package/dist/{conversation-CtjR1Zcx.js → conversation-CMkSmi02.js} +3 -11
  27. package/dist/{conversation-pending-messages-1Kad1Mif.js → conversation-feed-BVAOga0H.js} +27 -2
  28. package/dist/{conversation-privacy-DRsSgLGO.js → conversation-privacy-DPjv4SnA.js} +1 -1
  29. package/dist/{credential-sync-ClCnnGVj.js → credential-sync-BhbaZfmO.js} +16 -15
  30. package/dist/{db-BbpttyKH.d.ts → db-CCUqQe0E.d.ts} +13 -6
  31. package/dist/{db-CoA7_Xqu.js → db-Dts2XvLu.js} +144 -7
  32. package/dist/{executor-SWyHhit0.js → executor-Ck73J0wP.js} +64 -10
  33. package/dist/instrumentation.js +2 -2
  34. package/dist/{logging-BN5drSEZ.js → logging-9OAq-fdg.js} +2 -1
  35. package/dist/{message-D4qjpW1C.js → message-CtaPzC7m.js} +9 -9
  36. package/dist/nitro.d.ts +2 -2
  37. package/dist/nitro.js +2 -2
  38. package/dist/{oauth-callback-server-Xi-mTLOV.js → oauth-callback-server-C_LXY1d4.js} +2 -2
  39. package/dist/{oauth-relay-D6xxVywK.js → oauth-relay-CsfIazeF.js} +2 -1
  40. package/dist/{plugins-DtmjkTza.d.ts → plugins-B_0Cr0MO.d.ts} +0 -1
  41. package/dist/{projection-DXl4ftyL.js → projection-BzJQncZV.js} +251 -161
  42. package/dist/{prompt-Dmx6IfWZ.js → prompt-Cbq5b4SO.js} +5 -6
  43. package/dist/{registry-DosVt9f9.js → registry-cbpOxO4M.js} +3 -13
  44. package/dist/{resolve-BDjWJC9s.js → resolve-t-pmRdwS.js} +3 -3
  45. package/dist/{result-CaAFpf4B.js → result-DhgjR3nQ.js} +8 -8
  46. package/dist/{runner-h96Mkss6.js → runner-CHv9X9TH.js} +8 -8
  47. package/dist/{sandbox-egress-signals-rK91BW7i.js → sandbox-egress-signals-Yy3fSCbg.js} +1 -1
  48. package/dist/{schema-C_v8wb80.js → schema-BhneuGYv.js} +39 -7
  49. package/dist/{schema-CHsBmXIj.d.ts → schema-TSEisVJR.d.ts} +87 -14
  50. package/dist/secrets-DebYU866.js +18 -0
  51. package/dist/{service-account-WUMVuqVL.js → service-account-C4rBP8ne.js} +3 -3
  52. package/dist/{service-account-BpGpScaT.js → service-account-DjPIwCMj.js} +42 -26
  53. package/dist/{session-stop-xYK15HUu.js → session-stop-DkxI5vc3.js} +20 -775
  54. package/dist/{skills-DHApyCjj.js → skills-BZE2DP8I.js} +2 -2
  55. package/dist/{spawn-BQQrwGNe.js → spawn-BvULxIiu.js} +5 -5
  56. package/dist/{adapter-CMJfmHso.js → state-CO9ETDzk.js} +132 -2
  57. package/dist/{stop-CBeD6_Gs.js → stop-CL-rdtQb.js} +85 -32
  58. package/dist/{store-xtibD98L.js → store-DgD78_NK.js} +3 -3
  59. package/dist/{task-runner-BYPN4BEO.js → task-runner-CKOj6xla.js} +11 -11
  60. package/dist/{turn-failure-response-jNVl00MD.js → turn-failure-response-BTSo6SMJ.js} +8 -8
  61. package/dist/{validation-DGeB_moV.js → validation-CXeYgBzq.js} +1 -1
  62. package/dist/{version-C6nqU3Qc.js → version-AQa7Fr2H.js} +1 -1
  63. package/dist/version.js +1 -1
  64. package/dist/{viewer-9KLQibjn.js → viewer-Bqkb678l.js} +3 -3
  65. package/dist/warmup-h6u1e9n0.js +1869 -0
  66. package/dist/{work-xwX6unUE.js → work-yN_GAuXY.js} +11 -11
  67. package/dist/{worker-CiCCfwd4.js → worker-Hl7N292I.js} +6 -6
  68. package/migrations/0062_plugin_report_index.sql +1 -20
  69. package/migrations/0078_plugin_conversation_index.sql +1 -20
  70. package/migrations/0079_conversation_event_author_index.sql +1 -20
  71. package/migrations/0080_conversation_event_latest_message_indexes.sql +2 -27
  72. package/migrations/0090_guardian_review_time_index.sql +1 -20
  73. package/migrations/0091_conversation_participant_unsubscribed_index.sql +1 -20
  74. package/migrations/0097_conversation_kind_automation.sql +6 -0
  75. package/migrations/0098_review_item_plugin_actions.sql +5 -0
  76. package/migrations/0099_conversation_last_message_at.sql +1 -0
  77. package/migrations/0100_automation_task_kind_repair.sql +48 -0
  78. package/migrations/meta/0097_snapshot.json +4490 -0
  79. package/migrations/meta/0098_snapshot.json +4490 -0
  80. package/migrations/meta/0099_snapshot.json +4720 -0
  81. package/migrations/meta/0100_snapshot.json +4496 -0
  82. package/migrations/meta/_journal.json +28 -0
  83. package/package.json +5 -5
  84. package/dist/assistant-reply-CIApSfor.js +0 -58
  85. package/dist/warmup-7S6z068f.js +0 -993
@@ -1,15 +1,15 @@
1
- import { En as renderTag, H as PluginCredentialFailureError, K as AuthorizationFlowDisabledError, Sn as escapeClosingTags, an as getTerminalAssistantMessages, at as failTurnRecord, bo as loadForkHistory, en as isTurnExecutionLimitExceededError, et as lostWorkerBeforeFirstSave, nt as saveTurnCheckpoint, ot as getTurnRecord, rt as abandonTurnRecord, s as openConversationProjection, tt as pauseLostWorkerTurn, v as hydrateConversationMessages } from "./projection-DXl4ftyL.js";
2
- import { n as botConfig } from "./config-B4b-NXH5.js";
3
- import { T as SYSTEM_IDENTITY_ID, a as getConversationStore, r as getConversationEventStore, s as getSqlExecutor } from "./db-CoA7_Xqu.js";
4
- import { g as juniorAgentInvocations, h as juniorAgentBindings } from "./executor-SWyHhit0.js";
1
+ import { H as PluginCredentialFailureError, K as AuthorizationFlowDisabledError, Sn as renderTag, Xt as isTurnExecutionLimitExceededError, at as failTurnRecord, et as lostWorkerBeforeFirstSave, go as loadForkHistory, nt as saveTurnCheckpoint, ot as getTurnRecord, rt as abandonTurnRecord, s as openConversationProjection, tn as getTerminalAssistantMessages, tt as pauseLostWorkerTurn, v as hydrateConversationMessages, vn as escapeClosingTags } from "./projection-BzJQncZV.js";
2
+ import { n as botConfig } from "./config-DvnTPCfp.js";
3
+ import { M as SYSTEM_IDENTITY_ID, a as getConversationStore, r as getConversationEventStore, s as getSqlExecutor } from "./db-Dts2XvLu.js";
4
+ import { g as juniorAgentInvocations, h as juniorAgentBindings } from "./executor-Ck73J0wP.js";
5
5
  import { h as contextProvenance, m as agentInstructionProvenance, v as sameActorIdentity } from "./media-BepyEUNm.js";
6
- import { Dt as stopChildAgentsOf, Gt as finishTurn, Mt as supersedeOpenMailboxTurns, Ot as recordSubagentEnded, Ut as AgentRunError, Wt as executeTurn, an as AgentNameInUseError, kt as recordSubagentStarted, rn as AgentMessageQueueFullError, tn as AgentInvocationLimitError } from "./agent-runner-DHq1pjUg.js";
7
- import { k as getTurnRequestDeadline } from "./background-compaction-queue-D7ncdEa6.js";
8
- import { $ as getUnnamedAgentConversationId, A as markAgentInvocationPaused, C as isTerminalAgentInvocation, H as agentTypeStartsWithParentHistory, J as getAgentInvocationMessageId, L as agentBindingSchema, M as markAgentInvocationSteered, N as reportReplacedAgentInvocation, O as markAgentInvocationMailboxAppended, Q as getNamedAgentConversationId, T as listOpenAgentInvocations, V as agentTypeInstructions, W as getAgentInvocationId, X as getAgentInvocationTurnId, Z as getChildAgentLockName, _ as completeAgentInvocation, at as getConversationTurnBoundaryError, f as ConversationTurnLifecycleService, g as NON_TERMINAL_AGENT_INVOCATION_STATUSES, h as ACTIVE_AGENT_INVOCATION_STATUSES, j as markAgentInvocationRunning, rt as TurnInputCommitLostError, st as isTurnInputCommitLostError, v as getActiveAgentInvocationForConversation, w as listAgentInvocationsForConversation, x as getLatestAgentInvocationForConversation, y as getAgentInvocation, z as createAgentInvocationSchema } from "./turn-failure-response-jNVl00MD.js";
9
- import { n as getAssistantReplyText } from "./assistant-reply-CIApSfor.js";
10
- import { $ as withoutSavedSteeringMessages, B as maybePostAutomatedTurnLimitNotice, K as recordFinishedTurnForAutomatedLimit, X as buildSteeringPiMessage, Z as instructionForInputs, ct as readBlockedReport, h as parseWebMessages, i as resumeStoppedConversationTree, p as listActiveMailboxTurns, q as resetAutomatedTurnLimit, u as getActiveConversationTurnId } from "./session-stop-xYK15HUu.js";
11
- import { r as appendAndEnqueueInboundMessage } from "./store-xtibD98L.js";
12
- import { ft as getPersistedSandboxState, gt as coerceThreadConversationState, ht as persistThreadStateById, pt as getPersistedThreadState } from "./task-runner-BYPN4BEO.js";
6
+ import { Dt as stopChildAgentsOf, Gt as finishTurn, Mt as supersedeOpenMailboxTurns, Ot as recordSubagentEnded, Ut as AgentRunError, Wt as executeTurn, an as AgentNameInUseError, kt as recordSubagentStarted, rn as AgentMessageQueueFullError, tn as AgentInvocationLimitError } from "./agent-runner-DjMTPWEO.js";
7
+ import { D as getAssistantReplyText, P as readBlockedReport } from "./warmup-h6u1e9n0.js";
8
+ import { k as getTurnRequestDeadline } from "./background-compaction-queue-DUkHZjmL.js";
9
+ import { $ as getUnnamedAgentConversationId, A as markAgentInvocationPaused, C as isTerminalAgentInvocation, H as agentTypeStartsWithParentHistory, J as getAgentInvocationMessageId, L as agentBindingSchema, M as markAgentInvocationSteered, N as reportReplacedAgentInvocation, O as markAgentInvocationMailboxAppended, Q as getNamedAgentConversationId, T as listOpenAgentInvocations, V as agentTypeInstructions, W as getAgentInvocationId, X as getAgentInvocationTurnId, Z as getChildAgentLockName, _ as completeAgentInvocation, at as getConversationTurnBoundaryError, f as ConversationTurnLifecycleService, g as NON_TERMINAL_AGENT_INVOCATION_STATUSES, h as ACTIVE_AGENT_INVOCATION_STATUSES, j as markAgentInvocationRunning, rt as TurnInputCommitLostError, st as isTurnInputCommitLostError, v as getActiveAgentInvocationForConversation, w as listAgentInvocationsForConversation, x as getLatestAgentInvocationForConversation, y as getAgentInvocation, z as createAgentInvocationSchema } from "./turn-failure-response-BTSo6SMJ.js";
10
+ import { $ as withoutSavedSteeringMessages, B as maybePostAutomatedTurnLimitNotice, K as recordFinishedTurnForAutomatedLimit, X as buildSteeringPiMessage, Z as instructionForInputs, h as parseWebMessages, i as resumeStoppedConversationTree, p as listActiveMailboxTurns, q as resetAutomatedTurnLimit, u as getActiveConversationTurnId } from "./session-stop-DkxI5vc3.js";
11
+ import { r as appendAndEnqueueInboundMessage } from "./store-DgD78_NK.js";
12
+ import { ft as getPersistedSandboxState, gt as coerceThreadConversationState, ht as persistThreadStateById, pt as getPersistedThreadState } from "./task-runner-CKOj6xla.js";
13
13
  import { isDeepStrictEqual } from "node:util";
14
14
  import * as z from "zod";
15
15
  import { and, eq } from "drizzle-orm";
@@ -1,10 +1,10 @@
1
1
  import { v as __exportAll } from "./sentry-BRTJqumy.js";
2
- import { At as isInvalidConversationRecordError, Dt as hasConversationStop, St as countPendingConversationMessages, kt as isFinalAttempt } from "./projection-DXl4ftyL.js";
3
- import { W as isProviderRetryError, i as getChatConfig } from "./config-B4b-NXH5.js";
4
- import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging-BN5drSEZ.js";
5
- import { Ht as selectAttemptMessages, Vt as isAttemptInterrupt } from "./agent-runner-DHq1pjUg.js";
6
- import { k as getTurnRequestDeadline, y as ConversationQueueMessageRejectedError } from "./background-compaction-queue-D7ncdEa6.js";
7
- import { C as startConversationWork, b as releaseConversationWork, c as clearConsumedConversationWake, d as completeConversationWork, f as deadLetterAttempt, g as getConversationWorkState, i as beginConversationResume, m as ensureConversationWake, o as checkInConversationWork, p as drainConversationMailbox, t as ackMessages, u as completeConversationStop, v as recordAttemptFailure, x as requestAnotherSlice, y as recordConversationRetry } from "./store-xtibD98L.js";
2
+ import { At as isInvalidConversationRecordError, Dt as hasConversationStop, St as countPendingConversationMessages, kt as isFinalAttempt } from "./projection-BzJQncZV.js";
3
+ import { K as isProviderRetryError, i as getChatConfig } from "./config-DvnTPCfp.js";
4
+ import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging-9OAq-fdg.js";
5
+ import { Ht as selectAttemptMessages, Vt as isAttemptInterrupt } from "./agent-runner-DjMTPWEO.js";
6
+ import { k as getTurnRequestDeadline, y as ConversationQueueMessageRejectedError } from "./background-compaction-queue-DUkHZjmL.js";
7
+ import { C as startConversationWork, b as releaseConversationWork, c as clearConsumedConversationWake, d as completeConversationWork, f as deadLetterAttempt, g as getConversationWorkState, i as beginConversationResume, m as ensureConversationWake, o as checkInConversationWork, p as drainConversationMailbox, t as ackMessages, u as completeConversationStop, v as recordAttemptFailure, x as requestAnotherSlice, y as recordConversationRetry } from "./store-DgD78_NK.js";
8
8
  // src/chat/task-execution/worker.ts
9
9
  var worker_exports = /* @__PURE__ */ __exportAll({
10
10
  CONVERSATION_WORK_DEFER_DELAY_MS: () => CONVERSATION_WORK_DEFER_DELAY_MS,
@@ -1,20 +1 @@
1
- -- Before this migration runs, junior upgrade builds the marked index with
2
- -- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
3
- DO $$
4
- BEGIN
5
- -- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
6
- IF to_regclass('junior_conversation_events_plugin_report_idx') IS NULL THEN
7
- -- junior:concurrent-index
8
- CREATE INDEX "junior_conversation_events_plugin_report_idx" ON "junior_conversation_events" USING btree (("payload"->>'namespace'),("payload"->>'name'),"created_at") WHERE "junior_conversation_events"."type" = 'structured_event';
9
- END IF;
10
-
11
- -- A failed concurrent build can leave an index that exists but cannot be used.
12
- IF NOT EXISTS (
13
- SELECT 1 FROM pg_index
14
- WHERE indexrelid = 'junior_conversation_events_plugin_report_idx'::regclass
15
- AND indrelid = 'junior_conversation_events'::regclass
16
- AND indisvalid AND indisready
17
- ) THEN
18
- RAISE EXCEPTION 'The plugin report index is not valid and ready. Repair the concurrent build before running junior upgrade.';
19
- END IF;
20
- END $$;
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_plugin_report_idx" ON "junior_conversation_events" USING btree (("payload"->>'namespace'),("payload"->>'name'),"created_at") WHERE "junior_conversation_events"."type" = 'structured_event';
@@ -1,20 +1 @@
1
- -- Before this migration runs, junior upgrade builds the marked index with
2
- -- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
3
- DO $$
4
- BEGIN
5
- -- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
6
- IF to_regclass('junior_conversation_events_plugin_conversation_idx') IS NULL THEN
7
- -- junior:concurrent-index
8
- CREATE INDEX "junior_conversation_events_plugin_conversation_idx" ON "junior_conversation_events" USING btree ("conversation_id",("payload"->>'namespace'),("payload"->>'name'),"seq") WHERE "junior_conversation_events"."type" = 'structured_event';
9
- END IF;
10
-
11
- -- A failed concurrent build can leave an index that exists but cannot be used.
12
- IF NOT EXISTS (
13
- SELECT 1 FROM pg_index
14
- WHERE indexrelid = 'junior_conversation_events_plugin_conversation_idx'::regclass
15
- AND indrelid = 'junior_conversation_events'::regclass
16
- AND indisvalid AND indisready
17
- ) THEN
18
- RAISE EXCEPTION 'The plugin conversation index is not valid and ready. Repair the concurrent build before running junior upgrade.';
19
- END IF;
20
- END $$;
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_plugin_conversation_idx" ON "junior_conversation_events" USING btree ("conversation_id",("payload"->>'namespace'),("payload"->>'name'),"seq") WHERE "junior_conversation_events"."type" = 'structured_event';
@@ -1,20 +1 @@
1
- -- Before this migration runs, junior upgrade builds the marked index with
2
- -- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
3
- DO $$
4
- BEGIN
5
- -- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
6
- IF to_regclass('junior_conversation_events_author_idx') IS NULL THEN
7
- -- junior:concurrent-index
8
- CREATE INDEX "junior_conversation_events_author_idx" ON "junior_conversation_events" USING btree ("conversation_id","actor_identity_id","seq") WHERE "junior_conversation_events"."actor_identity_id" is not null;
9
- END IF;
10
-
11
- -- A failed concurrent build can leave an index that exists but cannot be used.
12
- IF NOT EXISTS (
13
- SELECT 1 FROM pg_index
14
- WHERE indexrelid = 'junior_conversation_events_author_idx'::regclass
15
- AND indrelid = 'junior_conversation_events'::regclass
16
- AND indisvalid AND indisready
17
- ) THEN
18
- RAISE EXCEPTION 'The conversation event author index is not valid and ready. Repair the concurrent build before running junior upgrade.';
19
- END IF;
20
- END $$;
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_author_idx" ON "junior_conversation_events" USING btree ("conversation_id","actor_identity_id","seq") WHERE "junior_conversation_events"."actor_identity_id" is not null;
@@ -1,27 +1,2 @@
1
- -- Before this migration runs, junior upgrade builds the marked indexes with
2
- -- CREATE INDEX CONCURRENTLY, so the builds below do not block writes.
3
- DO $$
4
- BEGIN
5
- -- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
6
- IF to_regclass('junior_conversation_events_message_role_idx') IS NULL THEN
7
- -- junior:concurrent-index
8
- CREATE INDEX "junior_conversation_events_message_role_idx" ON "junior_conversation_events" USING btree ("conversation_id",("payload"->>'role'),"created_at","seq") WHERE "junior_conversation_events"."type" = 'message';
9
- END IF;
10
- IF to_regclass('junior_conversation_events_user_message_time_idx') IS NULL THEN
11
- -- junior:concurrent-index
12
- CREATE INDEX "junior_conversation_events_user_message_time_idx" ON "junior_conversation_events" USING btree ("conversation_id","created_at","seq") WHERE "junior_conversation_events"."type" = 'user_message' and ("junior_conversation_events"."payload"->'provenance'->>'authority') = 'instruction' and ("junior_conversation_events"."payload"->'provenance'->'actor'->>'platform') in ('slack', 'local', 'web');
13
- END IF;
14
-
15
- -- A failed concurrent build can leave an index that exists but cannot be used.
16
- IF (
17
- SELECT count(*) FROM pg_index
18
- WHERE indexrelid IN (
19
- 'junior_conversation_events_message_role_idx'::regclass,
20
- 'junior_conversation_events_user_message_time_idx'::regclass
21
- )
22
- AND indrelid = 'junior_conversation_events'::regclass
23
- AND indisvalid AND indisready
24
- ) <> 2 THEN
25
- RAISE EXCEPTION 'The conversation event latest message indexes are not valid and ready. Repair the concurrent builds before running junior upgrade.';
26
- END IF;
27
- END $$;
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_message_role_idx" ON "junior_conversation_events" USING btree ("conversation_id",("payload"->>'role'),"created_at","seq") WHERE "junior_conversation_events"."type" = 'message';--> statement-breakpoint
2
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_user_message_time_idx" ON "junior_conversation_events" USING btree ("conversation_id","created_at","seq") WHERE "junior_conversation_events"."type" = 'user_message' and ("junior_conversation_events"."payload"->'provenance'->>'authority') = 'instruction' and ("junior_conversation_events"."payload"->'provenance'->'actor'->>'platform') in ('slack', 'local', 'web');
@@ -1,20 +1 @@
1
- -- Before this migration runs, junior upgrade builds the marked index with
2
- -- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
3
- DO $$
4
- BEGIN
5
- -- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
6
- IF to_regclass('junior_conversation_events_guardian_review_time_idx') IS NULL THEN
7
- -- junior:concurrent-index
8
- CREATE INDEX "junior_conversation_events_guardian_review_time_idx" ON "junior_conversation_events" USING btree ("created_at") WHERE "junior_conversation_events"."type" = 'guardian_action_reviewed';
9
- END IF;
10
-
11
- -- A failed concurrent build can leave an index that exists but cannot be used.
12
- IF NOT EXISTS (
13
- SELECT 1 FROM pg_index
14
- WHERE indexrelid = 'junior_conversation_events_guardian_review_time_idx'::regclass
15
- AND indrelid = 'junior_conversation_events'::regclass
16
- AND indisvalid AND indisready
17
- ) THEN
18
- RAISE EXCEPTION 'The Guardian review time index is not valid and ready. Repair the concurrent build before running junior upgrade.';
19
- END IF;
20
- END $$;
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_events_guardian_review_time_idx" ON "junior_conversation_events" USING btree ("created_at") WHERE "junior_conversation_events"."type" = 'guardian_action_reviewed';
@@ -1,20 +1 @@
1
- -- Before this migration runs, junior upgrade builds the marked index with
2
- -- CREATE INDEX CONCURRENTLY, so the build below does not block writes.
3
- DO $$
4
- BEGIN
5
- -- Even CREATE INDEX IF NOT EXISTS takes a write-blocking table lock.
6
- IF to_regclass('junior_conversation_participants_unsubscribed_idx') IS NULL THEN
7
- -- junior:concurrent-index
8
- CREATE INDEX "junior_conversation_participants_unsubscribed_idx" ON "junior_conversation_participants" USING btree ("user_id","root_conversation_id") WHERE "junior_conversation_participants"."unsubscribed_at" is not null;
9
- END IF;
10
-
11
- -- A failed concurrent build can leave an index that exists but cannot be used.
12
- IF NOT EXISTS (
13
- SELECT 1 FROM pg_index
14
- WHERE indexrelid = 'junior_conversation_participants_unsubscribed_idx'::regclass
15
- AND indrelid = 'junior_conversation_participants'::regclass
16
- AND indisvalid AND indisready
17
- ) THEN
18
- RAISE EXCEPTION 'The conversation participant unsubscribed index is not valid and ready. Repair the concurrent build before running junior upgrade.';
19
- END IF;
20
- END $$;
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_conversation_participants_unsubscribed_idx" ON "junior_conversation_participants" USING btree ("user_id","root_conversation_id") WHERE "junior_conversation_participants"."unsubscribed_at" is not null;
@@ -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', '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')) = ("junior_conversations"."parent_conversation_id" is null))) NOT VALID;
@@ -0,0 +1,5 @@
1
+ ALTER TABLE "junior_review_items" DROP CONSTRAINT "junior_review_items_kind_check";--> statement-breakpoint
2
+ -- The new check only allows more rows than the old one, so every row passes.
3
+ -- NOT VALID skips the scan under lock and still checks every new write. A
4
+ -- later migration validates it.
5
+ 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:%' and "junior_review_items"."answer" is null)))) NOT VALID;
@@ -0,0 +1 @@
1
+ ALTER TABLE "junior_conversations" ADD COLUMN "last_message_at" timestamp with time zone;
@@ -0,0 +1,48 @@
1
+ -- Repeat the `{ text }` task rewrite of 0096_automation_task_kind.
2
+ -- `junior upgrade` runs migrations before the new runtime takes traffic. In
3
+ -- that window the old runtime still created Automations, and it wrote the old
4
+ -- `{ text }` task and an `instruction` version definition after 0096 ran.
5
+ -- The new runtime cannot read those rows. Each statement changes only rows
6
+ -- with the old shape, so this migration is safe to run again.
7
+ -- junior:bounded-backfill: changes only active or paused Automations with an old, blank task, which cannot run, so few rows match.
8
+ UPDATE "junior_automations"
9
+ SET
10
+ "status" = 'blocked',
11
+ "status_reason" = 'This automation has no instruction. Write one or choose a skill, then resume it.'
12
+ WHERE "record"->'task' ? 'text'
13
+ AND btrim("record"->'task'->>'text', E' \t\r\n') = ''
14
+ AND "status" IN ('active', 'paused');--> statement-breakpoint
15
+ -- junior:bounded-backfill: changes only Automations with an old task, which the old runtime wrote during one rollout, so few rows match.
16
+ WITH "old" AS (
17
+ SELECT
18
+ "id",
19
+ coalesce(
20
+ nullif(btrim("record"->'task'->>'text', E' \t\r\n'), ''),
21
+ 'No instruction was saved.'
22
+ ) AS "instruction"
23
+ FROM "junior_automations"
24
+ WHERE "record"->'task' ? 'text'
25
+ )
26
+ UPDATE "junior_automations"
27
+ SET
28
+ "instruction" = "old"."instruction",
29
+ "record" = jsonb_set(
30
+ "record",
31
+ '{task}',
32
+ jsonb_build_object('kind', 'instruction', 'instruction', "old"."instruction")
33
+ )
34
+ FROM "old"
35
+ WHERE "junior_automations"."id" = "old"."id";--> statement-breakpoint
36
+ -- junior:bounded-backfill: changes only saved versions with an old definition, which the old runtime wrote during one rollout, so few rows match.
37
+ UPDATE "junior_automation_versions"
38
+ SET "definition" = ("definition" - 'instruction') || jsonb_build_object(
39
+ 'task',
40
+ jsonb_build_object(
41
+ 'kind', 'instruction',
42
+ 'instruction', coalesce(
43
+ nullif(btrim("definition"->>'instruction', E' \t\r\n'), ''),
44
+ 'No instruction was saved.'
45
+ )
46
+ )
47
+ )
48
+ WHERE "definition" ? 'instruction';