diff --git a/doc/DEVELOPING.md b/doc/DEVELOPING.md index 709eb2cb930..9736a2e7be1 100644 --- a/doc/DEVELOPING.md +++ b/doc/DEVELOPING.md @@ -1263,6 +1263,15 @@ run events, issue-lock release, plan-resume reporting, and worktree cutoffs. It re-exports the existing retry helpers and workspace-busy error class. Keep retry policy changes separate from this extraction. +Restart recovery and lease cleanup are in `server/src/services/heartbeat/recovery.ts`. +It owns hot-restart snapshots and adoption, native restart recovery, shutdown +draining, orphaned-run reaping, and active/pending-cleanup lease sweeps. +`createHeartbeatRecovery` binds the service database and explicit lifecycle +callbacks without starting work. The service supplies its shutdown flag callback +and shared execution sets so separate service instances keep the same ownership +and shutdown barriers. Cleanup single-flight state stays at module scope. +Keep recovery policy changes separate from retry scheduling and execution changes. + ## Wake Context Delivery Built-in adapters deliver wake context through the run prompt, including structured diff --git a/doc/openai-dot-runner.md b/doc/openai-dot-runner.md index 358dd0de041..6f8afba36f4 100644 --- a/doc/openai-dot-runner.md +++ b/doc/openai-dot-runner.md @@ -48,6 +48,16 @@ controller deployments are not qualified. The feature is off by default. Only the operator's one-use pairing code is displayed. OAuth tokens and callback signing secrets stay on the server and never enter the Runner descriptor, task prompt or saved adapter config. Pairing codes expire after 15 minutes. +Once paired, the connection has no Paperclip inactivity expiry, including existing +valid connections upgraded by migration `0319_heavy_captain_midlands.sql`. Access tokens +still last 15 minutes and are renewed with rotating, non-expiring refresh tokens; +revocation, replay detection, and current company/agent permissions still apply. +This does not control any independent OpenAI-side connection policy. + +In **Invite an external agent → Dot**, the prompt preview closes automatically +as soon as Paperclip observes the connection. The footer shows **Connecting…** +while Dot subscribes, then **Confirming connection…** during the event check. +After the round trip succeeds, **Done** closes the invitation dialog. The dedicated connection uses the merged MCP gateway's PKCE browser and device flows, including verified client metadata documents and organization hints. @@ -333,12 +343,13 @@ Mailbox `follow_up` entries reference new comments on an accepted assignment. Re ## Tool inventory -The top-level MCP catalog contains these 15 transport and lifecycle tools: +The top-level MCP catalog contains these 16 transport, lifecycle, and profile tools: `paperclip_dot_capabilities`, `paperclip_dot_request_turn`, `paperclip_dot_tasks`, `paperclip_dot_request_work`, `paperclip_dot_pair`, `paperclip_dot_inbox`, `paperclip_dot_read`, `paperclip_dot_accept`, `paperclip_dot_tool`, `paperclip_dot_progress`, `paperclip_dot_finish`, `paperclip_dot_operation_status`, -`paperclip_dot_confirm_event`, `paperclip_dot_renew`, `paperclip_dot_control_ack`. +`paperclip_dot_confirm_event`, `paperclip_dot_renew`, `paperclip_dot_control_ack`, +`paperclip_dot_set_avatar`. After accepting work, use `paperclip_dot_tool` with a name from the assignment's actual catalog. Availability depends on work mode, permissions, assigned apps, @@ -387,3 +398,28 @@ A plugin upgraded during a running Dot conversation can retain an old top-level tool catalog. Refresh its tools in ChatGPT plugin settings and reattach it. Inspect the real exposed actions before claiming new idle or lease actions are available. The assignment catalog is read on each new assignment. + +## Cloud direction and external-agent invitation UX + +The [2026-10-08 cloud Runner and invitation decision](plans/2026-10-08-cloud-dot-runner-and-external-invitations.md) keeps remote agents on the new Runner infrastructure. In addition to shared assignment lifecycle handling, this preserves a sandbox boundary for future tools that may access Paperclip workspaces. The first cloud version gives Dot no Paperclip workspace file or command tools; Dot works on its own computer. + +The self-hosted entry is **New Agent → Invite an external agent → Dot / Hermes / Other**. Dot receives a copyable setup prompt and live connection checks, with readiness requiring a confirmed event round trip. The same components have Storybook journeys with fixture data. Cloud execution remains disabled pending qualification. Hermes continues to use the existing external-agent invitation prompt. + +## Agent avatar + +After pairing, Dot can call `paperclip_dot_set_avatar` without an active assignment or completed event test. It changes only the Paperclip agent bound to that live connection. It requires the Dot and Assistant connections experimental flags, an active operator membership, and a non-revoked grant and binding. + +Input is `{ "imageBase64": "" }`. PNG, JPEG and WebP are supported, up to 512 KiB and 16 megapixels; animations and SVG are rejected. Paperclip re-encodes the image as a metadata-free PNG at most 512 pixels on either side. Sending the same image again is safe and does not create another asset. Send `{ "imageBase64": null }` to restore the existing Paperclip character and palette. + +The same capability is available to agents via `PUT /api/companies/:companyId/agents/:agentId/avatar` with the same body and normal agent bearer authentication. An agent can update only itself; board users need the same `agent_config:update` permission as other agent configuration changes. Task bridge and skill test credentials cannot change avatars. Returned `appearance.customAvatarAssetId` and `avatarUrl` propagate through existing agent views. The image is a company-scoped private asset served through authenticated `/api/assets/:assetId/content`, not a public image URL for third-party embeds. Previous assets remain available for configuration history. Company exports retain the preset character and palette and warn that uploaded avatar assets must be uploaded again after import; private asset IDs are never portable. Activity records contain asset metadata, never image bytes. + +The setup prompt asks Dot to upload its own current image only if it can obtain it. We have not verified a supported OpenAI avatar-export API. Avatar availability must never block pairing; Dot may call the tool later. This capability does not add workspace access or change Runner assignment execution. + + +### Invite from the agent picker + +In a self-hosted instance, enable **OpenAI Dot** and **Assistant connections (MCP)**, then choose **New Agent → Invite an external agent → Dot**. Copy the setup prompt into your Dot. Paperclip creates a scoped Runner agent and watches connection, event subscription, and a harmless event round trip. If your company requires hire approval, approve the agent before copying its pairing prompt. The test event is sent automatically after the callback is verified; Retry test event remains available if confirmation times out. + +Reopening setup resumes the operator's unfinished invitation. Pairing codes are not stored in browser persistence. After refreshing or when an open prompt expires, setup automatically prepares a fresh prompt to copy. It first checks current connection state and replaces only the pending capability, without revoking an established connection. A failed renewal offers a retry rather than looping. If another browser window replaces the prompt, the current window asks before replacing it again. Hermes and Other continue to use the ordinary external-agent invitation flow. + +Cloud Dot execution is still gated. The external launcher hooks do not yet enable managed cloud execution or qualify tenant MCP routing. See [the cloud Runner plan](plans/2026-10-08-cloud-dot-runner-and-external-invitations.md). diff --git a/doc/plans/2026-10-08-cloud-dot-runner-and-external-invitations.md b/doc/plans/2026-10-08-cloud-dot-runner-and-external-invitations.md new file mode 100644 index 00000000000..fc7d8b42667 --- /dev/null +++ b/doc/plans/2026-10-08-cloud-dot-runner-and-external-invitations.md @@ -0,0 +1,90 @@ +# Cloud Dot runners and external-agent invitations + +Date: 2026-10-08 + +Status: the live self-hosted invitation flow is implemented. The shared square picker and animated dialog now create/resume scoped invitations, preserve company approval, watch server state, and send the event test automatically. Dot driver launcher/checkpoint hooks are qualified with a real Rust process. **Cloud execution remains disabled:** the existing managed-environment and Cloud MCP guards are unchanged pending sandbox and tenant-ingress qualification. + +## Decision: remote agents use the new Runner infrastructure + +Keep Dot and future remote-agent drivers within the new Rust Runner infrastructure. A remote agent can do its thinking and computer work elsewhere while Paperclip still owns admission, assignment lifecycle, tool authorization, receipts, progress, cancellation, and completion through the same Runner contract used by other agents. + +There is also a deliberate future benefit: **we may give remote agents tools that access a Paperclip workspace. Those tools require sandbox isolation.** Keeping remote agents on the Runner infrastructure gives those future tools an established execution boundary, workspace lifecycle, and authorization path. We should not need to invent a second execution system when a remote agent gains workspace capabilities. + +Where the Runner runs and which tools the agent receives are independent decisions. Running a Runner in a sandbox does not itself grant Dot filesystem or shell access. The tool catalog and per-run grants determine that access. + +For the first cloud implementation: + +- Dot uses its own OpenAI-hosted computer. Do not expose Paperclip workspace file or command tools to it. +- Start one ordinary managed Runner execution job for an admitted assignment, using the configured cloud sandbox provider (for example, Kubernetes or Daytona). Reuse the job for that assignment's messages and tool calls. +- Do not start a new sandbox for each message or tool call. Do not require an idle, always-running sandbox just to receive Dot traffic. +- Do not run agent-provided commands on the Paperclip control-plane host. Future workspace tools execute inside the assignment's managed sandbox and require explicit capability grants. +- Keep public MCP, OAuth, subscription handling, and durable mailbox state on the control plane. These remain reachable while no Runner job is active. + +```mermaid +flowchart LR + User[Operator assigns work] --> CP[Paperclip control plane] + CP -->|admit assignment| Job[Managed sandbox: Rust Runner] + Job -->|offer, progress, receipts| CP + CP -->|MCP Events notification| Dot[Dot on OpenAI's computer] + Dot -->|MCP inbox and tool calls| CP + CP -->|authorized assignment operations| Job + Job -.->|future explicitly granted tools| Workspace[Isolated Paperclip workspace] +``` + +The control plane authenticates inbound Dot requests even when no assignment exists. Idle reads and connection checks need no sandbox. A request to start work creates a visible task and passes normal admission before launching a job. During an assignment, the control plane routes operations to its owning Runner through the durable bridge. Progress and completion return through normal Runner bookkeeping. After completion or cancellation, tear down the job according to the managed execution policy; keep the binding and mailbox. + +This preserves one lifecycle without promising that every provider performs identical work. For Dot, much of the driver coordinates a remote service. For a local coding agent, the driver also supervises a local process. Workspace access can be added later without weakening the boundary between the control plane and execution. + +## Invitation walkthrough + +Entry: **New agent → Invite an external agent → Dot / Hermes / Other**. + +The picker uses square cards matching the harness picker, with the Dot and Hermes brand marks. The shared dialog animates content-height changes without scaling text and respects reduced-motion preferences. The Dot option is governed by the standalone Dot experimental setting and its required Assistant connections (MCP) dependency in the live controller. Experimental infrastructure prerequisites belong in settings, not as a list of implementation details in this invitation. + +1. Choose **Dot**. Paperclip creates a company/agent-scoped invitation and a short-lived pairing prompt. +2. Show **Copy setup prompt**, using the shared `AgentSetupPrompt` component with the Dot mark. Tell the user to send the whole prompt to their Dot in ChatGPT. The preview remains inspectable and offers selectable text if clipboard access fails. +3. Dot follows the prompt to install or reuse the private plugin, complete scoped OAuth consent using the one-use pairing code, read its inbox, and subscribe to updates. Retain the exact user-approved plugin-creation consent wording from the existing prompt. The pairing code must remain transient and must not be logged, committed, or stored in browser persistence. +4. Paperclip watches the connection and updates three checks in place: + - **Connected to Paperclip** — the scoped OAuth/binding connection is established. + - **Task updates enabled** — the event subscription/callback is verified. + - **Test event confirmed** — Paperclip sent a readiness challenge through the event path and the paired Dot explicitly confirmed it through MCP. +5. Show **Your Dot is connected** and **Done** only after the round trip is confirmed. A successful copy, OAuth connection, or subscription alone is insufficient. + +The event delivery worker automatically issues the readiness test once the subscription is verified. It must be idempotent across refreshes/reconnects, correlate confirmation to the current binding and challenge, and never mark a replacement binding ready using an old confirmation. Use server events or bounded polling with reconnect/revalidation. UI timers are not evidence of success. + +When the event test times out, preserve completed checks and offer **Retry test event**. When the pairing code expires, automatically prepare a fresh prompt, invalidate the old prompt, and make the new one available to copy. When watching is interrupted, state that updates are paused and offer **Reconnect updates**; do not imply Dot itself disconnected. Returning to the picker must preserve a pending invitation rather than silently create duplicate agents or codes. Closing the dialog must not revoke an established connection. + +The managed invitation authorizes only the selected agent in the selected company; it does not grant operator access. OAuth scope preview and consent remain part of connecting. This flow should not require the operator to manipulate Dot's computer or manually run an event test. + +## Hermes and Other + +Hermes is a named choice with its existing brand mark. **No new Hermes protocol, tools, transport, authentication, or setup behavior is part of this work.** Hermes and Other use the same existing `buildAgentOnboardingPrompt` output, including its Hermes Gateway guidance and existing board approval/key-claim sequence. They do not show Dot's MCP event checks or claim readiness from a copied prompt. + +## Reviewable Storybook surface + +Folder: `ui/storybook/stories/external-agent-invite/`. + +- **Onboarding / External agent invitation / Journeys**: entry, picker, copy handoff, individual watched states, success, timeout/retry, expiration, interrupted updates, Hermes, Other, mobile, light theme, and long company names. +- **Onboarding / External agent invitation / Components**: picker and each controlled connection-check state. +- Interaction stories exercise copy → watched progression → success, retry without discarding completed checks, and measured intermediate heights while the modal expands and contracts. + +The shared presentation lives in `ui/src/components/new-agent/ExternalAgentInviteContent.tsx`. Storybook alone supplies timers and fixture credentials at `.example` URLs. It uses the live Dot prompt unchanged, including automatic readiness testing. The prompt optionally asks Dot to upload its own avatar using `paperclip_dot_set_avatar`; avatar availability does not block pairing. Hermes and Other reuse the production invitation builder without modifications. + +Run `pnpm --filter @paperclipai/ui storybook`, then open the journey group. Copying in the interactive Dot story advances simulated checks; the fixed-state stories remain still for inspection. These stories illustrate the live UX with simulated connection evidence; they do not prove a live cloud pairing. + +## Remaining implementation and qualification + +The live invitation controller, owner-scoped pending-invitation lookup, atomic creation, pending-code replacement, automatic event test, feature gating, and watcher are implemented. Active run controllers poll durable operation rows under their current controller generation and lease, so an operation reserved by another HTTP replica reaches its owning Runner. Idle-initiated work already uses normal admission. + +Before shipping cloud, connect Dot's qualified launcher hooks to managed job dispatch and qualify the dedicated tenant MCP ingress. Keep the present cloud restrictions until those paths are proven. The optional external launcher uses target-owned provider checkpoints and refuses recovery when identity or state is missing; it does not invent a replacement Dot thread. Preserve company isolation, approval rules, budget stops, assignment authority, and mutation receipts. Qualify real OAuth installation, event round trip, assignment execution, unsolicited Dot work, restart/reconnect, cancellation, and expired/revoked credentials against a real sandbox provider. No cloud-ready claim follows from this Storybook pass. + + +## Implemented invitation semantics + +- `POST /api/companies/:companyId/dot-invitations` finds or creates one unfinished Dot invitation for the signed-in operator. Creation holds a company row lock and commits the agent, membership, grants, approval (when required), and audit entries atomically. The fixed preset disables workspace/attachment access and periodic wakes; normal on-demand admission remains available. +- `GET` on that path returns the operator's unfinished invitation without a pairing secret. The dialog's existing binding query reports pairing/test expiry and agent approval state. +- Pairing codes stay in component memory and out of React Query's mutation results. After refresh, the UI checks current connection state and automatically creates a fresh prompt for an unfinished pairing. Expiry while the dialog is open also renews automatically; failures offer a retry without an automatic retry loop. Replacing a prompt requires the exact pending binding ID and its issuing operator; a concurrent completed OAuth connection is not revoked. +- The delivery worker creates one readiness challenge after callback verification under the binding row lock. Refreshing, reconnecting, or repeating a worker tick does not replace that challenge. An expired test needs an explicit retry. A revoked generation cannot confirm it. +- Hermes and Other share the existing external-agent invitation API and unchanged onboarding prompt. Dot is no longer a separate card in the harness picker. + +Verification: a disposable authenticated local instance exercised the natural New Agent entry, Dot prompt copy, Back, Hermes, refresh/resume, and pending-prompt replacement. Signed callback verification, nonce confirmation, scoped OAuth, actual Rust execution, duplicate receipts, and recovery have automated coverage. No real OpenAI Dot or managed cloud sandbox was connected during this implementation pass. diff --git a/doc/public-mcp.md b/doc/public-mcp.md index 87a66486427..fe266ebe0a4 100644 --- a/doc/public-mcp.md +++ b/doc/public-mcp.md @@ -205,8 +205,13 @@ Dynamic registration uses public clients, exact registered HTTPS redirect URIs (or HTTP loopback), authorization code flow, S256 PKCE and exact resource binding to the endpoint. Authorization requests expire in ten minutes; codes expire one minute after consent and are single-use. Access tokens expire in -fifteen minutes. `offline_access` issues a thirty-day rotating refresh token; -replaying a consumed refresh token revokes its entire grant. Tokens and codes +fifteen minutes. `offline_access` issues a thirty-day rotating refresh token for +personal assistant connections. Dedicated Dot agent connections instead receive +rotating refresh tokens without an inactivity expiry: they stay connected until +revoked or their agent/operator loses access. Migration `0319_heavy_captain_midlands.sql` +removes the old expiry from valid, unused Dot refresh tokens on unrevoked grants. +Expired credentials remain expired. +Replaying a consumed refresh token still revokes its entire grant. Tokens and codes are hashed at rest. `paperclip:read` is required; `paperclip:write` adds only task work and attachment mutations on direct connections. The `paperclip:configure` scope covers allowed configuration operations. One **Write all of your Paperclip diff --git a/packages/db/src/migrations/0319_heavy_captain_midlands.sql b/packages/db/src/migrations/0319_heavy_captain_midlands.sql new file mode 100644 index 00000000000..14233bbf75a --- /dev/null +++ b/packages/db/src/migrations/0319_heavy_captain_midlands.sql @@ -0,0 +1,15 @@ +ALTER TABLE "mcp_oauth_tokens" ALTER COLUMN "expires_at" DROP NOT NULL; +--> statement-breakpoint +-- Active Dot connections keep working without another consent flow. Expired +-- or consumed credentials stay invalid, revoked grants stay revoked, and +-- personal assistant connections retain their expiry. +UPDATE "mcp_oauth_tokens" AS tokens +SET "expires_at" = NULL +FROM "mcp_oauth_grants" AS grants +WHERE tokens."grant_id" = grants."id" + AND tokens."kind" = 'refresh' + AND tokens."used_at" IS NULL + AND tokens."expires_at" > now() + AND grants."purpose" = 'agent' + AND grants."resource" LIKE '%/mcp/runner' + AND grants."revoked_at" IS NULL; diff --git a/packages/db/src/migrations/meta/0314_snapshot.json b/packages/db/src/migrations/meta/0319_snapshot.json similarity index 91% rename from packages/db/src/migrations/meta/0314_snapshot.json rename to packages/db/src/migrations/meta/0319_snapshot.json index 52d8ef6d49a..8152888d270 100644 --- a/packages/db/src/migrations/meta/0314_snapshot.json +++ b/packages/db/src/migrations/meta/0319_snapshot.json @@ -1,6 +1,6 @@ { - "id": "a1aefefe-8911-4583-9c52-7c658e46e9b4", - "prevId": "adf783f2-c391-4fd5-b93a-d85e6d3c60a0", + "id": "af0b2d33-956b-4b12-8d68-8b4e14c991b2", + "prevId": "541f5e10-e2f3-44e1-b238-4d1cbfba61f2", "version": "7", "dialect": "postgresql", "tables": { @@ -64,37 +64,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "accounting_runtime_baselines_agent_id_agents_id_fk": { "name": "accounting_runtime_baselines_agent_id_agents_id_fk", "tableFrom": "accounting_runtime_baselines", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "accounting_runtime_baselines_company_id_companies_id_fk": { "name": "accounting_runtime_baselines_company_id_companies_id_fk", "tableFrom": "accounting_runtime_baselines", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -200,9 +200,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "billing_invoice_lines_company_idx": { "name": "billing_invoice_lines_company_idx", @@ -221,50 +221,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "billing_invoice_lines_company_id_companies_id_fk": { "name": "billing_invoice_lines_company_id_companies_id_fk", "tableFrom": "billing_invoice_lines", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "billing_invoice_lines_invoice_id_billing_invoices_id_fk": { "name": "billing_invoice_lines_invoice_id_billing_invoices_id_fk", "tableFrom": "billing_invoice_lines", + "tableTo": "billing_invoices", "columnsFrom": [ "invoice_id" ], - "tableTo": "billing_invoices", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "billing_invoice_lines_cost_event_id_cost_events_id_fk": { "name": "billing_invoice_lines_cost_event_id_cost_events_id_fk", "tableFrom": "billing_invoice_lines", + "tableTo": "cost_events", "columnsFrom": [ "cost_event_id" ], - "tableTo": "cost_events", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -361,24 +361,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "billing_invoices_company_id_companies_id_fk": { "name": "billing_invoices_company_id_companies_id_fk", "tableFrom": "billing_invoices", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -408,13 +408,19 @@ "name": "run_id", "type": "uuid", "primaryKey": false, - "notNull": true + "notNull": false + }, + "decision_invocation_id": { + "name": "decision_invocation_id", + "type": "uuid", + "primaryKey": false, + "notNull": false }, "agent_id": { "name": "agent_id", "type": "uuid", "primaryKey": false, - "notNull": true + "notNull": false }, "project_id": { "name": "project_id", @@ -456,6 +462,27 @@ } }, "indexes": { + "budget_reservations_decision_idx": { + "name": "budget_reservations_decision_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "decision_invocation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, "budget_reservations_run_idx": { "name": "budget_reservations_run_idx", "columns": [ @@ -473,9 +500,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "budget_reservations_active_idx": { "name": "budget_reservations_active_idx", @@ -500,57 +527,61 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"budget_reservations\".\"state\" = 'held'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "budget_reservations_company_id_companies_id_fk": { "name": "budget_reservations_company_id_companies_id_fk", "tableFrom": "budget_reservations", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "budget_reservations_run_id_heartbeat_runs_id_fk": { "name": "budget_reservations_run_id_heartbeat_runs_id_fk", "tableFrom": "budget_reservations", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "budget_reservations_agent_id_agents_id_fk": { "name": "budget_reservations_agent_id_agents_id_fk", "tableFrom": "budget_reservations", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": {}, "policies": {}, "checkConstraints": { + "budget_reservations_source_check": { + "name": "budget_reservations_source_check", + "value": "(\"budget_reservations\".\"run_id\" is not null)::int + (\"budget_reservations\".\"decision_invocation_id\" is not null)::int = 1" + }, "budget_reservations_state_check": { "name": "budget_reservations_state_check", "value": "\"budget_reservations\".\"state\" in ('held', 'settled', 'released')" @@ -673,9 +704,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cost_adjustments_event_idx": { "name": "cost_adjustments_event_idx", @@ -700,9 +731,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cost_adjustments_invoice_line_idx": { "name": "cost_adjustments_invoice_line_idx", @@ -721,50 +752,50 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "cost_adjustments_company_id_companies_id_fk": { "name": "cost_adjustments_company_id_companies_id_fk", "tableFrom": "cost_adjustments", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "cost_adjustments_cost_event_id_cost_events_id_fk": { "name": "cost_adjustments_cost_event_id_cost_events_id_fk", "tableFrom": "cost_adjustments", + "tableTo": "cost_events", "columnsFrom": [ "cost_event_id" ], - "tableTo": "cost_events", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "cost_adjustments_invoice_line_id_billing_invoice_lines_id_fk": { "name": "cost_adjustments_invoice_line_id_billing_invoice_lines_id_fk", "tableFrom": "cost_adjustments", + "tableTo": "billing_invoice_lines", "columnsFrom": [ "invoice_line_id" ], - "tableTo": "billing_invoice_lines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -876,24 +907,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "provider_billing_snapshots_company_id_companies_id_fk": { "name": "provider_billing_snapshots_company_id_companies_id_fk", "tableFrom": "provider_billing_snapshots", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -1003,9 +1034,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "run_usage_receipts_run_latest_idx": { "name": "run_usage_receipts_run_latest_idx", @@ -1030,37 +1061,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "run_usage_receipts_company_id_companies_id_fk": { "name": "run_usage_receipts_company_id_companies_id_fk", "tableFrom": "run_usage_receipts", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "run_usage_receipts_run_id_heartbeat_runs_id_fk": { "name": "run_usage_receipts_run_id_heartbeat_runs_id_fk", "tableFrom": "run_usage_receipts", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -1172,9 +1203,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "activity_log_company_agent_created_idx": { "name": "activity_log_company_agent_created_idx", @@ -1199,9 +1230,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "activity_log_company_responsible_user_created_idx": { "name": "activity_log_company_responsible_user_created_idx", @@ -1226,9 +1257,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "activity_log_run_id_idx": { "name": "activity_log_run_id_idx", @@ -1241,9 +1272,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "activity_log_entity_type_id_idx": { "name": "activity_log_entity_type_id_idx", @@ -1262,50 +1293,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "activity_log_company_id_companies_id_fk": { "name": "activity_log_company_id_companies_id_fk", "tableFrom": "activity_log", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "activity_log_agent_id_agents_id_fk": { "name": "activity_log_agent_id_agents_id_fk", "tableFrom": "activity_log", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "activity_log_run_id_heartbeat_runs_id_fk": { "name": "activity_log_run_id_heartbeat_runs_id_fk", "tableFrom": "activity_log", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -1461,9 +1492,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "adapter_auth_sessions_company_owner_adapter_active_uq": { "name": "adapter_auth_sessions_company_owner_adapter_active_uq", @@ -1488,10 +1519,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"adapter_auth_sessions\".\"status\" IN ('starting', 'waiting_for_user', 'promoting', 'awaiting_code', 'submitting')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "adapter_auth_sessions_public_session_id_uq": { "name": "adapter_auth_sessions_public_session_id_uq", @@ -1504,9 +1535,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "adapter_auth_sessions_environment_idx": { "name": "adapter_auth_sessions_environment_idx", @@ -1519,9 +1550,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "adapter_auth_sessions_expires_idx": { "name": "adapter_auth_sessions_expires_idx", @@ -1534,9 +1565,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "adapter_auth_sessions_provider_lease_idx": { "name": "adapter_auth_sessions_provider_lease_idx", @@ -1549,37 +1580,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "adapter_auth_sessions_company_id_companies_id_fk": { "name": "adapter_auth_sessions_company_id_companies_id_fk", "tableFrom": "adapter_auth_sessions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "adapter_auth_sessions_environment_id_environments_id_fk": { "name": "adapter_auth_sessions_environment_id_environments_id_fk", "tableFrom": "adapter_auth_sessions", + "tableTo": "environments", "columnsFrom": [ "environment_id" ], - "tableTo": "environments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -1667,9 +1698,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_api_keys_company_agent_idx": { "name": "agent_api_keys_company_agent_idx", @@ -1688,37 +1719,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_api_keys_agent_id_agents_id_fk": { "name": "agent_api_keys_agent_id_agents_id_fk", "tableFrom": "agent_api_keys", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "agent_api_keys_company_id_companies_id_fk": { "name": "agent_api_keys_company_id_companies_id_fk", "tableFrom": "agent_api_keys", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -1818,9 +1849,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_commentary_company_kind_created_idx": { "name": "agent_commentary_company_kind_created_idx", @@ -1845,63 +1876,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_commentary_company_id_companies_id_fk": { "name": "agent_commentary_company_id_companies_id_fk", "tableFrom": "agent_commentary", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "agent_commentary_agent_id_agents_id_fk": { "name": "agent_commentary_agent_id_agents_id_fk", "tableFrom": "agent_commentary", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "agent_commentary_run_id_heartbeat_runs_id_fk": { "name": "agent_commentary_run_id_heartbeat_runs_id_fk", "tableFrom": "agent_commentary", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "agent_commentary_issue_id_issues_id_fk": { "name": "agent_commentary_issue_id_issues_id_fk", "tableFrom": "agent_commentary", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -2014,9 +2045,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_config_revisions_agent_created_idx": { "name": "agent_config_revisions_agent_created_idx", @@ -2035,50 +2066,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_config_revisions_company_id_companies_id_fk": { "name": "agent_config_revisions_company_id_companies_id_fk", "tableFrom": "agent_config_revisions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "agent_config_revisions_agent_id_agents_id_fk": { "name": "agent_config_revisions_agent_id_agents_id_fk", "tableFrom": "agent_config_revisions", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "agent_config_revisions_created_by_agent_id_agents_id_fk": { "name": "agent_config_revisions_created_by_agent_id_agents_id_fk", "tableFrom": "agent_config_revisions", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -2140,17 +2171,17 @@ "agent_identity_keys_owner_fk": { "name": "agent_identity_keys_owner_fk", "tableFrom": "agent_identity_keys", + "tableTo": "agents", "columnsFrom": [ "company_id", "agent_id" ], - "tableTo": "agents", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -2205,33 +2236,33 @@ "agent_instruction_heads_company_id_agent_id_entry_file_revision_id_agent_instruction_revisions_company_id_agent_id_entry_file_id_fk": { "name": "agent_instruction_heads_company_id_agent_id_entry_file_revision_id_agent_instruction_revisions_company_id_agent_id_entry_file_id_fk", "tableFrom": "agent_instruction_heads", + "tableTo": "agent_instruction_revisions", "columnsFrom": [ "company_id", "agent_id", "entry_file", "revision_id" ], - "tableTo": "agent_instruction_revisions", "columnsTo": [ "company_id", "agent_id", "entry_file", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "agent_instruction_heads_identity_uq": { "name": "agent_instruction_heads_identity_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "agent_id", "entry_file" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -2377,39 +2408,39 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_instruction_revisions_company_id_agent_id_agents_company_id_id_fk": { "name": "agent_instruction_revisions_company_id_agent_id_agents_company_id_id_fk", "tableFrom": "agent_instruction_revisions", + "tableTo": "agents", "columnsFrom": [ "company_id", "agent_id" ], - "tableTo": "agents", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "agent_instruction_revisions_identity_uq": { "name": "agent_instruction_revisions_identity_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "agent_id", "entry_file", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -2569,9 +2600,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_instruction_copies_agent_idx": { "name": "agent_instruction_copies_agent_idx", @@ -2596,39 +2627,39 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_instruction_working_copies_run_id_heartbeat_runs_id_fk": { "name": "agent_instruction_working_copies_run_id_heartbeat_runs_id_fk", "tableFrom": "agent_instruction_working_copies", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "agent_instruction_working_copies_company_id_agent_id_agents_company_id_id_fk": { "name": "agent_instruction_working_copies_company_id_agent_id_agents_company_id_id_fk", "tableFrom": "agent_instruction_working_copies", + "tableTo": "agents", "columnsFrom": [ "company_id", "agent_id" ], - "tableTo": "agents", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -2712,9 +2743,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_memberships_company_user_starred_idx": { "name": "agent_memberships_company_user_starred_idx", @@ -2739,9 +2770,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_memberships_agent_idx": { "name": "agent_memberships_agent_idx", @@ -2754,9 +2785,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_memberships_company_user_agent_uq": { "name": "agent_memberships_company_user_agent_uq", @@ -2781,37 +2812,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_memberships_company_id_companies_id_fk": { "name": "agent_memberships_company_id_companies_id_fk", "tableFrom": "agent_memberships", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "agent_memberships_agent_id_agents_id_fk": { "name": "agent_memberships_agent_id_agents_id_fk", "tableFrom": "agent_memberships", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -2934,9 +2965,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_runtime_state_company_updated_idx": { "name": "agent_runtime_state_company_updated_idx", @@ -2955,37 +2986,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_runtime_state_agent_id_agents_id_fk": { "name": "agent_runtime_state_agent_id_agents_id_fk", "tableFrom": "agent_runtime_state", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "agent_runtime_state_company_id_companies_id_fk": { "name": "agent_runtime_state_company_id_companies_id_fk", "tableFrom": "agent_runtime_state", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -3099,9 +3130,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_session_goal_actions_company_status_created_idx": { "name": "agent_session_goal_actions_company_status_created_idx", @@ -3126,9 +3157,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_session_goal_actions_session_created_idx": { "name": "agent_session_goal_actions_session_created_idx", @@ -3147,37 +3178,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_session_goal_actions_company_id_companies_id_fk": { "name": "agent_session_goal_actions_company_id_companies_id_fk", "tableFrom": "agent_session_goal_actions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "agent_session_goal_actions_session_id_agent_task_sessions_id_fk": { "name": "agent_session_goal_actions_session_id_agent_task_sessions_id_fk", "tableFrom": "agent_session_goal_actions", + "tableTo": "agent_task_sessions", "columnsFrom": [ "session_id" ], - "tableTo": "agent_task_sessions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -3339,9 +3370,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_task_sessions_company_agent_updated_idx": { "name": "agent_task_sessions_company_agent_updated_idx", @@ -3366,9 +3397,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_task_sessions_company_task_updated_idx": { "name": "agent_task_sessions_company_task_updated_idx", @@ -3393,50 +3424,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_task_sessions_company_id_companies_id_fk": { "name": "agent_task_sessions_company_id_companies_id_fk", "tableFrom": "agent_task_sessions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "agent_task_sessions_agent_id_agents_id_fk": { "name": "agent_task_sessions_agent_id_agents_id_fk", "tableFrom": "agent_task_sessions", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "agent_task_sessions_last_run_id_heartbeat_runs_id_fk": { "name": "agent_task_sessions_last_run_id_heartbeat_runs_id_fk", "tableFrom": "agent_task_sessions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "last_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -3594,9 +3625,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_wakeup_requests_company_requested_idx": { "name": "agent_wakeup_requests_company_requested_idx", @@ -3615,9 +3646,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_wakeup_requests_agent_requested_idx": { "name": "agent_wakeup_requests_agent_requested_idx", @@ -3636,9 +3667,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agent_wakeup_requests_review_path_recovery_idempotency_uq": { "name": "agent_wakeup_requests_review_path_recovery_idempotency_uq", @@ -3657,10 +3688,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"agent_wakeup_requests\".\"idempotency_key\" LIKE 'issue_review_path_lost:%' AND \"agent_wakeup_requests\".\"status\" <> 'skipped'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "agent_wakeup_requests_disposition_repair_idempotency_uq": { "name": "agent_wakeup_requests_disposition_repair_idempotency_uq", @@ -3679,10 +3710,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"agent_wakeup_requests\".\"idempotency_key\" LIKE 'issue_disposition_repair:%' AND \"agent_wakeup_requests\".\"status\" <> 'skipped'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "agent_wakeup_requests_question_response_delivery_idempotency_uq": { "name": "agent_wakeup_requests_question_response_delivery_idempotency_uq", @@ -3701,10 +3732,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "(\"agent_wakeup_requests\".\"idempotency_key\" LIKE 'question-response:%' OR \"agent_wakeup_requests\".\"idempotency_key\" LIKE 'interaction:%') AND \"agent_wakeup_requests\".\"status\" NOT IN ('skipped', 'failed', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "agent_wakeup_requests_connection_intent_delivery_idempotency_uq": { "name": "agent_wakeup_requests_connection_intent_delivery_idempotency_uq", @@ -3723,10 +3754,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"agent_wakeup_requests\".\"idempotency_key\" LIKE 'connection-intent:%' AND \"agent_wakeup_requests\".\"status\" NOT IN ('skipped', 'failed', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "agent_wakeup_requests_tool_action_delivery_uq": { "name": "agent_wakeup_requests_tool_action_delivery_uq", @@ -3745,10 +3776,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"agent_wakeup_requests\".\"idempotency_key\" LIKE 'tool-action-response:%' AND \"agent_wakeup_requests\".\"status\" NOT IN ('skipped', 'failed', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "agent_wakeup_requests_chat_completion_uq": { "name": "agent_wakeup_requests_chat_completion_uq", @@ -3767,10 +3798,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"agent_wakeup_requests\".\"idempotency_key\" LIKE 'chat-completion:%'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "agent_wakeup_requests_company_payload_issue_idx": { "name": "agent_wakeup_requests_company_payload_issue_idx", @@ -3783,43 +3814,43 @@ }, { "expression": "(\"payload\" ->> 'issueId')", - "isExpression": true, "asc": true, + "isExpression": true, "nulls": "last" } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agent_wakeup_requests_company_id_companies_id_fk": { "name": "agent_wakeup_requests_company_id_companies_id_fk", "tableFrom": "agent_wakeup_requests", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "agent_wakeup_requests_agent_id_agents_id_fk": { "name": "agent_wakeup_requests_agent_id_agents_id_fk", "tableFrom": "agent_wakeup_requests", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -4012,9 +4043,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agents_company_reports_to_idx": { "name": "agents_company_reports_to_idx", @@ -4033,9 +4064,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "agents_company_default_environment_idx": { "name": "agents_company_default_environment_idx", @@ -4054,61 +4085,61 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "agents_company_id_companies_id_fk": { "name": "agents_company_id_companies_id_fk", "tableFrom": "agents", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "agents_reports_to_agents_id_fk": { "name": "agents_reports_to_agents_id_fk", "tableFrom": "agents", + "tableTo": "agents", "columnsFrom": [ "reports_to" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "agents_default_environment_id_environments_id_fk": { "name": "agents_default_environment_id_environments_id_fk", "tableFrom": "agents", + "tableTo": "environments", "columnsFrom": [ "default_environment_id" ], - "tableTo": "environments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "agents_company_id_uq": { "name": "agents_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -4194,39 +4225,39 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "ai_connection_defaults_company_id_companies_id_fk": { "name": "ai_connection_defaults_company_id_companies_id_fk", "tableFrom": "ai_connection_defaults", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_connection_defaults_company_grant_fk": { "name": "ai_connection_defaults_company_grant_fk", "tableFrom": "ai_connection_defaults", + "tableTo": "connection_grants", "columnsFrom": [ "company_id", "grant_id" ], - "tableTo": "connection_grants", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -4299,54 +4330,54 @@ "ai_connection_pools_id_tool_connections_id_fk": { "name": "ai_connection_pools_id_tool_connections_id_fk", "tableFrom": "ai_connection_pools", + "tableTo": "tool_connections", "columnsFrom": [ "id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_connection_pools_company_id_companies_id_fk": { "name": "ai_connection_pools_company_id_companies_id_fk", "tableFrom": "ai_connection_pools", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_connection_pools_company_connection_fk": { "name": "ai_connection_pools_company_connection_fk", "tableFrom": "ai_connection_pools", + "tableTo": "tool_connections", "columnsFrom": [ "company_id", "id" ], - "tableTo": "tool_connections", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "ai_connection_pools_company_id_uq": { "name": "ai_connection_pools_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -4388,43 +4419,43 @@ "ai_connection_router_cursors_pool_id_ai_connection_pools_id_fk": { "name": "ai_connection_router_cursors_pool_id_ai_connection_pools_id_fk", "tableFrom": "ai_connection_router_cursors", + "tableTo": "ai_connection_pools", "columnsFrom": [ "pool_id" ], - "tableTo": "ai_connection_pools", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_connection_router_cursors_company_id_companies_id_fk": { "name": "ai_connection_router_cursors_company_id_companies_id_fk", "tableFrom": "ai_connection_router_cursors", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_connection_router_cursors_company_pool_fk": { "name": "ai_connection_router_cursors_company_pool_fk", "tableFrom": "ai_connection_router_cursors", + "tableTo": "ai_connection_pools", "columnsFrom": [ "company_id", "pool_id" ], - "tableTo": "ai_connection_pools", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -4518,80 +4549,80 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "ai_connection_task_pins_company_id_companies_id_fk": { "name": "ai_connection_task_pins_company_id_companies_id_fk", "tableFrom": "ai_connection_task_pins", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_connection_task_pins_pool_id_ai_connection_pools_id_fk": { "name": "ai_connection_task_pins_pool_id_ai_connection_pools_id_fk", "tableFrom": "ai_connection_task_pins", + "tableTo": "ai_connection_pools", "columnsFrom": [ "pool_id" ], - "tableTo": "ai_connection_pools", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_connection_task_pins_agent_id_agents_id_fk": { "name": "ai_connection_task_pins_agent_id_agents_id_fk", "tableFrom": "ai_connection_task_pins", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_connection_task_pins_company_pool_fk": { "name": "ai_connection_task_pins_company_pool_fk", "tableFrom": "ai_connection_task_pins", + "tableTo": "ai_connection_pools", "columnsFrom": [ "company_id", "pool_id" ], - "tableTo": "ai_connection_pools", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_connection_task_pins_company_agent_fk": { "name": "ai_connection_task_pins_company_agent_fk", "tableFrom": "ai_connection_task_pins", + "tableTo": "agents", "columnsFrom": [ "company_id", "agent_id" ], - "tableTo": "agents", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -4667,39 +4698,39 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "ai_provider_defaults_company_id_companies_id_fk": { "name": "ai_provider_defaults_company_id_companies_id_fk", "tableFrom": "ai_provider_defaults", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "ai_provider_defaults_company_grant_fk": { "name": "ai_provider_defaults_company_grant_fk", "tableFrom": "ai_provider_defaults", + "tableTo": "connection_grants", "columnsFrom": [ "company_id", "grant_id" ], - "tableTo": "connection_grants", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -4840,9 +4871,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "approval_comments_approval_idx": { "name": "approval_comments_approval_idx", @@ -4855,9 +4886,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "approval_comments_approval_created_idx": { "name": "approval_comments_approval_created_idx", @@ -4876,50 +4907,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "approval_comments_company_id_companies_id_fk": { "name": "approval_comments_company_id_companies_id_fk", "tableFrom": "approval_comments", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "approval_comments_approval_id_approvals_id_fk": { "name": "approval_comments_approval_id_approvals_id_fk", "tableFrom": "approval_comments", + "tableTo": "approvals", "columnsFrom": [ "approval_id" ], - "tableTo": "approvals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "approval_comments_author_agent_id_agents_id_fk": { "name": "approval_comments_author_agent_id_agents_id_fk", "tableFrom": "approval_comments", + "tableTo": "agents", "columnsFrom": [ "author_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -5033,37 +5064,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "approvals_company_id_companies_id_fk": { "name": "approvals_company_id_companies_id_fk", "tableFrom": "approvals", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "approvals_requested_by_agent_id_agents_id_fk": { "name": "approvals_requested_by_agent_id_agents_id_fk", "tableFrom": "approvals", + "tableTo": "agents", "columnsFrom": [ "requested_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -5170,9 +5201,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "assets_company_provider_idx": { "name": "assets_company_provider_idx", @@ -5191,9 +5222,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "assets_company_object_key_uq": { "name": "assets_company_object_key_uq", @@ -5212,37 +5243,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "assets_company_id_companies_id_fk": { "name": "assets_company_id_companies_id_fk", "tableFrom": "assets", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "assets_created_by_agent_id_agents_id_fk": { "name": "assets_created_by_agent_id_agents_id_fk", "tableFrom": "assets", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -5358,24 +5389,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "account_user_id_user_id_fk": { "name": "account_user_id_user_id_fk", "tableFrom": "account", + "tableTo": "user", "columnsFrom": [ "user_id" ], - "tableTo": "user", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -5442,15 +5473,15 @@ "session_user_id_user_id_fk": { "name": "session_user_id_user_id_fk", "tableFrom": "session", + "tableTo": "user", "columnsFrom": [ "user_id" ], - "tableTo": "user", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -5631,9 +5662,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "board_api_keys_user_idx": { "name": "board_api_keys_user_idx", @@ -5646,24 +5677,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "board_api_keys_user_id_user_id_fk": { "name": "board_api_keys_user_id_user_id_fk", "tableFrom": "board_api_keys", + "tableTo": "user", "columnsFrom": [ "user_id" ], - "tableTo": "user", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -5734,9 +5765,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "browser_use_browsers_session_idx": { "name": "browser_use_browsers_session_idx", @@ -5749,37 +5780,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "browser_use_browsers_company_id_companies_id_fk": { "name": "browser_use_browsers_company_id_companies_id_fk", "tableFrom": "browser_use_browsers", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "browser_use_browsers_session_id_browser_use_sessions_id_fk": { "name": "browser_use_browsers_session_id_browser_use_sessions_id_fk", "tableFrom": "browser_use_browsers", + "tableTo": "browser_use_sessions", "columnsFrom": [ "session_id" ], - "tableTo": "browser_use_sessions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -5901,9 +5932,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "browser_use_runs_provider_uq": { "name": "browser_use_runs_provider_uq", @@ -5916,9 +5947,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "browser_use_runs_session_idx": { "name": "browser_use_runs_session_idx", @@ -5931,50 +5962,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "browser_use_runs_company_id_companies_id_fk": { "name": "browser_use_runs_company_id_companies_id_fk", "tableFrom": "browser_use_runs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "browser_use_runs_session_id_browser_use_sessions_id_fk": { "name": "browser_use_runs_session_id_browser_use_sessions_id_fk", "tableFrom": "browser_use_runs", + "tableTo": "browser_use_sessions", "columnsFrom": [ "session_id" ], - "tableTo": "browser_use_sessions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "browser_use_runs_heartbeat_run_id_heartbeat_runs_id_fk": { "name": "browser_use_runs_heartbeat_run_id_heartbeat_runs_id_fk", "tableFrom": "browser_use_runs", + "tableTo": "heartbeat_runs", "columnsFrom": [ "heartbeat_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -6107,9 +6138,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "browser_use_sessions_provider_uq": { "name": "browser_use_sessions_provider_uq", @@ -6122,76 +6153,76 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "browser_use_sessions_company_id_companies_id_fk": { "name": "browser_use_sessions_company_id_companies_id_fk", "tableFrom": "browser_use_sessions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "browser_use_sessions_issue_id_issues_id_fk": { "name": "browser_use_sessions_issue_id_issues_id_fk", "tableFrom": "browser_use_sessions", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "browser_use_sessions_agent_id_agents_id_fk": { "name": "browser_use_sessions_agent_id_agents_id_fk", "tableFrom": "browser_use_sessions", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "browser_use_sessions_connection_id_tool_connections_id_fk": { "name": "browser_use_sessions_connection_id_tool_connections_id_fk", "tableFrom": "browser_use_sessions", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "browser_use_sessions_grant_id_connection_grants_id_fk": { "name": "browser_use_sessions_grant_id_connection_grants_id_fk", "tableFrom": "browser_use_sessions", + "tableTo": "connection_grants", "columnsFrom": [ "grant_id" ], - "tableTo": "connection_grants", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -6235,28 +6266,28 @@ "browser_use_settings_grant_id_connection_grants_id_fk": { "name": "browser_use_settings_grant_id_connection_grants_id_fk", "tableFrom": "browser_use_settings", + "tableTo": "connection_grants", "columnsFrom": [ "grant_id" ], - "tableTo": "connection_grants", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "browser_use_settings_company_id_companies_id_fk": { "name": "browser_use_settings_company_id_companies_id_fk", "tableFrom": "browser_use_settings", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -6394,9 +6425,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "budget_incidents_company_scope_idx": { "name": "budget_incidents_company_scope_idx", @@ -6427,9 +6458,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "budget_incidents_policy_window_threshold_idx": { "name": "budget_incidents_policy_window_threshold_idx", @@ -6454,51 +6485,51 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"budget_incidents\".\"status\" = 'open'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "budget_incidents_company_id_companies_id_fk": { "name": "budget_incidents_company_id_companies_id_fk", "tableFrom": "budget_incidents", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "budget_incidents_policy_id_budget_policies_id_fk": { "name": "budget_incidents_policy_id_budget_policies_id_fk", "tableFrom": "budget_incidents", + "tableTo": "budget_policies", "columnsFrom": [ "policy_id" ], - "tableTo": "budget_policies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "budget_incidents_approval_id_approvals_id_fk": { "name": "budget_incidents_approval_id_approvals_id_fk", "tableFrom": "budget_incidents", + "tableTo": "approvals", "columnsFrom": [ "approval_id" ], - "tableTo": "approvals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -6669,9 +6700,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "budget_policies_company_window_idx": { "name": "budget_policies_company_window_idx", @@ -6696,9 +6727,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "budget_policies_company_scope_metric_unique_idx": { "name": "budget_policies_company_scope_metric_unique_idx", @@ -6735,24 +6766,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "budget_policies_company_id_companies_id_fk": { "name": "budget_policies_company_id_companies_id_fk", "tableFrom": "budget_policies", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -6853,9 +6884,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "built_in_managed_resources_resource_idx": { "name": "built_in_managed_resources_resource_idx", @@ -6874,9 +6905,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "built_in_managed_resources_company_bundle_resource_uq": { "name": "built_in_managed_resources_company_bundle_resource_uq", @@ -6907,24 +6938,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "built_in_managed_resources_company_id_companies_id_fk": { "name": "built_in_managed_resources_company_id_companies_id_fk", "tableFrom": "built_in_managed_resources", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -6995,9 +7026,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "case_attachments_asset_uq": { "name": "case_attachments_asset_uq", @@ -7010,50 +7041,50 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "case_attachments_company_id_companies_id_fk": { "name": "case_attachments_company_id_companies_id_fk", "tableFrom": "case_attachments", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_attachments_case_id_cases_id_fk": { "name": "case_attachments_case_id_cases_id_fk", "tableFrom": "case_attachments", + "tableTo": "cases", "columnsFrom": [ "case_id" ], - "tableTo": "cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_attachments_asset_id_assets_id_fk": { "name": "case_attachments_asset_id_assets_id_fk", "tableFrom": "case_attachments", + "tableTo": "assets", "columnsFrom": [ "asset_id" ], - "tableTo": "assets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -7136,9 +7167,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "case_documents_document_uq": { "name": "case_documents_document_uq", @@ -7151,9 +7182,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "case_documents_company_case_updated_idx": { "name": "case_documents_company_case_updated_idx", @@ -7178,50 +7209,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "case_documents_company_id_companies_id_fk": { "name": "case_documents_company_id_companies_id_fk", "tableFrom": "case_documents", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_documents_case_id_cases_id_fk": { "name": "case_documents_case_id_cases_id_fk", "tableFrom": "case_documents", + "tableTo": "cases", "columnsFrom": [ "case_id" ], - "tableTo": "cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_documents_document_id_documents_id_fk": { "name": "case_documents_document_id_documents_id_fk", "tableFrom": "case_documents", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -7323,9 +7354,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "case_events_company_case_idx": { "name": "case_events_company_case_idx", @@ -7344,50 +7375,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "case_events_company_id_companies_id_fk": { "name": "case_events_company_id_companies_id_fk", "tableFrom": "case_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_events_case_id_cases_id_fk": { "name": "case_events_case_id_cases_id_fk", "tableFrom": "case_events", + "tableTo": "cases", "columnsFrom": [ "case_id" ], - "tableTo": "cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_events_actor_agent_id_agents_id_fk": { "name": "case_events_actor_agent_id_agents_id_fk", "tableFrom": "case_events", + "tableTo": "agents", "columnsFrom": [ "actor_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -7479,9 +7510,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "case_issue_links_company_case_idx": { "name": "case_issue_links_company_case_idx", @@ -7500,9 +7531,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "case_issue_links_issue_idx": { "name": "case_issue_links_issue_idx", @@ -7515,50 +7546,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "case_issue_links_company_id_companies_id_fk": { "name": "case_issue_links_company_id_companies_id_fk", "tableFrom": "case_issue_links", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_issue_links_case_id_cases_id_fk": { "name": "case_issue_links_case_id_cases_id_fk", "tableFrom": "case_issue_links", + "tableTo": "cases", "columnsFrom": [ "case_id" ], - "tableTo": "cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_issue_links_issue_id_issues_id_fk": { "name": "case_issue_links_issue_id_issues_id_fk", "tableFrom": "case_issue_links", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -7634,9 +7665,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "case_labels_company_case_idx": { "name": "case_labels_company_case_idx", @@ -7655,9 +7686,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "case_labels_label_idx": { "name": "case_labels_label_idx", @@ -7670,50 +7701,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "case_labels_company_id_companies_id_fk": { "name": "case_labels_company_id_companies_id_fk", "tableFrom": "case_labels", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_labels_case_id_cases_id_fk": { "name": "case_labels_case_id_cases_id_fk", "tableFrom": "case_labels", + "tableTo": "cases", "columnsFrom": [ "case_id" ], - "tableTo": "cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "case_labels_label_id_labels_id_fk": { "name": "case_labels_label_id_labels_id_fk", "tableFrom": "case_labels", + "tableTo": "labels", "columnsFrom": [ "label_id" ], - "tableTo": "labels", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -7852,9 +7883,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cases_identifier_uq": { "name": "cases_identifier_uq", @@ -7867,9 +7898,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cases_company_type_key_uq": { "name": "cases_company_type_key_uq", @@ -7894,9 +7925,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cases_company_status_idx": { "name": "cases_company_status_idx", @@ -7915,9 +7946,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cases_company_type_idx": { "name": "cases_company_type_idx", @@ -7936,9 +7967,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cases_company_project_idx": { "name": "cases_company_project_idx", @@ -7957,9 +7988,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cases_parent_idx": { "name": "cases_parent_idx", @@ -7972,9 +8003,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cases_title_search_idx": { "name": "cases_title_search_idx", @@ -7988,9 +8019,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} }, "cases_identifier_search_idx": { "name": "cases_identifier_search_idx", @@ -8004,9 +8035,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} }, "cases_summary_search_idx": { "name": "cases_summary_search_idx", @@ -8020,63 +8051,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} } }, "foreignKeys": { "cases_company_id_companies_id_fk": { "name": "cases_company_id_companies_id_fk", "tableFrom": "cases", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "cases_project_id_projects_id_fk": { "name": "cases_project_id_projects_id_fk", "tableFrom": "cases", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "cases_parent_case_id_cases_id_fk": { "name": "cases_parent_case_id_cases_id_fk", "tableFrom": "cases", + "tableTo": "cases", "columnsFrom": [ "parent_case_id" ], - "tableTo": "cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "cases_created_by_agent_id_agents_id_fk": { "name": "cases_created_by_agent_id_agents_id_fk", "tableFrom": "cases", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -8196,97 +8227,97 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_actions_company_id_companies_id_fk": { "name": "chat_actions_company_id_companies_id_fk", "tableFrom": "chat_actions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_actions_delivery_id_chat_deliveries_id_fk": { "name": "chat_actions_delivery_id_chat_deliveries_id_fk", "tableFrom": "chat_actions", + "tableTo": "chat_deliveries", "columnsFrom": [ "delivery_id" ], - "tableTo": "chat_deliveries", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_actions_company_delivery_fk": { "name": "chat_actions_company_delivery_fk", "tableFrom": "chat_actions", + "tableTo": "chat_deliveries", "columnsFrom": [ "company_id", "delivery_id" ], - "tableTo": "chat_deliveries", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_actions_company_conversation_fk": { "name": "chat_actions_company_conversation_fk", "tableFrom": "chat_actions", + "tableTo": "chat_conversations", "columnsFrom": [ "company_id", "conversation_id" ], - "tableTo": "chat_conversations", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_actions_company_principal_fk": { "name": "chat_actions_company_principal_fk", "tableFrom": "chat_actions", + "tableTo": "chat_external_principals", "columnsFrom": [ "company_id", "principal_id" ], - "tableTo": "chat_external_principals", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_actions_company_endpoint_fk": { "name": "chat_actions_company_endpoint_fk", "tableFrom": "chat_actions", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -8384,54 +8415,54 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_agent_routes_company_id_companies_id_fk": { "name": "chat_agent_routes_company_id_companies_id_fk", "tableFrom": "chat_agent_routes", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_agent_routes_company_source_fk": { "name": "chat_agent_routes_company_source_fk", "tableFrom": "chat_agent_routes", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "source_endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_agent_routes_company_destination_fk": { "name": "chat_agent_routes_company_destination_fk", "tableFrom": "chat_agent_routes", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "destination_endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -8571,9 +8602,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_conversations_thread_uq": { "name": "chat_conversations_thread_uq", @@ -8604,106 +8635,106 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_conversations_company_id_companies_id_fk": { "name": "chat_conversations_company_id_companies_id_fk", "tableFrom": "chat_conversations", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_conversations_resource_id_chat_endpoint_resources_id_fk": { "name": "chat_conversations_resource_id_chat_endpoint_resources_id_fk", "tableFrom": "chat_conversations", + "tableTo": "chat_endpoint_resources", "columnsFrom": [ "resource_id" ], - "tableTo": "chat_endpoint_resources", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_conversations_issue_id_issues_id_fk": { "name": "chat_conversations_issue_id_issues_id_fk", "tableFrom": "chat_conversations", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" }, "chat_conversations_company_issue_fk": { "name": "chat_conversations_company_issue_fk", "tableFrom": "chat_conversations", + "tableTo": "issues", "columnsFrom": [ "company_id", "issue_id" ], - "tableTo": "issues", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_conversations_company_endpoint_fk": { "name": "chat_conversations_company_endpoint_fk", "tableFrom": "chat_conversations", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_conversations_company_resource_fk": { "name": "chat_conversations_company_resource_fk", "tableFrom": "chat_conversations", + "tableTo": "chat_endpoint_resources", "columnsFrom": [ "company_id", "resource_id" ], - "tableTo": "chat_endpoint_resources", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "chat_conversations_company_id_uq": { "name": "chat_conversations_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -8846,9 +8877,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_deliveries_event_uq": { "name": "chat_deliveries_event_uq", @@ -8867,9 +8898,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_deliveries_dedupe_uq": { "name": "chat_deliveries_dedupe_uq", @@ -8888,106 +8919,106 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_deliveries_company_id_companies_id_fk": { "name": "chat_deliveries_company_id_companies_id_fk", "tableFrom": "chat_deliveries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_deliveries_conversation_id_chat_conversations_id_fk": { "name": "chat_deliveries_conversation_id_chat_conversations_id_fk", "tableFrom": "chat_deliveries", + "tableTo": "chat_conversations", "columnsFrom": [ "conversation_id" ], - "tableTo": "chat_conversations", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_deliveries_principal_id_chat_external_principals_id_fk": { "name": "chat_deliveries_principal_id_chat_external_principals_id_fk", "tableFrom": "chat_deliveries", + "tableTo": "chat_external_principals", "columnsFrom": [ "principal_id" ], - "tableTo": "chat_external_principals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_deliveries_company_endpoint_fk": { "name": "chat_deliveries_company_endpoint_fk", "tableFrom": "chat_deliveries", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_deliveries_company_conversation_fk": { "name": "chat_deliveries_company_conversation_fk", "tableFrom": "chat_deliveries", + "tableTo": "chat_conversations", "columnsFrom": [ "company_id", "conversation_id" ], - "tableTo": "chat_conversations", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_deliveries_company_principal_fk": { "name": "chat_deliveries_company_principal_fk", "tableFrom": "chat_deliveries", + "tableTo": "chat_external_principals", "columnsFrom": [ "company_id", "principal_id" ], - "tableTo": "chat_external_principals", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "chat_deliveries_company_id_uq": { "name": "chat_deliveries_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -9073,9 +9104,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_endpoint_leases_expiry_idx": { "name": "chat_endpoint_leases_expiry_idx", @@ -9088,39 +9119,39 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_endpoint_leases_company_id_companies_id_fk": { "name": "chat_endpoint_leases_company_id_companies_id_fk", "tableFrom": "chat_endpoint_leases", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_endpoint_leases_company_endpoint_fk": { "name": "chat_endpoint_leases_company_endpoint_fk", "tableFrom": "chat_endpoint_leases", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -9242,9 +9273,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_endpoint_resources_external_uq": { "name": "chat_endpoint_resources_external_uq", @@ -9269,50 +9300,50 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_endpoint_resources_company_id_companies_id_fk": { "name": "chat_endpoint_resources_company_id_companies_id_fk", "tableFrom": "chat_endpoint_resources", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_endpoint_resources_company_endpoint_fk": { "name": "chat_endpoint_resources_company_endpoint_fk", "tableFrom": "chat_endpoint_resources", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "chat_endpoint_resources_company_id_uq": { "name": "chat_endpoint_resources_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -9547,9 +9578,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_endpoints_agent_idx": { "name": "chat_endpoints_agent_idx", @@ -9568,9 +9599,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_endpoints_status_idx": { "name": "chat_endpoints_status_idx", @@ -9589,9 +9620,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_endpoints_public_id_uq": { "name": "chat_endpoints_public_id_uq", @@ -9604,9 +9635,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_endpoints_agentmail_inbox_uq": { "name": "chat_endpoints_agentmail_inbox_uq", @@ -9619,10 +9650,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"chat_endpoints\".\"provider\" = 'agentmail' and \"chat_endpoints\".\"status\" != 'archived' and \"chat_endpoints\".\"bot_external_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "chat_endpoints_connection_uq": { "name": "chat_endpoints_connection_uq", @@ -9635,9 +9666,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_endpoints_live_bot_external_uq": { "name": "chat_endpoints_live_bot_external_uq", @@ -9662,10 +9693,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"chat_endpoints\".\"status\" in ('verifying', 'active', 'paused', 'attention')\n and \"chat_endpoints\".\"provider_account_id\" is not null\n and \"chat_endpoints\".\"bot_external_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "chat_endpoints_photon_number_uq": { "name": "chat_endpoints_photon_number_uq", @@ -9678,10 +9709,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"chat_endpoints\".\"provider\" = 'imessage-photon' and \"chat_endpoints\".\"status\" <> 'archived' and \"chat_endpoints\".\"bot_external_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "chat_endpoints_live_discord_bot_external_uq": { "name": "chat_endpoints_live_discord_bot_external_uq", @@ -9700,10 +9731,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"chat_endpoints\".\"provider\" = 'discord'\n and \"chat_endpoints\".\"status\" in ('verifying', 'active', 'paused', 'attention')\n and \"chat_endpoints\".\"bot_external_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "chat_endpoints_live_global_app_bot_external_uq": { "name": "chat_endpoints_live_global_app_bot_external_uq", @@ -9722,10 +9753,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"chat_endpoints\".\"provider\" in ('github', 'microsoft-teams')\n and \"chat_endpoints\".\"status\" in ('verifying', 'active', 'paused', 'attention')\n and \"chat_endpoints\".\"bot_external_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "chat_endpoints_live_bot_username_uq": { "name": "chat_endpoints_live_bot_username_uq", @@ -9750,79 +9781,79 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"chat_endpoints\".\"status\" in ('verifying', 'active', 'paused', 'attention')\n and \"chat_endpoints\".\"provider_account_id\" is not null\n and \"chat_endpoints\".\"bot_username\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "chat_endpoints_company_id_companies_id_fk": { "name": "chat_endpoints_company_id_companies_id_fk", "tableFrom": "chat_endpoints", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_endpoints_assigned_agent_id_agents_id_fk": { "name": "chat_endpoints_assigned_agent_id_agents_id_fk", "tableFrom": "chat_endpoints", + "tableTo": "agents", "columnsFrom": [ "assigned_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" }, "chat_endpoints_company_agent_fk": { "name": "chat_endpoints_company_agent_fk", "tableFrom": "chat_endpoints", + "tableTo": "agents", "columnsFrom": [ "company_id", "assigned_agent_id" ], - "tableTo": "agents", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_endpoints_company_connection_fk": { "name": "chat_endpoints_company_connection_fk", "tableFrom": "chat_endpoints", + "tableTo": "tool_connections", "columnsFrom": [ "company_id", "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "chat_endpoints_company_id_uq": { "name": "chat_endpoints_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -9958,9 +9989,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_external_principals_external_uq": { "name": "chat_external_principals_external_uq", @@ -9991,35 +10022,35 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_external_principals_company_id_companies_id_fk": { "name": "chat_external_principals_company_id_companies_id_fk", "tableFrom": "chat_external_principals", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "chat_external_principals_company_id_uq": { "name": "chat_external_principals_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -10134,9 +10165,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_identity_links_endpoint_principal_uq": { "name": "chat_identity_links_endpoint_principal_uq", @@ -10155,54 +10186,54 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_identity_links_company_id_companies_id_fk": { "name": "chat_identity_links_company_id_companies_id_fk", "tableFrom": "chat_identity_links", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_identity_links_company_endpoint_fk": { "name": "chat_identity_links_company_endpoint_fk", "tableFrom": "chat_identity_links", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_identity_links_company_principal_fk": { "name": "chat_identity_links_company_principal_fk", "tableFrom": "chat_identity_links", + "tableTo": "chat_external_principals", "columnsFrom": [ "company_id", "principal_id" ], - "tableTo": "chat_external_principals", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -10307,138 +10338,138 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_message_links_company_id_companies_id_fk": { "name": "chat_message_links_company_id_companies_id_fk", "tableFrom": "chat_message_links", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_message_links_delivery_id_chat_deliveries_id_fk": { "name": "chat_message_links_delivery_id_chat_deliveries_id_fk", "tableFrom": "chat_message_links", + "tableTo": "chat_deliveries", "columnsFrom": [ "delivery_id" ], - "tableTo": "chat_deliveries", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_message_links_publication_id_chat_publications_id_fk": { "name": "chat_message_links_publication_id_chat_publications_id_fk", "tableFrom": "chat_message_links", + "tableTo": "chat_publications", "columnsFrom": [ "publication_id" ], - "tableTo": "chat_publications", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_message_links_comment_id_issue_comments_id_fk": { "name": "chat_message_links_comment_id_issue_comments_id_fk", "tableFrom": "chat_message_links", + "tableTo": "issue_comments", "columnsFrom": [ "comment_id" ], - "tableTo": "issue_comments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_message_links_company_endpoint_fk": { "name": "chat_message_links_company_endpoint_fk", "tableFrom": "chat_message_links", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_message_links_company_delivery_fk": { "name": "chat_message_links_company_delivery_fk", "tableFrom": "chat_message_links", + "tableTo": "chat_deliveries", "columnsFrom": [ "company_id", "delivery_id" ], - "tableTo": "chat_deliveries", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_message_links_company_publication_fk": { "name": "chat_message_links_company_publication_fk", "tableFrom": "chat_message_links", + "tableTo": "chat_publications", "columnsFrom": [ "company_id", "publication_id" ], - "tableTo": "chat_publications", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_message_links_company_comment_fk": { "name": "chat_message_links_company_comment_fk", "tableFrom": "chat_message_links", + "tableTo": "issue_comments", "columnsFrom": [ "company_id", "comment_id" ], - "tableTo": "issue_comments", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_message_links_company_conversation_fk": { "name": "chat_message_links_company_conversation_fk", "tableFrom": "chat_message_links", + "tableTo": "chat_conversations", "columnsFrom": [ "company_id", "conversation_id" ], - "tableTo": "chat_conversations", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -10582,9 +10613,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_publications_work_idx": { "name": "chat_publications_work_idx", @@ -10603,9 +10634,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_publications_idempotency_uq": { "name": "chat_publications_idempotency_uq", @@ -10624,110 +10655,110 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_publications_company_id_companies_id_fk": { "name": "chat_publications_company_id_companies_id_fk", "tableFrom": "chat_publications", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_publications_issue_id_issues_id_fk": { "name": "chat_publications_issue_id_issues_id_fk", "tableFrom": "chat_publications", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" }, "chat_publications_comment_id_issue_comments_id_fk": { "name": "chat_publications_comment_id_issue_comments_id_fk", "tableFrom": "chat_publications", + "tableTo": "issue_comments", "columnsFrom": [ "comment_id" ], - "tableTo": "issue_comments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_publications_company_issue_fk": { "name": "chat_publications_company_issue_fk", "tableFrom": "chat_publications", + "tableTo": "issues", "columnsFrom": [ "company_id", "issue_id" ], - "tableTo": "issues", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_publications_company_comment_fk": { "name": "chat_publications_company_comment_fk", "tableFrom": "chat_publications", + "tableTo": "issue_comments", "columnsFrom": [ "company_id", "comment_id" ], - "tableTo": "issue_comments", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "chat_publications_company_endpoint_fk": { "name": "chat_publications_company_endpoint_fk", "tableFrom": "chat_publications", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_publications_company_conversation_fk": { "name": "chat_publications_company_conversation_fk", "tableFrom": "chat_publications", + "tableTo": "chat_conversations", "columnsFrom": [ "company_id", "conversation_id" ], - "tableTo": "chat_conversations", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -10822,9 +10853,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_sdk_state_expiry_idx": { "name": "chat_sdk_state_expiry_idx", @@ -10837,39 +10868,39 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_sdk_state_company_id_companies_id_fk": { "name": "chat_sdk_state_company_id_companies_id_fk", "tableFrom": "chat_sdk_state", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_sdk_state_company_endpoint_fk": { "name": "chat_sdk_state_company_endpoint_fk", "tableFrom": "chat_sdk_state", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -10972,9 +11003,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_completion_deliveries_pending_idx": { "name": "chat_completion_deliveries_pending_idx", @@ -10993,63 +11024,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_completion_deliveries_company_id_companies_id_fk": { "name": "chat_completion_deliveries_company_id_companies_id_fk", "tableFrom": "chat_completion_deliveries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_completion_deliveries_task_id_chat_task_handoffs_task_id_fk": { "name": "chat_completion_deliveries_task_id_chat_task_handoffs_task_id_fk", "tableFrom": "chat_completion_deliveries", + "tableTo": "chat_task_handoffs", "columnsFrom": [ "task_id" ], - "tableTo": "chat_task_handoffs", "columnsTo": [ "task_id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_completion_deliveries_target_run_id_heartbeat_runs_id_fk": { "name": "chat_completion_deliveries_target_run_id_heartbeat_runs_id_fk", "tableFrom": "chat_completion_deliveries", + "tableTo": "heartbeat_runs", "columnsFrom": [ "target_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_completion_deliveries_response_comment_id_issue_comments_id_fk": { "name": "chat_completion_deliveries_response_comment_id_issue_comments_id_fk", "tableFrom": "chat_completion_deliveries", + "tableTo": "issue_comments", "columnsFrom": [ "response_comment_id" ], - "tableTo": "issue_comments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -11118,63 +11149,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_task_handoffs_task_id_issues_id_fk": { "name": "chat_task_handoffs_task_id_issues_id_fk", "tableFrom": "chat_task_handoffs", + "tableTo": "issues", "columnsFrom": [ "task_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_task_handoffs_company_id_companies_id_fk": { "name": "chat_task_handoffs_company_id_companies_id_fk", "tableFrom": "chat_task_handoffs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_task_handoffs_conversation_id_issues_id_fk": { "name": "chat_task_handoffs_conversation_id_issues_id_fk", "tableFrom": "chat_task_handoffs", + "tableTo": "issues", "columnsFrom": [ "conversation_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_task_handoffs_agent_id_agents_id_fk": { "name": "chat_task_handoffs_agent_id_agents_id_fk", "tableFrom": "chat_task_handoffs", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -11287,17 +11318,17 @@ "chat_github_configurations_company_id_endpoint_id_chat_endpoints_company_id_id_fk": { "name": "chat_github_configurations_company_id_endpoint_id_chat_endpoints_company_id_id_fk", "tableFrom": "chat_github_configurations", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -11391,9 +11422,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_github_registration_endpoint_idx": { "name": "chat_github_registration_endpoint_idx", @@ -11412,26 +11443,26 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_github_registrations_company_id_endpoint_id_chat_endpoints_company_id_id_fk": { "name": "chat_github_registrations_company_id_endpoint_id_chat_endpoints_company_id_id_fk", "tableFrom": "chat_github_registrations", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -11611,9 +11642,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_github_reviews_pull_idx": { "name": "chat_github_reviews_pull_idx", @@ -11644,9 +11675,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_github_reviews_task_idx": { "name": "chat_github_reviews_task_idx", @@ -11671,65 +11702,65 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_github_reviews_run_id_heartbeat_runs_id_fk": { "name": "chat_github_reviews_run_id_heartbeat_runs_id_fk", "tableFrom": "chat_github_reviews", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "chat_github_reviews_company_id_endpoint_id_chat_endpoints_company_id_id_fk": { "name": "chat_github_reviews_company_id_endpoint_id_chat_endpoints_company_id_id_fk", "tableFrom": "chat_github_reviews", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_github_reviews_company_id_issue_id_issues_company_id_id_fk": { "name": "chat_github_reviews_company_id_issue_id_issues_company_id_id_fk", "tableFrom": "chat_github_reviews", + "tableTo": "issues", "columnsFrom": [ "company_id", "issue_id" ], - "tableTo": "issues", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "chat_github_reviews_company_id_uq": { "name": "chat_github_reviews_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -11745,6 +11776,139 @@ }, "isRLSEnabled": false }, + "public.chat_slack_registrations": { + "name": "chat_slack_registrations", + "schema": "", + "columns": { + "endpoint_id": { + "name": "endpoint_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "manifest": { + "name": "manifest", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "manifest_hash": { + "name": "manifest_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "callback_uri": { + "name": "callback_uri", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "app_id": { + "name": "app_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "secret_ids": { + "name": "secret_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bot_user_id": { + "name": "bot_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_code": { + "name": "error_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "chat_slack_registrations_company_id_endpoint_id_chat_endpoints_company_id_id_fk": { + "name": "chat_slack_registrations_company_id_endpoint_id_chat_endpoints_company_id_id_fk", + "tableFrom": "chat_slack_registrations", + "tableTo": "chat_endpoints", + "columnsFrom": [ + "company_id", + "endpoint_id" + ], + "columnsTo": [ + "company_id", + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "chat_slack_registration_status_check": { + "name": "chat_slack_registration_status_check", + "value": "\"chat_slack_registrations\".\"status\" in ('creating', 'uncertain', 'failed', 'install', 'credentials_saved', 'configured', 'removed')" + } + }, + "isRLSEnabled": false + }, "public.chat_teams_file_transfers": { "name": "chat_teams_file_transfers", "schema": "", @@ -11995,9 +12159,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_teams_file_transfers_token_uq": { "name": "chat_teams_file_transfers_token_uq", @@ -12016,9 +12180,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "chat_teams_file_transfers_work_idx": { "name": "chat_teams_file_transfers_work_idx", @@ -12043,97 +12207,97 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "chat_teams_file_transfers_company_id_companies_id_fk": { "name": "chat_teams_file_transfers_company_id_companies_id_fk", "tableFrom": "chat_teams_file_transfers", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_teams_file_transfers_issue_id_issues_id_fk": { "name": "chat_teams_file_transfers_issue_id_issues_id_fk", "tableFrom": "chat_teams_file_transfers", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" }, "chat_teams_file_transfers_company_id_endpoint_id_chat_endpoints_company_id_id_fk": { "name": "chat_teams_file_transfers_company_id_endpoint_id_chat_endpoints_company_id_id_fk", "tableFrom": "chat_teams_file_transfers", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_teams_file_transfers_company_id_publication_id_chat_publications_company_id_id_fk": { "name": "chat_teams_file_transfers_company_id_publication_id_chat_publications_company_id_id_fk", "tableFrom": "chat_teams_file_transfers", + "tableTo": "chat_publications", "columnsFrom": [ "company_id", "publication_id" ], - "tableTo": "chat_publications", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_teams_file_transfers_company_id_conversation_id_chat_conversations_company_id_id_fk": { "name": "chat_teams_file_transfers_company_id_conversation_id_chat_conversations_company_id_id_fk", "tableFrom": "chat_teams_file_transfers", + "tableTo": "chat_conversations", "columnsFrom": [ "company_id", "conversation_id" ], - "tableTo": "chat_conversations", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "chat_teams_file_transfers_company_id_principal_id_chat_external_principals_company_id_id_fk": { "name": "chat_teams_file_transfers_company_id_principal_id_chat_external_principals_company_id_id_fk", "tableFrom": "chat_teams_file_transfers", + "tableTo": "chat_external_principals", "columnsFrom": [ "company_id", "principal_id" ], - "tableTo": "chat_external_principals", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -12270,9 +12434,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cli_auth_challenges_approved_by_idx": { "name": "cli_auth_challenges_approved_by_idx", @@ -12285,9 +12449,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cli_auth_challenges_requested_company_idx": { "name": "cli_auth_challenges_requested_company_idx", @@ -12300,50 +12464,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "cli_auth_challenges_requested_company_id_companies_id_fk": { "name": "cli_auth_challenges_requested_company_id_companies_id_fk", "tableFrom": "cli_auth_challenges", + "tableTo": "companies", "columnsFrom": [ "requested_company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "cli_auth_challenges_approved_by_user_id_user_id_fk": { "name": "cli_auth_challenges_approved_by_user_id_user_id_fk", "tableFrom": "cli_auth_challenges", + "tableTo": "user", "columnsFrom": [ "approved_by_user_id" ], - "tableTo": "user", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "cli_auth_challenges_board_api_key_id_board_api_keys_id_fk": { "name": "cli_auth_challenges_board_api_key_id_board_api_keys_id_fk", "tableFrom": "cli_auth_challenges", + "tableTo": "board_api_keys", "columnsFrom": [ "board_api_key_id" ], - "tableTo": "board_api_keys", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -12500,9 +12664,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": {}, @@ -12562,9 +12726,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_logos_asset_uq": { "name": "company_logos_asset_uq", @@ -12577,37 +12741,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_logos_company_id_companies_id_fk": { "name": "company_logos_company_id_companies_id_fk", "tableFrom": "company_logos", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_logos_asset_id_assets_id_fk": { "name": "company_logos_asset_id_assets_id_fk", "tableFrom": "company_logos", + "tableTo": "assets", "columnsFrom": [ "asset_id" ], - "tableTo": "assets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -12697,9 +12861,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_memberships_principal_status_idx": { "name": "company_memberships_principal_status_idx", @@ -12724,9 +12888,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_memberships_company_status_idx": { "name": "company_memberships_company_status_idx", @@ -12745,24 +12909,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_memberships_company_id_companies_id_fk": { "name": "company_memberships_company_id_companies_id_fk", "tableFrom": "company_memberships", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -12876,63 +13040,63 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_onboarding_seeds_company_id_companies_id_fk": { "name": "company_onboarding_seeds_company_id_companies_id_fk", "tableFrom": "company_onboarding_seeds", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_onboarding_seeds_goal_id_goals_id_fk": { "name": "company_onboarding_seeds_goal_id_goals_id_fk", "tableFrom": "company_onboarding_seeds", + "tableTo": "goals", "columnsFrom": [ "goal_id" ], - "tableTo": "goals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_onboarding_seeds_agent_id_agents_id_fk": { "name": "company_onboarding_seeds_agent_id_agents_id_fk", "tableFrom": "company_onboarding_seeds", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_onboarding_seeds_issue_id_issues_id_fk": { "name": "company_onboarding_seeds_issue_id_issues_id_fk", "tableFrom": "company_onboarding_seeds", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -13042,9 +13206,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_bindings_secret_idx": { "name": "company_secret_bindings_secret_idx", @@ -13057,9 +13221,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_bindings_target_idx": { "name": "company_secret_bindings_target_idx", @@ -13084,9 +13248,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_bindings_target_path_uq": { "name": "company_secret_bindings_target_path_uq", @@ -13117,37 +13281,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_secret_bindings_company_id_companies_id_fk": { "name": "company_secret_bindings_company_id_companies_id_fk", "tableFrom": "company_secret_bindings", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "company_secret_bindings_secret_id_company_secrets_id_fk": { "name": "company_secret_bindings_secret_id_company_secrets_id_fk", "tableFrom": "company_secret_bindings", + "tableTo": "company_secrets", "columnsFrom": [ "secret_id" ], - "tableTo": "company_secrets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -13382,9 +13546,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_proposals_proposer_status_idx": { "name": "company_secret_proposals_proposer_status_idx", @@ -13403,9 +13567,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_proposals_expiry_idx": { "name": "company_secret_proposals_expiry_idx", @@ -13424,9 +13588,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_proposals_secret_proposal_idx": { "name": "company_secret_proposals_secret_proposal_idx", @@ -13439,9 +13603,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_proposals_interaction_idx": { "name": "company_secret_proposals_interaction_idx", @@ -13454,128 +13618,128 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_secret_proposals_company_id_companies_id_fk": { "name": "company_secret_proposals_company_id_companies_id_fk", "tableFrom": "company_secret_proposals", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "company_secret_proposals_secret_id_company_secrets_id_fk": { "name": "company_secret_proposals_secret_id_company_secrets_id_fk", "tableFrom": "company_secret_proposals", + "tableTo": "company_secrets", "columnsFrom": [ "secret_id" ], - "tableTo": "company_secrets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_secret_proposals_secret_proposal_id_company_secret_proposals_id_fk": { "name": "company_secret_proposals_secret_proposal_id_company_secret_proposals_id_fk", "tableFrom": "company_secret_proposals", + "tableTo": "company_secret_proposals", "columnsFrom": [ "secret_proposal_id" ], - "tableTo": "company_secret_proposals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_secret_proposals_target_id_agents_id_fk": { "name": "company_secret_proposals_target_id_agents_id_fk", "tableFrom": "company_secret_proposals", + "tableTo": "agents", "columnsFrom": [ "target_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_secret_proposals_proposed_by_agent_id_agents_id_fk": { "name": "company_secret_proposals_proposed_by_agent_id_agents_id_fk", "tableFrom": "company_secret_proposals", + "tableTo": "agents", "columnsFrom": [ "proposed_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_secret_proposals_origin_issue_id_issues_id_fk": { "name": "company_secret_proposals_origin_issue_id_issues_id_fk", "tableFrom": "company_secret_proposals", + "tableTo": "issues", "columnsFrom": [ "origin_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_secret_proposals_origin_run_id_heartbeat_runs_id_fk": { "name": "company_secret_proposals_origin_run_id_heartbeat_runs_id_fk", "tableFrom": "company_secret_proposals", + "tableTo": "heartbeat_runs", "columnsFrom": [ "origin_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_secret_proposals_interaction_id_issue_thread_interactions_id_fk": { "name": "company_secret_proposals_interaction_id_issue_thread_interactions_id_fk", "tableFrom": "company_secret_proposals", + "tableTo": "issue_thread_interactions", "columnsFrom": [ "interaction_id" ], - "tableTo": "issue_thread_interactions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_secret_proposals_created_secret_id_company_secrets_id_fk": { "name": "company_secret_proposals_created_secret_id_company_secrets_id_fk", "tableFrom": "company_secret_proposals", + "tableTo": "company_secrets", "columnsFrom": [ "created_secret_id" ], - "tableTo": "company_secrets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -13720,9 +13884,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_provider_configs_company_provider_idx": { "name": "company_secret_provider_configs_company_provider_idx", @@ -13741,9 +13905,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_provider_configs_default_uq": { "name": "company_secret_provider_configs_default_uq", @@ -13762,38 +13926,38 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"company_secret_provider_configs\".\"is_default\" = true", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "company_secret_provider_configs_company_id_companies_id_fk": { "name": "company_secret_provider_configs_company_id_companies_id_fk", "tableFrom": "company_secret_provider_configs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_secret_provider_configs_created_by_agent_id_agents_id_fk": { "name": "company_secret_provider_configs_created_by_agent_id_agents_id_fk", "tableFrom": "company_secret_provider_configs", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -13906,9 +14070,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_versions_value_sha256_idx": { "name": "company_secret_versions_value_sha256_idx", @@ -13921,9 +14085,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_versions_fingerprint_idx": { "name": "company_secret_versions_fingerprint_idx", @@ -13936,9 +14100,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secret_versions_secret_version_uq": { "name": "company_secret_versions_secret_version_uq", @@ -13957,37 +14121,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_secret_versions_secret_id_company_secrets_id_fk": { "name": "company_secret_versions_secret_id_company_secrets_id_fk", "tableFrom": "company_secret_versions", + "tableTo": "company_secrets", "columnsFrom": [ "secret_id" ], - "tableTo": "company_secrets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_secret_versions_created_by_agent_id_agents_id_fk": { "name": "company_secret_versions_created_by_agent_id_agents_id_fk", "tableFrom": "company_secret_versions", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -14160,9 +14324,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secrets_company_scope_idx": { "name": "company_secrets_company_scope_idx", @@ -14181,9 +14345,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secrets_company_owner_idx": { "name": "company_secrets_company_owner_idx", @@ -14202,9 +14366,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secrets_user_definition_owner_idx": { "name": "company_secrets_user_definition_owner_idx", @@ -14229,9 +14393,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secrets_company_provider_idx": { "name": "company_secrets_company_provider_idx", @@ -14250,9 +14414,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secrets_provider_config_idx": { "name": "company_secrets_provider_config_idx", @@ -14265,9 +14429,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_secrets_company_name_uq": { "name": "company_secrets_company_name_uq", @@ -14286,10 +14450,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"company_secrets\".\"scope\" = 'company' and \"company_secrets\".\"deleted_at\" is null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "company_secrets_company_key_uq": { "name": "company_secrets_company_key_uq", @@ -14308,10 +14472,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"company_secrets\".\"scope\" = 'company' and \"company_secrets\".\"deleted_at\" is null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "company_secrets_user_definition_owner_uq": { "name": "company_secrets_user_definition_owner_uq", @@ -14336,64 +14500,64 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"company_secrets\".\"scope\" = 'user' and \"company_secrets\".\"deleted_at\" is null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "company_secrets_company_id_companies_id_fk": { "name": "company_secrets_company_id_companies_id_fk", "tableFrom": "company_secrets", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "company_secrets_user_secret_definition_id_user_secret_definitions_id_fk": { "name": "company_secrets_user_secret_definition_id_user_secret_definitions_id_fk", "tableFrom": "company_secrets", + "tableTo": "user_secret_definitions", "columnsFrom": [ "user_secret_definition_id" ], - "tableTo": "user_secret_definitions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_secrets_provider_config_id_company_secret_provider_configs_id_fk": { "name": "company_secrets_provider_config_id_company_secret_provider_configs_id_fk", "tableFrom": "company_secrets", + "tableTo": "company_secret_provider_configs", "columnsFrom": [ "provider_config_id" ], - "tableTo": "company_secret_provider_configs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_secrets_created_by_agent_id_agents_id_fk": { "name": "company_secrets_created_by_agent_id_agents_id_fk", "tableFrom": "company_secrets", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -14463,15 +14627,15 @@ "company_skill_policies_company_id_companies_id_fk": { "name": "company_skill_policies_company_id_companies_id_fk", "tableFrom": "company_skill_policies", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -14572,9 +14736,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_source_entries_company_skill_idx": { "name": "company_skill_source_entries_company_skill_idx", @@ -14593,50 +14757,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_skill_source_entries_company_id_companies_id_fk": { "name": "company_skill_source_entries_company_id_companies_id_fk", "tableFrom": "company_skill_source_entries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_source_entries_source_id_company_skill_sources_id_fk": { "name": "company_skill_source_entries_source_id_company_skill_sources_id_fk", "tableFrom": "company_skill_source_entries", + "tableTo": "company_skill_sources", "columnsFrom": [ "source_id" ], - "tableTo": "company_skill_sources", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_source_entries_skill_id_company_skills_id_fk": { "name": "company_skill_source_entries_skill_id_company_skills_id_fk", "tableFrom": "company_skill_source_entries", + "tableTo": "company_skills", "columnsFrom": [ "skill_id" ], - "tableTo": "company_skills", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -14781,9 +14945,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_sources_identity_ref_idx": { "name": "company_skill_sources_identity_ref_idx", @@ -14808,37 +14972,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_skill_sources_company_id_companies_id_fk": { "name": "company_skill_sources_company_id_companies_id_fk", "tableFrom": "company_skill_sources", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_sources_connection_id_tool_connections_id_fk": { "name": "company_skill_sources_connection_id_tool_connections_id_fk", "tableFrom": "company_skill_sources", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -14939,9 +15103,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_comments_parent_idx": { "name": "company_skill_comments_parent_idx", @@ -14954,63 +15118,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_skill_comments_company_id_companies_id_fk": { "name": "company_skill_comments_company_id_companies_id_fk", "tableFrom": "company_skill_comments", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_comments_company_skill_id_company_skills_id_fk": { "name": "company_skill_comments_company_skill_id_company_skills_id_fk", "tableFrom": "company_skill_comments", + "tableTo": "company_skills", "columnsFrom": [ "company_skill_id" ], - "tableTo": "company_skills", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_comments_parent_comment_id_company_skill_comments_id_fk": { "name": "company_skill_comments_parent_comment_id_company_skill_comments_id_fk", "tableFrom": "company_skill_comments", + "tableTo": "company_skill_comments", "columnsFrom": [ "parent_comment_id" ], - "tableTo": "company_skill_comments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_skill_comments_author_agent_id_agents_id_fk": { "name": "company_skill_comments_author_agent_id_agents_id_fk", "tableFrom": "company_skill_comments", + "tableTo": "agents", "columnsFrom": [ "author_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -15080,9 +15244,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_stars_skill_user_idx": { "name": "company_skill_stars_skill_user_idx", @@ -15101,9 +15265,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_stars_company_skill_created_idx": { "name": "company_skill_stars_company_skill_created_idx", @@ -15128,50 +15292,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_skill_stars_company_id_companies_id_fk": { "name": "company_skill_stars_company_id_companies_id_fk", "tableFrom": "company_skill_stars", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_stars_company_skill_id_company_skills_id_fk": { "name": "company_skill_stars_company_skill_id_company_skills_id_fk", "tableFrom": "company_skill_stars", + "tableTo": "company_skills", "columnsFrom": [ "company_skill_id" ], - "tableTo": "company_skills", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_stars_agent_id_agents_id_fk": { "name": "company_skill_stars_agent_id_agents_id_fk", "tableFrom": "company_skill_stars", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -15266,9 +15430,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_test_inputs_company_skill_active_idx": { "name": "company_skill_test_inputs_company_skill_active_idx", @@ -15293,37 +15457,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_skill_test_inputs_company_id_companies_id_fk": { "name": "company_skill_test_inputs_company_id_companies_id_fk", "tableFrom": "company_skill_test_inputs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_test_inputs_skill_id_company_skills_id_fk": { "name": "company_skill_test_inputs_skill_id_company_skills_id_fk", "tableFrom": "company_skill_test_inputs", + "tableTo": "company_skills", "columnsFrom": [ "skill_id" ], - "tableTo": "company_skills", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -15436,50 +15600,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_skill_test_run_templates_company_id_companies_id_fk": { "name": "company_skill_test_run_templates_company_id_companies_id_fk", "tableFrom": "company_skill_test_run_templates", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_test_run_templates_created_by_agent_id_agents_id_fk": { "name": "company_skill_test_run_templates_created_by_agent_id_agents_id_fk", "tableFrom": "company_skill_test_run_templates", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_skill_test_run_templates_updated_by_agent_id_agents_id_fk": { "name": "company_skill_test_run_templates_updated_by_agent_id_agents_id_fk", "tableFrom": "company_skill_test_run_templates", + "tableTo": "agents", "columnsFrom": [ "updated_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -15669,9 +15833,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_test_runs_company_issue_idx": { "name": "company_skill_test_runs_company_issue_idx", @@ -15690,9 +15854,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_test_runs_company_input_created_idx": { "name": "company_skill_test_runs_company_input_created_idx", @@ -15717,9 +15881,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_test_runs_company_status_idx": { "name": "company_skill_test_runs_company_status_idx", @@ -15738,9 +15902,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_test_runs_company_harness_expires_idx": { "name": "company_skill_test_runs_company_harness_expires_idx", @@ -15759,89 +15923,89 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_skill_test_runs_company_id_companies_id_fk": { "name": "company_skill_test_runs_company_id_companies_id_fk", "tableFrom": "company_skill_test_runs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_test_runs_skill_id_company_skills_id_fk": { "name": "company_skill_test_runs_skill_id_company_skills_id_fk", "tableFrom": "company_skill_test_runs", + "tableTo": "company_skills", "columnsFrom": [ "skill_id" ], - "tableTo": "company_skills", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_test_runs_input_id_company_skill_test_inputs_id_fk": { "name": "company_skill_test_runs_input_id_company_skill_test_inputs_id_fk", "tableFrom": "company_skill_test_runs", + "tableTo": "company_skill_test_inputs", "columnsFrom": [ "input_id" ], - "tableTo": "company_skill_test_inputs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_skill_test_runs_skill_version_id_company_skill_versions_id_fk": { "name": "company_skill_test_runs_skill_version_id_company_skill_versions_id_fk", "tableFrom": "company_skill_test_runs", + "tableTo": "company_skill_versions", "columnsFrom": [ "skill_version_id" ], - "tableTo": "company_skill_versions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" }, "company_skill_test_runs_agent_id_agents_id_fk": { "name": "company_skill_test_runs_agent_id_agents_id_fk", "tableFrom": "company_skill_test_runs", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" }, "company_skill_test_runs_issue_id_issues_id_fk": { "name": "company_skill_test_runs_issue_id_issues_id_fk", "tableFrom": "company_skill_test_runs", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -15948,9 +16112,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skill_versions_skill_release_idx": { "name": "company_skill_versions_skill_release_idx", @@ -15969,10 +16133,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"company_skill_versions\".\"release_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "company_skill_versions_company_skill_created_idx": { "name": "company_skill_versions_company_skill_created_idx", @@ -15997,50 +16161,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_skill_versions_company_id_companies_id_fk": { "name": "company_skill_versions_company_id_companies_id_fk", "tableFrom": "company_skill_versions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_versions_company_skill_id_company_skills_id_fk": { "name": "company_skill_versions_company_skill_id_company_skills_id_fk", "tableFrom": "company_skill_versions", + "tableTo": "company_skills", "columnsFrom": [ "company_skill_id" ], - "tableTo": "company_skills", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "company_skill_versions_author_agent_id_agents_id_fk": { "name": "company_skill_versions_author_agent_id_agents_id_fk", "tableFrom": "company_skill_versions", + "tableTo": "agents", "columnsFrom": [ "author_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -16270,9 +16434,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skills_company_name_idx": { "name": "company_skills_company_name_idx", @@ -16291,9 +16455,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skills_company_folder_idx": { "name": "company_skills_company_folder_idx", @@ -16312,9 +16476,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skills_company_categories_idx": { "name": "company_skills_company_categories_idx", @@ -16327,9 +16491,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} }, "company_skills_company_sharing_scope_idx": { "name": "company_skills_company_sharing_scope_idx", @@ -16348,9 +16512,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skills_company_current_version_idx": { "name": "company_skills_company_current_version_idx", @@ -16369,9 +16533,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_skills_company_forked_from_idx": { "name": "company_skills_company_forked_from_idx", @@ -16390,76 +16554,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_skills_company_id_companies_id_fk": { "name": "company_skills_company_id_companies_id_fk", "tableFrom": "company_skills", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "company_skills_folder_id_folders_id_fk": { "name": "company_skills_folder_id_folders_id_fk", "tableFrom": "company_skills", + "tableTo": "folders", "columnsFrom": [ "folder_id" ], - "tableTo": "folders", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_skills_forked_from_skill_id_company_skills_id_fk": { "name": "company_skills_forked_from_skill_id_company_skills_id_fk", "tableFrom": "company_skills", + "tableTo": "company_skills", "columnsFrom": [ "forked_from_skill_id" ], - "tableTo": "company_skills", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_skills_forked_from_company_id_companies_id_fk": { "name": "company_skills_forked_from_company_id_companies_id_fk", "tableFrom": "company_skills", + "tableTo": "companies", "columnsFrom": [ "forked_from_company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "company_skills_current_version_id_company_skill_versions_id_fk": { "name": "company_skills_current_version_id_company_skill_versions_id_fk", "tableFrom": "company_skills", + "tableTo": "company_skill_versions", "columnsFrom": [ "current_version_id" ], - "tableTo": "company_skill_versions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -16594,9 +16758,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_transfer_runs_idempotency_direction_idx": { "name": "company_transfer_runs_idempotency_direction_idx", @@ -16615,9 +16779,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_transfer_runs_actor_status_idx": { "name": "company_transfer_runs_actor_status_idx", @@ -16636,24 +16800,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_transfer_runs_company_id_companies_id_fk": { "name": "company_transfer_runs_company_id_companies_id_fk", "tableFrom": "company_transfer_runs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -16719,9 +16883,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_user_sidebar_preferences_user_idx": { "name": "company_user_sidebar_preferences_user_idx", @@ -16734,9 +16898,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "company_user_sidebar_preferences_company_user_uq": { "name": "company_user_sidebar_preferences_company_user_uq", @@ -16755,24 +16919,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "company_user_sidebar_preferences_company_id_companies_id_fk": { "name": "company_user_sidebar_preferences_company_id_companies_id_fk", "tableFrom": "company_user_sidebar_preferences", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -16896,9 +17060,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "completion_contracts_issue_hash_uq": { "name": "completion_contracts_issue_hash_uq", @@ -16917,68 +17081,68 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "completion_contracts_company_id_companies_id_fk": { "name": "completion_contracts_company_id_companies_id_fk", "tableFrom": "completion_contracts", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "completion_contracts_issue_company_fk": { "name": "completion_contracts_issue_company_fk", "tableFrom": "completion_contracts", + "tableTo": "issues", "columnsFrom": [ "company_id", "issue_id" ], - "tableTo": "issues", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "completion_contracts_supersedes_owner_fk": { "name": "completion_contracts_supersedes_owner_fk", "tableFrom": "completion_contracts", + "tableTo": "completion_contracts", "columnsFrom": [ "company_id", "issue_id", "supersedes_contract_id" ], - "tableTo": "completion_contracts", "columnsTo": [ "company_id", "issue_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "completion_contracts_company_issue_id_uq": { "name": "completion_contracts_company_issue_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "issue_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -17116,9 +17280,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_event_deliveries_company_status_idx": { "name": "connection_event_deliveries_company_status_idx", @@ -17143,24 +17307,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "connection_event_deliveries_company_id_companies_id_fk": { "name": "connection_event_deliveries_company_id_companies_id_fk", "tableFrom": "connection_event_deliveries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -17224,37 +17388,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "connection_intent_deliveries_interaction_id_issue_thread_interactions_id_fk": { "name": "connection_intent_deliveries_interaction_id_issue_thread_interactions_id_fk", "tableFrom": "connection_intent_deliveries", + "tableTo": "issue_thread_interactions", "columnsFrom": [ "interaction_id" ], - "tableTo": "issue_thread_interactions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "connection_intent_deliveries_company_id_companies_id_fk": { "name": "connection_intent_deliveries_company_id_companies_id_fk", "tableFrom": "connection_intent_deliveries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -17284,7 +17448,20 @@ "name": "agent_id", "type": "uuid", "primaryKey": false, - "notNull": true + "notNull": false + }, + "usage_kind": { + "name": "usage_kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'agent'" + }, + "responsible_user_id": { + "name": "responsible_user_id", + "type": "text", + "primaryKey": false, + "notNull": false }, "issue_id": { "name": "issue_id", @@ -17438,9 +17615,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cost_events_provider_request_idx": { "name": "cost_events_provider_request_idx", @@ -17465,9 +17642,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cost_events_company_project_occurred_idx": { "name": "cost_events_company_project_occurred_idx", @@ -17492,9 +17669,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cost_events_unpriced_idx": { "name": "cost_events_unpriced_idx", @@ -17519,10 +17696,10 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"cost_events\".\"cost_status\" = 'unpriced' and \"cost_events\".\"billing_type\" <> 'subscription_included'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "cost_events_company_occurred_idx": { "name": "cost_events_company_occurred_idx", @@ -17541,9 +17718,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cost_events_company_agent_occurred_idx": { "name": "cost_events_company_agent_occurred_idx", @@ -17568,9 +17745,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cost_events_company_provider_occurred_idx": { "name": "cost_events_company_provider_occurred_idx", @@ -17595,9 +17772,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cost_events_company_biller_occurred_idx": { "name": "cost_events_company_biller_occurred_idx", @@ -17622,9 +17799,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "cost_events_company_heartbeat_run_idx": { "name": "cost_events_company_heartbeat_run_idx", @@ -17643,95 +17820,99 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "cost_events_company_id_companies_id_fk": { "name": "cost_events_company_id_companies_id_fk", "tableFrom": "cost_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "cost_events_agent_id_agents_id_fk": { "name": "cost_events_agent_id_agents_id_fk", "tableFrom": "cost_events", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "cost_events_issue_id_issues_id_fk": { "name": "cost_events_issue_id_issues_id_fk", "tableFrom": "cost_events", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "cost_events_project_id_projects_id_fk": { "name": "cost_events_project_id_projects_id_fk", "tableFrom": "cost_events", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "cost_events_goal_id_goals_id_fk": { "name": "cost_events_goal_id_goals_id_fk", "tableFrom": "cost_events", + "tableTo": "goals", "columnsFrom": [ "goal_id" ], - "tableTo": "goals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "cost_events_heartbeat_run_id_heartbeat_runs_id_fk": { "name": "cost_events_heartbeat_run_id_heartbeat_runs_id_fk", "tableFrom": "cost_events", + "tableTo": "heartbeat_runs", "columnsFrom": [ "heartbeat_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": {}, "policies": {}, "checkConstraints": { + "cost_events_usage_kind_check": { + "name": "cost_events_usage_kind_check", + "value": "\"cost_events\".\"usage_kind\" = 'decision' or (\"cost_events\".\"usage_kind\" = 'agent' and \"cost_events\".\"agent_id\" is not null)" + }, "cost_events_nonnegative_amounts": { "name": "cost_events_nonnegative_amounts", "value": "\"cost_events\".\"cost_cents\" >= 0 and \"cost_events\".\"input_tokens\" >= 0 and \"cost_events\".\"cached_input_tokens\" >= 0 and \"cost_events\".\"output_tokens\" >= 0" @@ -17739,6 +17920,346 @@ }, "isRLSEnabled": false }, + "public.company_decision_models": { + "name": "company_decision_models", + "schema": "", + "columns": { + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "grant_id": { + "name": "grant_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "allow_background": { + "name": "allow_background", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "company_decision_models_company_id_companies_id_fk": { + "name": "company_decision_models_company_id_companies_id_fk", + "tableFrom": "company_decision_models", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "company_decisions_configured": { + "name": "company_decisions_configured", + "value": "(\"company_decision_models\".\"connection_id\" is null) = (\"company_decision_models\".\"grant_id\" is null) and (not \"company_decision_models\".\"enabled\" or (\"company_decision_models\".\"connection_id\" is not null and \"company_decision_models\".\"provider\" is not null and \"company_decision_models\".\"model\" is not null))" + } + }, + "isRLSEnabled": false + }, + "public.decision_invocations": { + "name": "decision_invocations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "feature": { + "name": "feature", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "actor_type": { + "name": "actor_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "responsible_user_id": { + "name": "responsible_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "agent_id": { + "name": "agent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "issue_id": { + "name": "issue_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "run_id": { + "name": "run_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "identity_context_id": { + "name": "identity_context_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "connection_id": { + "name": "connection_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "grant_id": { + "name": "grant_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "question_types": { + "name": "question_types", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "error_code": { + "name": "error_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_request_id": { + "name": "provider_request_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cost_event_id": { + "name": "cost_event_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "input_tokens": { + "name": "input_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "output_tokens": { + "name": "output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "decision_invocations_company_started_idx": { + "name": "decision_invocations_company_started_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "decision_invocations_pending_idx": { + "name": "decision_invocations_pending_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"decision_invocations\".\"status\" = 'running'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "decision_invocations_cost_idx": { + "name": "decision_invocations_cost_idx", + "columns": [ + { + "expression": "cost_event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "decision_invocations_company_id_companies_id_fk": { + "name": "decision_invocations_company_id_companies_id_fk", + "tableFrom": "decision_invocations", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "decision_invocations_cost_event_id_cost_events_id_fk": { + "name": "decision_invocations_cost_event_id_cost_events_id_fk", + "tableFrom": "decision_invocations", + "tableTo": "cost_events", + "columnsFrom": [ + "cost_event_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "decision_invocations_status_check": { + "name": "decision_invocations_status_check", + "value": "\"decision_invocations\".\"status\" in ('running', 'succeeded', 'failed', 'unknown')" + } + }, + "isRLSEnabled": false + }, "public.decision_archive_notification_outbox": { "name": "decision_archive_notification_outbox", "schema": "", @@ -17863,9 +18384,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_archive_notification_outbox_pending_idx": { "name": "decision_archive_notification_outbox_pending_idx", @@ -17884,37 +18405,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_archive_notification_outbox_company_id_companies_id_fk": { "name": "decision_archive_notification_outbox_company_id_companies_id_fk", "tableFrom": "decision_archive_notification_outbox", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_archive_notification_outbox_origin_agent_id_agents_id_fk": { "name": "decision_archive_notification_outbox_origin_agent_id_agents_id_fk", "tableFrom": "decision_archive_notification_outbox", + "tableTo": "agents", "columnsFrom": [ "origin_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -18031,9 +18552,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_queue_items_company_source_idx": { "name": "decision_queue_items_company_source_idx", @@ -18058,78 +18579,78 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_queue_items_company_id_companies_id_fk": { "name": "decision_queue_items_company_id_companies_id_fk", "tableFrom": "decision_queue_items", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_queue_items_added_by_agent_id_agents_id_fk": { "name": "decision_queue_items_added_by_agent_id_agents_id_fk", "tableFrom": "decision_queue_items", + "tableTo": "agents", "columnsFrom": [ "added_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_queue_items_added_by_run_id_heartbeat_runs_id_fk": { "name": "decision_queue_items_added_by_run_id_heartbeat_runs_id_fk", "tableFrom": "decision_queue_items", + "tableTo": "heartbeat_runs", "columnsFrom": [ "added_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_queue_items_added_by_agent_api_key_id_agent_api_keys_id_fk": { "name": "decision_queue_items_added_by_agent_api_key_id_agent_api_keys_id_fk", "tableFrom": "decision_queue_items", + "tableTo": "agent_api_keys", "columnsFrom": [ "added_by_agent_api_key_id" ], - "tableTo": "agent_api_keys", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_queue_items_queue_company_fk": { "name": "decision_queue_items_queue_company_fk", "tableFrom": "decision_queue_items", + "tableTo": "decision_queues", "columnsFrom": [ "queue_id", "company_id" ], - "tableTo": "decision_queues", "columnsTo": [ "id", "company_id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -18261,9 +18782,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_queues_company_updated_idx": { "name": "decision_queues_company_updated_idx", @@ -18282,74 +18803,74 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_queues_company_id_companies_id_fk": { "name": "decision_queues_company_id_companies_id_fk", "tableFrom": "decision_queues", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_queues_created_by_agent_id_agents_id_fk": { "name": "decision_queues_created_by_agent_id_agents_id_fk", "tableFrom": "decision_queues", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_queues_created_by_run_id_heartbeat_runs_id_fk": { "name": "decision_queues_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "decision_queues", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_queues_created_by_agent_api_key_id_agent_api_keys_id_fk": { "name": "decision_queues_created_by_agent_api_key_id_agent_api_keys_id_fk", "tableFrom": "decision_queues", + "tableTo": "agent_api_keys", "columnsFrom": [ "created_by_agent_api_key_id" ], - "tableTo": "agent_api_keys", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "decision_queues_id_company_uq": { "name": "decision_queues_id_company_uq", + "nullsNotDistinct": false, "columns": [ "id", "company_id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -18496,9 +19017,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_retention_company_archived_idx": { "name": "decision_retention_company_archived_idx", @@ -18517,50 +19038,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_retention_company_id_companies_id_fk": { "name": "decision_retention_company_id_companies_id_fk", "tableFrom": "decision_retention", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_retention_archived_by_agent_id_agents_id_fk": { "name": "decision_retention_archived_by_agent_id_agents_id_fk", "tableFrom": "decision_retention", + "tableTo": "agents", "columnsFrom": [ "archived_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_retention_archived_by_run_id_heartbeat_runs_id_fk": { "name": "decision_retention_archived_by_run_id_heartbeat_runs_id_fk", "tableFrom": "decision_retention", + "tableTo": "heartbeat_runs", "columnsFrom": [ "archived_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -18703,9 +19224,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_triage_company_decide_by_idx": { "name": "decision_triage_company_decide_by_idx", @@ -18724,63 +19245,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_triage_company_id_companies_id_fk": { "name": "decision_triage_company_id_companies_id_fk", "tableFrom": "decision_triage", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_triage_set_by_agent_id_agents_id_fk": { "name": "decision_triage_set_by_agent_id_agents_id_fk", "tableFrom": "decision_triage", + "tableTo": "agents", "columnsFrom": [ "set_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_triage_set_by_run_id_heartbeat_runs_id_fk": { "name": "decision_triage_set_by_run_id_heartbeat_runs_id_fk", "tableFrom": "decision_triage", + "tableTo": "heartbeat_runs", "columnsFrom": [ "set_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_triage_set_by_agent_api_key_id_agent_api_keys_id_fk": { "name": "decision_triage_set_by_agent_api_key_id_agent_api_keys_id_fk", "tableFrom": "decision_triage", + "tableTo": "agent_api_keys", "columnsFrom": [ "set_by_agent_api_key_id" ], - "tableTo": "agent_api_keys", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -18920,9 +19441,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_triage_events_queue_created_idx": { "name": "decision_triage_events_queue_created_idx", @@ -18941,76 +19462,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_triage_events_company_id_companies_id_fk": { "name": "decision_triage_events_company_id_companies_id_fk", "tableFrom": "decision_triage_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_triage_events_queue_id_decision_queues_id_fk": { "name": "decision_triage_events_queue_id_decision_queues_id_fk", "tableFrom": "decision_triage_events", + "tableTo": "decision_queues", "columnsFrom": [ "queue_id" ], - "tableTo": "decision_queues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_triage_events_actor_agent_id_agents_id_fk": { "name": "decision_triage_events_actor_agent_id_agents_id_fk", "tableFrom": "decision_triage_events", + "tableTo": "agents", "columnsFrom": [ "actor_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_triage_events_actor_run_id_heartbeat_runs_id_fk": { "name": "decision_triage_events_actor_run_id_heartbeat_runs_id_fk", "tableFrom": "decision_triage_events", + "tableTo": "heartbeat_runs", "columnsFrom": [ "actor_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_triage_events_agent_api_key_id_agent_api_keys_id_fk": { "name": "decision_triage_events_agent_api_key_id_agent_api_keys_id_fk", "tableFrom": "decision_triage_events", + "tableTo": "agent_api_keys", "columnsFrom": [ "agent_api_key_id" ], - "tableTo": "agent_api_keys", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -19137,9 +19658,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_training_examples_issue_idx": { "name": "decision_training_examples_issue_idx", @@ -19152,9 +19673,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_training_examples_source_author_uq": { "name": "decision_training_examples_source_author_uq", @@ -19179,37 +19700,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_training_examples_company_id_companies_id_fk": { "name": "decision_training_examples_company_id_companies_id_fk", "tableFrom": "decision_training_examples", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_training_examples_issue_id_issues_id_fk": { "name": "decision_training_examples_issue_id_issues_id_fk", "tableFrom": "decision_training_examples", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -19291,63 +19812,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_bundles_company_id_companies_id_fk": { "name": "decision_bundles_company_id_companies_id_fk", "tableFrom": "decision_bundles", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_bundles_origin_agent_id_agents_id_fk": { "name": "decision_bundles_origin_agent_id_agents_id_fk", "tableFrom": "decision_bundles", + "tableTo": "agents", "columnsFrom": [ "origin_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_bundles_origin_issue_id_issues_id_fk": { "name": "decision_bundles_origin_issue_id_issues_id_fk", "tableFrom": "decision_bundles", + "tableTo": "issues", "columnsFrom": [ "origin_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_bundles_origin_run_id_heartbeat_runs_id_fk": { "name": "decision_bundles_origin_run_id_heartbeat_runs_id_fk", "tableFrom": "decision_bundles", + "tableTo": "heartbeat_runs", "columnsFrom": [ "origin_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -19441,9 +19962,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_effect_executions_target_issue_idx": { "name": "decision_effect_executions_target_issue_idx", @@ -19456,50 +19977,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_effect_executions_decision_id_decisions_id_fk": { "name": "decision_effect_executions_decision_id_decisions_id_fk", "tableFrom": "decision_effect_executions", + "tableTo": "decisions", "columnsFrom": [ "decision_id" ], - "tableTo": "decisions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_effect_executions_target_issue_id_issues_id_fk": { "name": "decision_effect_executions_target_issue_id_issues_id_fk", "tableFrom": "decision_effect_executions", + "tableTo": "issues", "columnsFrom": [ "target_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decision_effect_executions_activity_log_id_activity_log_id_fk": { "name": "decision_effect_executions_activity_log_id_activity_log_id_fk", "tableFrom": "decision_effect_executions", + "tableTo": "activity_log", "columnsFrom": [ "activity_log_id" ], - "tableTo": "activity_log", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -19543,9 +20064,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decision_target_issues_issue_idx": { "name": "decision_target_issues_issue_idx", @@ -19558,50 +20079,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "decision_target_issues_decision_id_decisions_id_fk": { "name": "decision_target_issues_decision_id_decisions_id_fk", "tableFrom": "decision_target_issues", + "tableTo": "decisions", "columnsFrom": [ "decision_id" ], - "tableTo": "decisions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_target_issues_issue_id_issues_id_fk": { "name": "decision_target_issues_issue_id_issues_id_fk", "tableFrom": "decision_target_issues", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "decision_target_issues_company_id_companies_id_fk": { "name": "decision_target_issues_company_id_companies_id_fk", "tableFrom": "decision_target_issues", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": { @@ -19803,9 +20324,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decisions_bundle_idx": { "name": "decisions_bundle_idx", @@ -19818,9 +20339,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decisions_origin_issue_idx": { "name": "decisions_origin_issue_idx", @@ -19833,9 +20354,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "decisions_company_idempotency_uq": { "name": "decisions_company_idempotency_uq", @@ -19854,77 +20375,77 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"decisions\".\"idempotency_key\" IS NOT NULL", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "decisions_company_id_companies_id_fk": { "name": "decisions_company_id_companies_id_fk", "tableFrom": "decisions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decisions_bundle_id_decision_bundles_id_fk": { "name": "decisions_bundle_id_decision_bundles_id_fk", "tableFrom": "decisions", + "tableTo": "decision_bundles", "columnsFrom": [ "bundle_id" ], - "tableTo": "decision_bundles", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "decisions_origin_agent_id_agents_id_fk": { "name": "decisions_origin_agent_id_agents_id_fk", "tableFrom": "decisions", + "tableTo": "agents", "columnsFrom": [ "origin_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decisions_origin_issue_id_issues_id_fk": { "name": "decisions_origin_issue_id_issues_id_fk", "tableFrom": "decisions", + "tableTo": "issues", "columnsFrom": [ "origin_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "decisions_origin_run_id_heartbeat_runs_id_fk": { "name": "decisions_origin_run_id_heartbeat_runs_id_fk", "tableFrom": "decisions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "origin_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -20048,9 +20569,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_anchor_snapshots_company_document_revision_idx": { "name": "document_annotation_anchor_snapshots_company_document_revision_idx", @@ -20075,76 +20596,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "document_annotation_anchor_snapshots_company_id_companies_id_fk": { "name": "document_annotation_anchor_snapshots_company_id_companies_id_fk", "tableFrom": "document_annotation_anchor_snapshots", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "document_annotation_anchor_snapshots_thread_id_document_annotation_threads_id_fk": { "name": "document_annotation_anchor_snapshots_thread_id_document_annotation_threads_id_fk", "tableFrom": "document_annotation_anchor_snapshots", + "tableTo": "document_annotation_threads", "columnsFrom": [ "thread_id" ], - "tableTo": "document_annotation_threads", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_anchor_snapshots_document_id_documents_id_fk": { "name": "document_annotation_anchor_snapshots_document_id_documents_id_fk", "tableFrom": "document_annotation_anchor_snapshots", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_anchor_snapshots_from_revision_id_document_revisions_id_fk": { "name": "document_annotation_anchor_snapshots_from_revision_id_document_revisions_id_fk", "tableFrom": "document_annotation_anchor_snapshots", + "tableTo": "document_revisions", "columnsFrom": [ "from_revision_id" ], - "tableTo": "document_revisions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "document_annotation_anchor_snapshots_to_revision_id_document_revisions_id_fk": { "name": "document_annotation_anchor_snapshots_to_revision_id_document_revisions_id_fk", "tableFrom": "document_annotation_anchor_snapshots", + "tableTo": "document_revisions", "columnsFrom": [ "to_revision_id" ], - "tableTo": "document_revisions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -20281,9 +20802,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_comments_company_issue_created_at_idx": { "name": "document_annotation_comments_company_issue_created_at_idx", @@ -20308,9 +20829,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_comments_company_routine_created_at_idx": { "name": "document_annotation_comments_company_routine_created_at_idx", @@ -20335,9 +20856,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_comments_company_case_created_at_idx": { "name": "document_annotation_comments_company_case_created_at_idx", @@ -20362,9 +20883,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_comments_company_document_created_at_idx": { "name": "document_annotation_comments_company_document_created_at_idx", @@ -20389,9 +20910,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_comments_issue_comment_idx": { "name": "document_annotation_comments_issue_comment_idx", @@ -20404,9 +20925,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_comments_body_search_idx": { "name": "document_annotation_comments_body_search_idx", @@ -20420,128 +20941,128 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} } }, "foreignKeys": { "document_annotation_comments_company_id_companies_id_fk": { "name": "document_annotation_comments_company_id_companies_id_fk", "tableFrom": "document_annotation_comments", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "document_annotation_comments_thread_id_document_annotation_threads_id_fk": { "name": "document_annotation_comments_thread_id_document_annotation_threads_id_fk", "tableFrom": "document_annotation_comments", + "tableTo": "document_annotation_threads", "columnsFrom": [ "thread_id" ], - "tableTo": "document_annotation_threads", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_comments_issue_id_issues_id_fk": { "name": "document_annotation_comments_issue_id_issues_id_fk", "tableFrom": "document_annotation_comments", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_comments_routine_id_routines_id_fk": { "name": "document_annotation_comments_routine_id_routines_id_fk", "tableFrom": "document_annotation_comments", + "tableTo": "routines", "columnsFrom": [ "routine_id" ], - "tableTo": "routines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_comments_case_id_cases_id_fk": { "name": "document_annotation_comments_case_id_cases_id_fk", "tableFrom": "document_annotation_comments", + "tableTo": "cases", "columnsFrom": [ "case_id" ], - "tableTo": "cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_comments_document_id_documents_id_fk": { "name": "document_annotation_comments_document_id_documents_id_fk", "tableFrom": "document_annotation_comments", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_comments_author_agent_id_agents_id_fk": { "name": "document_annotation_comments_author_agent_id_agents_id_fk", "tableFrom": "document_annotation_comments", + "tableTo": "agents", "columnsFrom": [ "author_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "document_annotation_comments_created_by_run_id_heartbeat_runs_id_fk": { "name": "document_annotation_comments_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "document_annotation_comments", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "document_annotation_comments_issue_comment_id_issue_comments_id_fk": { "name": "document_annotation_comments_issue_comment_id_issue_comments_id_fk", "tableFrom": "document_annotation_comments", + "tableTo": "issue_comments", "columnsFrom": [ "issue_comment_id" ], - "tableTo": "issue_comments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -20766,9 +21287,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_threads_company_issue_status_idx": { "name": "document_annotation_threads_company_issue_status_idx", @@ -20793,9 +21314,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_threads_company_routine_status_idx": { "name": "document_annotation_threads_company_routine_status_idx", @@ -20820,9 +21341,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_threads_company_case_status_idx": { "name": "document_annotation_threads_company_case_status_idx", @@ -20847,9 +21368,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_threads_company_current_revision_open_idx": { "name": "document_annotation_threads_company_current_revision_open_idx", @@ -20880,9 +21401,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_annotation_threads_company_anchor_state_idx": { "name": "document_annotation_threads_company_anchor_state_idx", @@ -20901,128 +21422,128 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "document_annotation_threads_company_id_companies_id_fk": { "name": "document_annotation_threads_company_id_companies_id_fk", "tableFrom": "document_annotation_threads", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "document_annotation_threads_issue_id_issues_id_fk": { "name": "document_annotation_threads_issue_id_issues_id_fk", "tableFrom": "document_annotation_threads", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_threads_routine_id_routines_id_fk": { "name": "document_annotation_threads_routine_id_routines_id_fk", "tableFrom": "document_annotation_threads", + "tableTo": "routines", "columnsFrom": [ "routine_id" ], - "tableTo": "routines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_threads_case_id_cases_id_fk": { "name": "document_annotation_threads_case_id_cases_id_fk", "tableFrom": "document_annotation_threads", + "tableTo": "cases", "columnsFrom": [ "case_id" ], - "tableTo": "cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_threads_document_id_documents_id_fk": { "name": "document_annotation_threads_document_id_documents_id_fk", "tableFrom": "document_annotation_threads", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_annotation_threads_original_revision_id_document_revisions_id_fk": { "name": "document_annotation_threads_original_revision_id_document_revisions_id_fk", "tableFrom": "document_annotation_threads", + "tableTo": "document_revisions", "columnsFrom": [ "original_revision_id" ], - "tableTo": "document_revisions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "document_annotation_threads_current_revision_id_document_revisions_id_fk": { "name": "document_annotation_threads_current_revision_id_document_revisions_id_fk", "tableFrom": "document_annotation_threads", + "tableTo": "document_revisions", "columnsFrom": [ "current_revision_id" ], - "tableTo": "document_revisions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "document_annotation_threads_created_by_agent_id_agents_id_fk": { "name": "document_annotation_threads_created_by_agent_id_agents_id_fk", "tableFrom": "document_annotation_threads", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "document_annotation_threads_resolved_by_agent_id_agents_id_fk": { "name": "document_annotation_threads_resolved_by_agent_id_agents_id_fk", "tableFrom": "document_annotation_threads", + "tableTo": "agents", "columnsFrom": [ "resolved_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -21110,9 +21631,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_memberships_company_user_document_uq": { "name": "document_memberships_company_user_document_uq", @@ -21137,37 +21658,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "document_memberships_company_id_companies_id_fk": { "name": "document_memberships_company_id_companies_id_fk", "tableFrom": "document_memberships", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_memberships_document_id_documents_id_fk": { "name": "document_memberships_document_id_documents_id_fk", "tableFrom": "document_memberships", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -21274,9 +21795,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "document_revisions_company_document_created_idx": { "name": "document_revisions_company_document_created_idx", @@ -21301,63 +21822,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "document_revisions_company_id_companies_id_fk": { "name": "document_revisions_company_id_companies_id_fk", "tableFrom": "document_revisions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_revisions_document_id_documents_id_fk": { "name": "document_revisions_document_id_documents_id_fk", "tableFrom": "document_revisions", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "document_revisions_created_by_agent_id_agents_id_fk": { "name": "document_revisions_created_by_agent_id_agents_id_fk", "tableFrom": "document_revisions", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "document_revisions_created_by_run_id_heartbeat_runs_id_fk": { "name": "document_revisions_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "document_revisions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -21496,9 +22017,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "documents_company_created_idx": { "name": "documents_company_created_idx", @@ -21517,9 +22038,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "documents_title_search_idx": { "name": "documents_title_search_idx", @@ -21533,9 +22054,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} }, "documents_latest_body_search_idx": { "name": "documents_latest_body_search_idx", @@ -21549,63 +22070,803 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} } }, "foreignKeys": { "documents_company_id_companies_id_fk": { "name": "documents_company_id_companies_id_fk", "tableFrom": "documents", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "documents_created_by_agent_id_agents_id_fk": { "name": "documents_created_by_agent_id_agents_id_fk", "tableFrom": "documents", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "documents_updated_by_agent_id_agents_id_fk": { "name": "documents_updated_by_agent_id_agents_id_fk", "tableFrom": "documents", + "tableTo": "agents", "columnsFrom": [ "updated_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "documents_locked_by_agent_id_agents_id_fk": { "name": "documents_locked_by_agent_id_agents_id_fk", "tableFrom": "documents", + "tableTo": "agents", "columnsFrom": [ "locked_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dot_agent_bindings": { + "name": "dot_agent_bindings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "operator_id": { + "name": "operator_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "grant_id": { + "name": "grant_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pairing'" + }, + "pairing_code_hash": { + "name": "pairing_code_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pairing_expires_at": { + "name": "pairing_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "dot_url": { + "name": "dot_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "challenge_hash": { + "name": "challenge_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "challenge_expires_at": { + "name": "challenge_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "ready_at": { + "name": "ready_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "dot_bindings_active_agent_uq": { + "name": "dot_bindings_active_agent_uq", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"dot_agent_bindings\".\"revoked_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "dot_bindings_active_grant_uq": { + "name": "dot_bindings_active_grant_uq", + "columns": [ + { + "expression": "grant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"dot_agent_bindings\".\"revoked_at\" IS NULL AND \"dot_agent_bindings\".\"grant_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "dot_bindings_pairing_code_uq": { + "name": "dot_bindings_pairing_code_uq", + "columns": [ + { + "expression": "pairing_code_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dot_agent_bindings_company_id_companies_id_fk": { + "name": "dot_agent_bindings_company_id_companies_id_fk", + "tableFrom": "dot_agent_bindings", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dot_agent_bindings_agent_id_agents_id_fk": { + "name": "dot_agent_bindings_agent_id_agents_id_fk", + "tableFrom": "dot_agent_bindings", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dot_agent_bindings_grant_id_mcp_oauth_grants_id_fk": { + "name": "dot_agent_bindings_grant_id_mcp_oauth_grants_id_fk", + "tableFrom": "dot_agent_bindings", + "tableTo": "mcp_oauth_grants", + "columnsFrom": [ + "grant_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dot_mailbox_items": { + "name": "dot_mailbox_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "binding_id": { + "name": "binding_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "binding_generation": { + "name": "binding_generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "assignment_id": { + "name": "assignment_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_event_id": { + "name": "source_event_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "references": { + "name": "references", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "dot_mailbox_event_uq": { + "name": "dot_mailbox_event_uq", + "columns": [ + { + "expression": "binding_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "binding_generation", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dot_mailbox_binding_cursor_idx": { + "name": "dot_mailbox_binding_cursor_idx", + "columns": [ + { + "expression": "binding_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "binding_generation", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dot_mailbox_items_company_id_companies_id_fk": { + "name": "dot_mailbox_items_company_id_companies_id_fk", + "tableFrom": "dot_mailbox_items", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dot_mailbox_items_binding_id_dot_agent_bindings_id_fk": { + "name": "dot_mailbox_items_binding_id_dot_agent_bindings_id_fk", + "tableFrom": "dot_mailbox_items", + "tableTo": "dot_agent_bindings", + "columnsFrom": [ + "binding_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dot_mailbox_items_assignment_id_dot_runner_assignments_id_fk": { + "name": "dot_mailbox_items_assignment_id_dot_runner_assignments_id_fk", + "tableFrom": "dot_mailbox_items", + "tableTo": "dot_runner_assignments", + "columnsFrom": [ + "assignment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dot_runner_assignments": { + "name": "dot_runner_assignments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "binding_id": { + "name": "binding_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "binding_generation": { + "name": "binding_generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "normalized_session_id": { + "name": "normalized_session_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "turn_id": { + "name": "turn_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "controller_generation": { + "name": "controller_generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "catalog_digest": { + "name": "catalog_digest", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "projection": { + "name": "projection", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "accept_by": { + "name": "accept_by", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "settled_at": { + "name": "settled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_activity_at": { + "name": "last_activity_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "dot_assignments_turn_uq": { + "name": "dot_assignments_turn_uq", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "turn_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "dot_assignments_active_binding_uq": { + "name": "dot_assignments_active_binding_uq", + "columns": [ + { + "expression": "binding_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"dot_runner_assignments\".\"status\" IN ('offered', 'accepted')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "dot_assignments_company_idx": { + "name": "dot_assignments_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dot_runner_assignments_company_id_companies_id_fk": { + "name": "dot_runner_assignments_company_id_companies_id_fk", + "tableFrom": "dot_runner_assignments", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dot_runner_assignments_binding_id_dot_agent_bindings_id_fk": { + "name": "dot_runner_assignments_binding_id_dot_agent_bindings_id_fk", + "tableFrom": "dot_runner_assignments", + "tableTo": "dot_agent_bindings", + "columnsFrom": [ + "binding_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dot_runner_assignments_run_id_heartbeat_runs_id_fk": { + "name": "dot_runner_assignments_run_id_heartbeat_runs_id_fk", + "tableFrom": "dot_runner_assignments", + "tableTo": "heartbeat_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dot_runner_assignments_agent_id_agents_id_fk": { + "name": "dot_runner_assignments_agent_id_agents_id_fk", + "tableFrom": "dot_runner_assignments", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.dot_runner_operations": { + "name": "dot_runner_operations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "assignment_id": { + "name": "assignment_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "digest": { + "name": "digest", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "command": { + "name": "command", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'reserved'" + }, + "outcome": { + "name": "outcome", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "source_event_id": { + "name": "source_event_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "dot_operations_request_uq": { + "name": "dot_operations_request_uq", + "columns": [ + { + "expression": "assignment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "dot_runner_operations_company_id_companies_id_fk": { + "name": "dot_runner_operations_company_id_companies_id_fk", + "tableFrom": "dot_runner_operations", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "dot_runner_operations_assignment_id_dot_runner_assignments_id_fk": { + "name": "dot_runner_operations_assignment_id_dot_runner_assignments_id_fk", + "tableFrom": "dot_runner_operations", + "tableTo": "dot_runner_assignments", + "columnsFrom": [ + "assignment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -21672,17 +22933,17 @@ "email_endpoints_company_id_endpoint_id_chat_endpoints_company_id_id_fk": { "name": "email_endpoints_company_id_endpoint_id_chat_endpoints_company_id_id_fk", "tableFrom": "email_endpoints", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -21795,9 +23056,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "email_messages_conversation_idx": { "name": "email_messages_conversation_idx", @@ -21822,41 +23083,41 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "email_messages_company_id_endpoint_id_chat_endpoints_company_id_id_fk": { "name": "email_messages_company_id_endpoint_id_chat_endpoints_company_id_id_fk", "tableFrom": "email_messages", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "email_messages_company_id_conversation_id_chat_conversations_company_id_id_fk": { "name": "email_messages_company_id_conversation_id_chat_conversations_company_id_id_fk", "tableFrom": "email_messages", + "tableTo": "chat_conversations", "columnsFrom": [ "company_id", "conversation_id" ], - "tableTo": "chat_conversations", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -21942,42 +23203,42 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"email_sends\".\"outcome\" in ('queued', 'uncertain')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "email_sends_company_id_endpoint_id_chat_endpoints_company_id_id_fk": { "name": "email_sends_company_id_endpoint_id_chat_endpoints_company_id_id_fk", "tableFrom": "email_sends", + "tableTo": "chat_endpoints", "columnsFrom": [ "company_id", "endpoint_id" ], - "tableTo": "chat_endpoints", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "email_sends_company_id_publication_id_chat_publications_company_id_id_fk": { "name": "email_sends_company_id_publication_id_chat_publications_company_id_id_fk", "tableFrom": "email_sends", + "tableTo": "chat_publications", "columnsFrom": [ "company_id", "publication_id" ], - "tableTo": "chat_publications", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -22132,9 +23393,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_custom_image_setup_sessions_environment_active_uq": { "name": "environment_custom_image_setup_sessions_environment_active_uq", @@ -22147,10 +23408,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"environment_custom_image_setup_sessions\".\"status\" IN ('starting', 'waiting_for_user', 'capturing')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "environment_custom_image_setup_sessions_template_idx": { "name": "environment_custom_image_setup_sessions_template_idx", @@ -22163,9 +23424,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_custom_image_setup_sessions_promoted_template_idx": { "name": "environment_custom_image_setup_sessions_promoted_template_idx", @@ -22178,9 +23439,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_custom_image_setup_sessions_expires_idx": { "name": "environment_custom_image_setup_sessions_expires_idx", @@ -22193,9 +23454,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_custom_image_setup_sessions_provider_lease_idx": { "name": "environment_custom_image_setup_sessions_provider_lease_idx", @@ -22214,76 +23475,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "environment_custom_image_setup_sessions_environment_id_environments_id_fk": { "name": "environment_custom_image_setup_sessions_environment_id_environments_id_fk", "tableFrom": "environment_custom_image_setup_sessions", + "tableTo": "environments", "columnsFrom": [ "environment_id" ], - "tableTo": "environments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "environment_custom_image_setup_sessions_template_id_environment_custom_image_templates_id_fk": { "name": "environment_custom_image_setup_sessions_template_id_environment_custom_image_templates_id_fk", "tableFrom": "environment_custom_image_setup_sessions", + "tableTo": "environment_custom_image_templates", "columnsFrom": [ "template_id" ], - "tableTo": "environment_custom_image_templates", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "environment_custom_image_setup_sessions_promoted_template_id_environment_custom_image_templates_id_fk": { "name": "environment_custom_image_setup_sessions_promoted_template_id_environment_custom_image_templates_id_fk", "tableFrom": "environment_custom_image_setup_sessions", + "tableTo": "environment_custom_image_templates", "columnsFrom": [ "promoted_template_id" ], - "tableTo": "environment_custom_image_templates", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "environment_custom_image_setup_sessions_environment_lease_id_environment_leases_id_fk": { "name": "environment_custom_image_setup_sessions_environment_lease_id_environment_leases_id_fk", "tableFrom": "environment_custom_image_setup_sessions", + "tableTo": "environment_leases", "columnsFrom": [ "environment_lease_id" ], - "tableTo": "environment_leases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "environment_custom_image_setup_sessions_started_by_agent_id_agents_id_fk": { "name": "environment_custom_image_setup_sessions_started_by_agent_id_agents_id_fk", "tableFrom": "environment_custom_image_setup_sessions", + "tableTo": "agents", "columnsFrom": [ "started_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -22416,9 +23677,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_custom_image_templates_environment_provider_status_idx": { "name": "environment_custom_image_templates_environment_provider_status_idx", @@ -22443,9 +23704,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_custom_image_templates_environment_active_uq": { "name": "environment_custom_image_templates_environment_active_uq", @@ -22458,10 +23719,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"environment_custom_image_templates\".\"status\" = 'active'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "environment_custom_image_templates_superseded_by_idx": { "name": "environment_custom_image_templates_superseded_by_idx", @@ -22474,9 +23735,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_custom_image_templates_last_used_idx": { "name": "environment_custom_image_templates_last_used_idx", @@ -22489,50 +23750,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "environment_custom_image_templates_environment_id_environments_id_fk": { "name": "environment_custom_image_templates_environment_id_environments_id_fk", "tableFrom": "environment_custom_image_templates", + "tableTo": "environments", "columnsFrom": [ "environment_id" ], - "tableTo": "environments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "environment_custom_image_templates_created_by_agent_id_agents_id_fk": { "name": "environment_custom_image_templates_created_by_agent_id_agents_id_fk", "tableFrom": "environment_custom_image_templates", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "environment_custom_image_templates_superseded_by_template_id_environment_custom_image_templates_id_fk": { "name": "environment_custom_image_templates_superseded_by_template_id_environment_custom_image_templates_id_fk", "tableFrom": "environment_custom_image_templates", + "tableTo": "environment_custom_image_templates", "columnsFrom": [ "superseded_by_template_id" ], - "tableTo": "environment_custom_image_templates", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -22691,9 +23952,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_leases_company_execution_workspace_idx": { "name": "environment_leases_company_execution_workspace_idx", @@ -22712,9 +23973,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_leases_company_issue_idx": { "name": "environment_leases_company_issue_idx", @@ -22733,9 +23994,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_leases_heartbeat_run_idx": { "name": "environment_leases_heartbeat_run_idx", @@ -22748,9 +24009,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_leases_company_last_used_idx": { "name": "environment_leases_company_last_used_idx", @@ -22769,9 +24030,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environment_leases_provider_lease_idx": { "name": "environment_leases_provider_lease_idx", @@ -22784,76 +24045,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "environment_leases_company_id_companies_id_fk": { "name": "environment_leases_company_id_companies_id_fk", "tableFrom": "environment_leases", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "environment_leases_environment_id_environments_id_fk": { "name": "environment_leases_environment_id_environments_id_fk", "tableFrom": "environment_leases", + "tableTo": "environments", "columnsFrom": [ "environment_id" ], - "tableTo": "environments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "environment_leases_execution_workspace_id_execution_workspaces_id_fk": { "name": "environment_leases_execution_workspace_id_execution_workspaces_id_fk", "tableFrom": "environment_leases", + "tableTo": "execution_workspaces", "columnsFrom": [ "execution_workspace_id" ], - "tableTo": "execution_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "environment_leases_issue_id_issues_id_fk": { "name": "environment_leases_issue_id_issues_id_fk", "tableFrom": "environment_leases", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "environment_leases_heartbeat_run_id_heartbeat_runs_id_fk": { "name": "environment_leases_heartbeat_run_id_heartbeat_runs_id_fk", "tableFrom": "environment_leases", + "tableTo": "heartbeat_runs", "columnsFrom": [ "heartbeat_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -22946,9 +24207,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "environments_local_driver_idx": { "name": "environments_local_driver_idx", @@ -22961,10 +24222,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"environments\".\"driver\" = 'local'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "environments_managed_sandbox_idx": { "name": "environments_managed_sandbox_idx", @@ -22977,10 +24238,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"environments\".\"driver\" = 'sandbox' AND (\"environments\".\"metadata\" ->> 'managedByPaperclip')::boolean = true", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "environments_name_idx": { "name": "environments_name_idx", @@ -22993,9 +24254,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": {}, @@ -23117,9 +24378,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "execution_workspace_runtime_leases_company_owner_idx": { "name": "execution_workspace_runtime_leases_company_owner_idx", @@ -23138,9 +24399,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "execution_workspace_runtime_leases_expires_at_idx": { "name": "execution_workspace_runtime_leases_expires_at_idx", @@ -23153,86 +24414,86 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "execution_workspace_runtime_leases_company_id_companies_id_fk": { "name": "execution_workspace_runtime_leases_company_id_companies_id_fk", "tableFrom": "execution_workspace_runtime_leases", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "execution_workspace_runtime_leases_execution_workspace_id_execution_workspaces_id_fk": { "name": "execution_workspace_runtime_leases_execution_workspace_id_execution_workspaces_id_fk", "tableFrom": "execution_workspace_runtime_leases", + "tableTo": "execution_workspaces", "columnsFrom": [ "execution_workspace_id" ], - "tableTo": "execution_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "execution_workspace_runtime_leases_owner_issue_id_issues_id_fk": { "name": "execution_workspace_runtime_leases_owner_issue_id_issues_id_fk", "tableFrom": "execution_workspace_runtime_leases", + "tableTo": "issues", "columnsFrom": [ "owner_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "execution_workspace_runtime_leases_owner_run_id_heartbeat_runs_id_fk": { "name": "execution_workspace_runtime_leases_owner_run_id_heartbeat_runs_id_fk", "tableFrom": "execution_workspace_runtime_leases", + "tableTo": "heartbeat_runs", "columnsFrom": [ "owner_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "execution_workspace_runtime_leases_owner_agent_id_agents_id_fk": { "name": "execution_workspace_runtime_leases_owner_agent_id_agents_id_fk", "tableFrom": "execution_workspace_runtime_leases", + "tableTo": "agents", "columnsFrom": [ "owner_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "execution_workspace_runtime_leases_execution_workspace_id_unique": { "name": "execution_workspace_runtime_leases_execution_workspace_id_unique", + "nullsNotDistinct": false, "columns": [ "execution_workspace_id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -23419,9 +24680,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "execution_workspaces_company_project_workspace_status_idx": { "name": "execution_workspaces_company_project_workspace_status_idx", @@ -23446,9 +24707,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "execution_workspaces_company_source_issue_idx": { "name": "execution_workspaces_company_source_issue_idx", @@ -23467,9 +24728,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "execution_workspaces_company_last_used_idx": { "name": "execution_workspaces_company_last_used_idx", @@ -23488,9 +24749,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "execution_workspaces_company_branch_idx": { "name": "execution_workspaces_company_branch_idx", @@ -23509,76 +24770,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "execution_workspaces_company_id_companies_id_fk": { "name": "execution_workspaces_company_id_companies_id_fk", "tableFrom": "execution_workspaces", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "execution_workspaces_project_id_projects_id_fk": { "name": "execution_workspaces_project_id_projects_id_fk", "tableFrom": "execution_workspaces", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "execution_workspaces_project_workspace_id_project_workspaces_id_fk": { "name": "execution_workspaces_project_workspace_id_project_workspaces_id_fk", "tableFrom": "execution_workspaces", + "tableTo": "project_workspaces", "columnsFrom": [ "project_workspace_id" ], - "tableTo": "project_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "execution_workspaces_source_issue_id_issues_id_fk": { "name": "execution_workspaces_source_issue_id_issues_id_fk", "tableFrom": "execution_workspaces", + "tableTo": "issues", "columnsFrom": [ "source_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "execution_workspaces_derived_from_execution_workspace_id_execution_workspaces_id_fk": { "name": "execution_workspaces_derived_from_execution_workspace_id_execution_workspaces_id_fk", "tableFrom": "execution_workspaces", + "tableTo": "execution_workspaces", "columnsFrom": [ "derived_from_execution_workspace_id" ], - "tableTo": "execution_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -23728,9 +24989,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "external_object_mentions_company_object_idx": { "name": "external_object_mentions_company_object_idx", @@ -23749,9 +25010,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "external_object_mentions_company_provider_idx": { "name": "external_object_mentions_company_provider_idx", @@ -23776,9 +25037,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "external_object_mentions_company_source_record_uq": { "name": "external_object_mentions_company_source_record_uq", @@ -23827,10 +25088,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"external_object_mentions\".\"source_record_id\" is not null and \"external_object_mentions\".\"canonical_identity_hash\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "external_object_mentions_company_source_null_record_uq": { "name": "external_object_mentions_company_source_null_record_uq", @@ -23873,64 +25134,64 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"external_object_mentions\".\"source_record_id\" is null and \"external_object_mentions\".\"canonical_identity_hash\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "external_object_mentions_company_id_companies_id_fk": { "name": "external_object_mentions_company_id_companies_id_fk", "tableFrom": "external_object_mentions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "external_object_mentions_source_issue_id_issues_id_fk": { "name": "external_object_mentions_source_issue_id_issues_id_fk", "tableFrom": "external_object_mentions", + "tableTo": "issues", "columnsFrom": [ "source_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "external_object_mentions_object_id_external_objects_id_fk": { "name": "external_object_mentions_object_id_external_objects_id_fk", "tableFrom": "external_object_mentions", + "tableTo": "external_objects", "columnsFrom": [ "object_id" ], - "tableTo": "external_objects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "external_object_mentions_created_by_plugin_id_plugins_id_fk": { "name": "external_object_mentions_created_by_plugin_id_plugins_id_fk", "tableFrom": "external_object_mentions", + "tableTo": "plugins", "columnsFrom": [ "created_by_plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -24162,9 +25423,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "external_objects_company_provider_status_idx": { "name": "external_objects_company_provider_status_idx", @@ -24189,9 +25450,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "external_objects_company_refresh_idx": { "name": "external_objects_company_refresh_idx", @@ -24210,9 +25471,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "external_objects_company_external_id_uq": { "name": "external_objects_company_external_id_uq", @@ -24243,9 +25504,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "external_objects_company_identity_uq": { "name": "external_objects_company_identity_uq", @@ -24276,37 +25537,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "external_objects_company_id_companies_id_fk": { "name": "external_objects_company_id_companies_id_fk", "tableFrom": "external_objects", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "external_objects_plugin_id_plugins_id_fk": { "name": "external_objects_plugin_id_plugins_id_fk", "tableFrom": "external_objects", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -24496,9 +25757,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "feedback_exports_company_created_idx": { "name": "feedback_exports_company_created_idx", @@ -24517,9 +25778,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "feedback_exports_company_status_idx": { "name": "feedback_exports_company_status_idx", @@ -24544,9 +25805,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "feedback_exports_company_issue_idx": { "name": "feedback_exports_company_issue_idx", @@ -24571,9 +25832,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "feedback_exports_company_project_idx": { "name": "feedback_exports_company_project_idx", @@ -24598,9 +25859,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "feedback_exports_company_author_idx": { "name": "feedback_exports_company_author_idx", @@ -24625,63 +25886,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "feedback_exports_company_id_companies_id_fk": { "name": "feedback_exports_company_id_companies_id_fk", "tableFrom": "feedback_exports", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "feedback_exports_feedback_vote_id_feedback_votes_id_fk": { "name": "feedback_exports_feedback_vote_id_feedback_votes_id_fk", "tableFrom": "feedback_exports", + "tableTo": "feedback_votes", "columnsFrom": [ "feedback_vote_id" ], - "tableTo": "feedback_votes", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "feedback_exports_issue_id_issues_id_fk": { "name": "feedback_exports_issue_id_issues_id_fk", "tableFrom": "feedback_exports", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "feedback_exports_project_id_projects_id_fk": { "name": "feedback_exports_project_id_projects_id_fk", "tableFrom": "feedback_exports", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -24801,9 +26062,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "feedback_votes_issue_target_idx": { "name": "feedback_votes_issue_target_idx", @@ -24828,9 +26089,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "feedback_votes_author_idx": { "name": "feedback_votes_author_idx", @@ -24849,9 +26110,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "feedback_votes_company_target_author_idx": { "name": "feedback_votes_company_target_author_idx", @@ -24882,37 +26143,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "feedback_votes_company_id_companies_id_fk": { "name": "feedback_votes_company_id_companies_id_fk", "tableFrom": "feedback_votes", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "feedback_votes_issue_id_issues_id_fk": { "name": "feedback_votes_issue_id_issues_id_fk", "tableFrom": "feedback_votes", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -25123,9 +26384,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "finance_events_company_occurred_idx": { "name": "finance_events_company_occurred_idx", @@ -25144,9 +26405,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "finance_events_company_biller_occurred_idx": { "name": "finance_events_company_biller_occurred_idx", @@ -25171,9 +26432,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "finance_events_company_kind_occurred_idx": { "name": "finance_events_company_kind_occurred_idx", @@ -25198,9 +26459,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "finance_events_company_direction_occurred_idx": { "name": "finance_events_company_direction_occurred_idx", @@ -25225,9 +26486,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "finance_events_company_heartbeat_run_idx": { "name": "finance_events_company_heartbeat_run_idx", @@ -25246,9 +26507,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "finance_events_company_cost_event_idx": { "name": "finance_events_company_cost_event_idx", @@ -25267,102 +26528,102 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "finance_events_company_id_companies_id_fk": { "name": "finance_events_company_id_companies_id_fk", "tableFrom": "finance_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "finance_events_agent_id_agents_id_fk": { "name": "finance_events_agent_id_agents_id_fk", "tableFrom": "finance_events", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "finance_events_issue_id_issues_id_fk": { "name": "finance_events_issue_id_issues_id_fk", "tableFrom": "finance_events", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "finance_events_project_id_projects_id_fk": { "name": "finance_events_project_id_projects_id_fk", "tableFrom": "finance_events", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "finance_events_goal_id_goals_id_fk": { "name": "finance_events_goal_id_goals_id_fk", "tableFrom": "finance_events", + "tableTo": "goals", "columnsFrom": [ "goal_id" ], - "tableTo": "goals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "finance_events_heartbeat_run_id_heartbeat_runs_id_fk": { "name": "finance_events_heartbeat_run_id_heartbeat_runs_id_fk", "tableFrom": "finance_events", + "tableTo": "heartbeat_runs", "columnsFrom": [ "heartbeat_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "finance_events_cost_event_id_cost_events_id_fk": { "name": "finance_events_cost_event_id_cost_events_id_fk", "tableFrom": "finance_events", + "tableTo": "cost_events", "columnsFrom": [ "cost_event_id" ], - "tableTo": "cost_events", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -25476,9 +26737,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "folders_company_kind_root_slug_uq": { "name": "folders_company_kind_root_slug_uq", @@ -25503,10 +26764,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"folders\".\"parent_id\" is null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "folders_company_kind_parent_slug_uq": { "name": "folders_company_kind_parent_slug_uq", @@ -25537,10 +26798,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"folders\".\"parent_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "folders_company_kind_system_key_uq": { "name": "folders_company_kind_system_key_uq", @@ -25565,10 +26826,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"folders\".\"system_key\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "folders_company_kind_parent_position_idx": { "name": "folders_company_kind_parent_position_idx", @@ -25605,37 +26866,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "folders_company_id_companies_id_fk": { "name": "folders_company_id_companies_id_fk", "tableFrom": "folders", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "folders_parent_id_folders_id_fk": { "name": "folders_parent_id_folders_id_fk", "tableFrom": "folders", + "tableTo": "folders", "columnsFrom": [ "parent_id" ], - "tableTo": "folders", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -25726,50 +26987,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "goals_company_id_companies_id_fk": { "name": "goals_company_id_companies_id_fk", "tableFrom": "goals", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "goals_parent_id_goals_id_fk": { "name": "goals_parent_id_goals_id_fk", "tableFrom": "goals", + "tableTo": "goals", "columnsFrom": [ "parent_id" ], - "tableTo": "goals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "goals_owner_agent_id_agents_id_fk": { "name": "goals_owner_agent_id_agents_id_fk", "tableFrom": "goals", + "tableTo": "agents", "columnsFrom": [ "owner_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -25904,9 +27165,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_run_events_run_source_event_uq": { "name": "heartbeat_run_events_run_source_event_uq", @@ -25925,10 +27186,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"heartbeat_run_events\".\"source_event_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "heartbeat_run_events_run_source_seq_uq": { "name": "heartbeat_run_events_run_source_seq_uq", @@ -25953,10 +27214,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"heartbeat_run_events\".\"source_instance_id\" is not null and \"heartbeat_run_events\".\"source_seq\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "heartbeat_run_events_company_run_idx": { "name": "heartbeat_run_events_company_run_idx", @@ -25975,9 +27236,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_run_events_company_created_idx": { "name": "heartbeat_run_events_company_created_idx", @@ -25996,50 +27257,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "heartbeat_run_events_company_id_companies_id_fk": { "name": "heartbeat_run_events_company_id_companies_id_fk", "tableFrom": "heartbeat_run_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "heartbeat_run_events_run_id_heartbeat_runs_id_fk": { "name": "heartbeat_run_events_run_id_heartbeat_runs_id_fk", "tableFrom": "heartbeat_run_events", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "heartbeat_run_events_agent_id_agents_id_fk": { "name": "heartbeat_run_events_agent_id_agents_id_fk", "tableFrom": "heartbeat_run_events", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -26145,9 +27406,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_run_watchdog_decisions_company_run_snooze_idx": { "name": "heartbeat_run_watchdog_decisions_company_run_snooze_idx", @@ -26172,76 +27433,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "heartbeat_run_watchdog_decisions_company_id_companies_id_fk": { "name": "heartbeat_run_watchdog_decisions_company_id_companies_id_fk", "tableFrom": "heartbeat_run_watchdog_decisions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "heartbeat_run_watchdog_decisions_run_id_heartbeat_runs_id_fk": { "name": "heartbeat_run_watchdog_decisions_run_id_heartbeat_runs_id_fk", "tableFrom": "heartbeat_run_watchdog_decisions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "heartbeat_run_watchdog_decisions_evaluation_issue_id_issues_id_fk": { "name": "heartbeat_run_watchdog_decisions_evaluation_issue_id_issues_id_fk", "tableFrom": "heartbeat_run_watchdog_decisions", + "tableTo": "issues", "columnsFrom": [ "evaluation_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "heartbeat_run_watchdog_decisions_created_by_agent_id_agents_id_fk": { "name": "heartbeat_run_watchdog_decisions_created_by_agent_id_agents_id_fk", "tableFrom": "heartbeat_run_watchdog_decisions", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "heartbeat_run_watchdog_decisions_created_by_run_id_heartbeat_runs_id_fk": { "name": "heartbeat_run_watchdog_decisions_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "heartbeat_run_watchdog_decisions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -26757,10 +28018,10 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"heartbeat_runs\".\"cost_accounting_pending\" = true", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "heartbeat_runs_execution_status_delivery_idx": { "name": "heartbeat_runs_execution_status_delivery_idx", @@ -26773,10 +28034,10 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"heartbeat_runs\".\"execution_status_delivery_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "heartbeat_runs_execution_control_deadline_idx": { "name": "heartbeat_runs_execution_control_deadline_idx", @@ -26789,10 +28050,10 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"heartbeat_runs\".\"execution_control_deadline_at\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "heartbeat_runs_native_replacement_predecessor_uq": { "name": "heartbeat_runs_native_replacement_predecessor_uq", @@ -26811,10 +28072,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"heartbeat_runs\".\"scheduled_retry_reason\" = 'native_safe_replacement'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "heartbeat_runs_company_agent_started_idx": { "name": "heartbeat_runs_company_agent_started_idx", @@ -26839,9 +28100,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_runs_company_issue_created_idx": { "name": "heartbeat_runs_company_issue_created_idx", @@ -26866,9 +28127,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_runs_company_responsible_user_idx": { "name": "heartbeat_runs_company_responsible_user_idx", @@ -26893,9 +28154,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_runs_company_liveness_idx": { "name": "heartbeat_runs_company_liveness_idx", @@ -26920,9 +28181,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_runs_company_status_last_output_idx": { "name": "heartbeat_runs_company_status_last_output_idx", @@ -26947,9 +28208,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_runs_company_status_process_started_idx": { "name": "heartbeat_runs_company_status_process_started_idx", @@ -26974,9 +28235,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_runs_company_created_at_desc_idx": { "name": "heartbeat_runs_company_created_at_desc_idx", @@ -26995,9 +28256,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_runs_company_ctx_issue_created_idx": { "name": "heartbeat_runs_company_ctx_issue_created_idx", @@ -27010,8 +28271,8 @@ }, { "expression": "(\"context_snapshot\" ->> 'issueId')", - "isExpression": true, "asc": true, + "isExpression": true, "nulls": "last" }, { @@ -27022,9 +28283,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_runs_company_ctx_task_created_idx": { "name": "heartbeat_runs_company_ctx_task_created_idx", @@ -27037,8 +28298,8 @@ }, { "expression": "(\"context_snapshot\" ->> 'taskId')", - "isExpression": true, "asc": true, + "isExpression": true, "nulls": "last" }, { @@ -27049,9 +28310,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "heartbeat_runs_company_ctx_taskkey_created_idx": { "name": "heartbeat_runs_company_ctx_taskkey_created_idx", @@ -27064,8 +28325,8 @@ }, { "expression": "(\"context_snapshot\" ->> 'taskKey')", - "isExpression": true, "asc": true, + "isExpression": true, "nulls": "last" }, { @@ -27076,98 +28337,98 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "heartbeat_runs_company_id_companies_id_fk": { "name": "heartbeat_runs_company_id_companies_id_fk", "tableFrom": "heartbeat_runs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "heartbeat_runs_agent_id_agents_id_fk": { "name": "heartbeat_runs_agent_id_agents_id_fk", "tableFrom": "heartbeat_runs", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "heartbeat_runs_issue_id_issues_id_fk": { "name": "heartbeat_runs_issue_id_issues_id_fk", "tableFrom": "heartbeat_runs", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "heartbeat_runs_wakeup_request_id_agent_wakeup_requests_id_fk": { "name": "heartbeat_runs_wakeup_request_id_agent_wakeup_requests_id_fk", "tableFrom": "heartbeat_runs", + "tableTo": "agent_wakeup_requests", "columnsFrom": [ "wakeup_request_id" ], - "tableTo": "agent_wakeup_requests", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "heartbeat_runs_retry_of_run_id_heartbeat_runs_id_fk": { "name": "heartbeat_runs_retry_of_run_id_heartbeat_runs_id_fk", "tableFrom": "heartbeat_runs", + "tableTo": "heartbeat_runs", "columnsFrom": [ "retry_of_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "heartbeat_runs_company_native_issue_id_uq": { "name": "heartbeat_runs_company_native_issue_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "native_issue_id", "id" - ], - "nullsNotDistinct": false + ] }, "heartbeat_runs_company_native_issue_contract_id_uq": { "name": "heartbeat_runs_company_native_issue_contract_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "native_issue_id", "id", "completion_contract_id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -27261,9 +28522,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "inbox_dismissals_company_item_idx": { "name": "inbox_dismissals_company_item_idx", @@ -27282,9 +28543,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "inbox_dismissals_company_user_item_idx": { "name": "inbox_dismissals_company_user_item_idx", @@ -27309,24 +28570,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "inbox_dismissals_company_id_companies_id_fk": { "name": "inbox_dismissals_company_id_companies_id_fk", "tableFrom": "inbox_dismissals", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -27396,9 +28657,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_grant_delegations_grant_agent_uq": { "name": "connection_grant_delegations_grant_agent_uq", @@ -27417,52 +28678,52 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "connection_grant_delegations_company_id_companies_id_fk": { "name": "connection_grant_delegations_company_id_companies_id_fk", "tableFrom": "connection_grant_delegations", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "connection_grant_delegations_agent_id_agents_id_fk": { "name": "connection_grant_delegations_agent_id_agents_id_fk", "tableFrom": "connection_grant_delegations", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "connection_grant_delegations_company_grant_fk": { "name": "connection_grant_delegations_company_grant_fk", "tableFrom": "connection_grant_delegations", + "tableTo": "connection_grants", "columnsFrom": [ "company_id", "grant_id" ], - "tableTo": "connection_grants", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -27538,9 +28799,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_grant_members_grant_subject_uq": { "name": "connection_grant_members_grant_subject_uq", @@ -27565,39 +28826,39 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "connection_grant_members_company_id_companies_id_fk": { "name": "connection_grant_members_company_id_companies_id_fk", "tableFrom": "connection_grant_members", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "connection_grant_members_company_grant_fk": { "name": "connection_grant_members_company_grant_fk", "tableFrom": "connection_grant_members", + "tableTo": "connection_grants", "columnsFrom": [ "company_id", "grant_id" ], - "tableTo": "connection_grants", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -27754,9 +29015,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_grants_subject_user_idx": { "name": "connection_grants_subject_user_idx", @@ -27775,9 +29036,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_grants_subject_agent_idx": { "name": "connection_grants_subject_agent_idx", @@ -27796,9 +29057,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_grants_user_uq": { "name": "connection_grants_user_uq", @@ -27817,9 +29078,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_grants_agent_uq": { "name": "connection_grants_agent_uq", @@ -27838,9 +29099,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_grants_default_uq": { "name": "connection_grants_default_uq", @@ -27853,90 +29114,90 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"connection_grants\".\"is_default\" = true and \"connection_grants\".\"kind\" = 'organization'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "connection_grants_company_id_companies_id_fk": { "name": "connection_grants_company_id_companies_id_fk", "tableFrom": "connection_grants", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "connection_grants_subject_agent_id_agents_id_fk": { "name": "connection_grants_subject_agent_id_agents_id_fk", "tableFrom": "connection_grants", + "tableTo": "agents", "columnsFrom": [ "subject_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "connection_grants_created_by_agent_id_agents_id_fk": { "name": "connection_grants_created_by_agent_id_agents_id_fk", "tableFrom": "connection_grants", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "connection_grants_revoked_by_agent_id_agents_id_fk": { "name": "connection_grants_revoked_by_agent_id_agents_id_fk", "tableFrom": "connection_grants", + "tableTo": "agents", "columnsFrom": [ "revoked_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "connection_grants_company_connection_fk": { "name": "connection_grants_company_connection_fk", "tableFrom": "connection_grants", + "tableTo": "tool_connections", "columnsFrom": [ "company_id", "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "connection_grants_company_id_uq": { "name": "connection_grants_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -28106,9 +29367,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_token_issuances_connection_created_idx": { "name": "connection_token_issuances_connection_created_idx", @@ -28133,9 +29394,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_token_issuances_agent_connection_idx": { "name": "connection_token_issuances_agent_connection_idx", @@ -28166,9 +29427,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "connection_token_issuances_run_idx": { "name": "connection_token_issuances_run_idx", @@ -28187,102 +29448,102 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "connection_token_issuances_company_id_companies_id_fk": { "name": "connection_token_issuances_company_id_companies_id_fk", "tableFrom": "connection_token_issuances", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "connection_token_issuances_application_id_tool_applications_id_fk": { "name": "connection_token_issuances_application_id_tool_applications_id_fk", "tableFrom": "connection_token_issuances", + "tableTo": "tool_applications", "columnsFrom": [ "application_id" ], - "tableTo": "tool_applications", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "connection_token_issuances_connection_id_tool_connections_id_fk": { "name": "connection_token_issuances_connection_id_tool_connections_id_fk", "tableFrom": "connection_token_issuances", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "connection_token_issuances_agent_id_agents_id_fk": { "name": "connection_token_issuances_agent_id_agents_id_fk", "tableFrom": "connection_token_issuances", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "connection_token_issuances_run_id_heartbeat_runs_id_fk": { "name": "connection_token_issuances_run_id_heartbeat_runs_id_fk", "tableFrom": "connection_token_issuances", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "connection_token_issuances_issue_id_issues_id_fk": { "name": "connection_token_issuances_issue_id_issues_id_fk", "tableFrom": "connection_token_issuances", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "connection_token_issuances_project_id_projects_id_fk": { "name": "connection_token_issuances_project_id_projects_id_fk", "tableFrom": "connection_token_issuances", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -28356,24 +29617,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "instance_settings_default_environment_id_environments_id_fk": { "name": "instance_settings_default_environment_id_environments_id_fk", "tableFrom": "instance_settings", + "tableTo": "environments", "columnsFrom": [ "default_environment_id" ], - "tableTo": "environments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -28439,9 +29700,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "instance_user_roles_role_idx": { "name": "instance_user_roles_role_idx", @@ -28454,9 +29715,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": {}, @@ -28560,9 +29821,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "invites_company_invite_state_idx": { "name": "invites_company_invite_state_idx", @@ -28593,24 +29854,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "invites_company_id_companies_id_fk": { "name": "invites_company_id_companies_id_fk", "tableFrom": "invites", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -28710,9 +29971,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_access_grants_issue_idx": { "name": "issue_access_grants_issue_idx", @@ -28731,37 +29992,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_access_grants_issue_id_issues_id_fk": { "name": "issue_access_grants_issue_id_issues_id_fk", "tableFrom": "issue_access_grants", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_access_grants_granted_by_agent_id_agents_id_fk": { "name": "issue_access_grants_granted_by_agent_id_agents_id_fk", "tableFrom": "issue_access_grants", + "tableTo": "agents", "columnsFrom": [ "granted_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -28833,9 +30094,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_approvals_approval_idx": { "name": "issue_approvals_approval_idx", @@ -28848,9 +30109,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_approvals_company_idx": { "name": "issue_approvals_company_idx", @@ -28863,63 +30124,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_approvals_company_id_companies_id_fk": { "name": "issue_approvals_company_id_companies_id_fk", "tableFrom": "issue_approvals", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_approvals_issue_id_issues_id_fk": { "name": "issue_approvals_issue_id_issues_id_fk", "tableFrom": "issue_approvals", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_approvals_approval_id_approvals_id_fk": { "name": "issue_approvals_approval_id_approvals_id_fk", "tableFrom": "issue_approvals", + "tableTo": "approvals", "columnsFrom": [ "approval_id" ], - "tableTo": "approvals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_approvals_linked_by_agent_id_agents_id_fk": { "name": "issue_approvals_linked_by_agent_id_agents_id_fk", "tableFrom": "issue_approvals", + "tableTo": "agents", "columnsFrom": [ "linked_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": { @@ -29010,9 +30271,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_attachments_issue_comment_idx": { "name": "issue_attachments_issue_comment_idx", @@ -29025,9 +30286,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_attachments_originating_run_idx": { "name": "issue_attachments_originating_run_idx", @@ -29040,9 +30301,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_attachments_asset_uq": { "name": "issue_attachments_asset_uq", @@ -29055,76 +30316,76 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_attachments_company_id_companies_id_fk": { "name": "issue_attachments_company_id_companies_id_fk", "tableFrom": "issue_attachments", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_attachments_issue_id_issues_id_fk": { "name": "issue_attachments_issue_id_issues_id_fk", "tableFrom": "issue_attachments", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_attachments_asset_id_assets_id_fk": { "name": "issue_attachments_asset_id_assets_id_fk", "tableFrom": "issue_attachments", + "tableTo": "assets", "columnsFrom": [ "asset_id" ], - "tableTo": "assets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_attachments_issue_comment_id_issue_comments_id_fk": { "name": "issue_attachments_issue_comment_id_issue_comments_id_fk", "tableFrom": "issue_attachments", + "tableTo": "issue_comments", "columnsFrom": [ "issue_comment_id" ], - "tableTo": "issue_comments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_attachments_originating_run_id_heartbeat_runs_id_fk": { "name": "issue_attachments_originating_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_attachments", + "tableTo": "heartbeat_runs", "columnsFrom": [ "originating_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -29297,9 +30558,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_comments_company_idx": { "name": "issue_comments_company_idx", @@ -29312,9 +30573,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_comments_company_issue_created_at_idx": { "name": "issue_comments_company_issue_created_at_idx", @@ -29339,9 +30600,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_comments_company_author_issue_created_at_idx": { "name": "issue_comments_company_author_issue_created_at_idx", @@ -29372,9 +30633,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_comments_body_search_idx": { "name": "issue_comments_body_search_idx", @@ -29388,148 +30649,148 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_comments_company_id_companies_id_fk": { "name": "issue_comments_company_id_companies_id_fk", "tableFrom": "issue_comments", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_comments_issue_id_issues_id_fk": { "name": "issue_comments_issue_id_issues_id_fk", "tableFrom": "issue_comments", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_comments_author_agent_id_agents_id_fk": { "name": "issue_comments_author_agent_id_agents_id_fk", "tableFrom": "issue_comments", + "tableTo": "agents", "columnsFrom": [ "author_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_comments_on_behalf_of_user_id_user_id_fk": { "name": "issue_comments_on_behalf_of_user_id_user_id_fk", "tableFrom": "issue_comments", + "tableTo": "user", "columnsFrom": [ "on_behalf_of_user_id" ], - "tableTo": "user", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_comments_created_by_run_id_heartbeat_runs_id_fk": { "name": "issue_comments_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_comments", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_comments_derived_author_agent_id_agents_id_fk": { "name": "issue_comments_derived_author_agent_id_agents_id_fk", "tableFrom": "issue_comments", + "tableTo": "agents", "columnsFrom": [ "derived_author_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_comments_derived_created_by_run_id_heartbeat_runs_id_fk": { "name": "issue_comments_derived_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_comments", + "tableTo": "heartbeat_runs", "columnsFrom": [ "derived_created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_comments_deleted_by_agent_id_agents_id_fk": { "name": "issue_comments_deleted_by_agent_id_agents_id_fk", "tableFrom": "issue_comments", + "tableTo": "agents", "columnsFrom": [ "deleted_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_comments_deleted_by_run_id_heartbeat_runs_id_fk": { "name": "issue_comments_deleted_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_comments", + "tableTo": "heartbeat_runs", "columnsFrom": [ "deleted_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "issue_comments_client_request_uq": { "name": "issue_comments_client_request_uq", + "nullsNotDistinct": false, "columns": [ "issue_id", "author_user_id", "client_request_id" - ], - "nullsNotDistinct": false + ] }, "issue_comments_company_id_uq": { "name": "issue_comments_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -29591,9 +30852,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_create_idempotency_keys_issue_idx": { "name": "issue_create_idempotency_keys_issue_idx", @@ -29606,9 +30867,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_create_idempotency_keys_company_created_at_idx": { "name": "issue_create_idempotency_keys_company_created_at_idx", @@ -29627,37 +30888,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_create_idempotency_keys_company_id_companies_id_fk": { "name": "issue_create_idempotency_keys_company_id_companies_id_fk", "tableFrom": "issue_create_idempotency_keys", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_create_idempotency_keys_issue_id_issues_id_fk": { "name": "issue_create_idempotency_keys_issue_id_issues_id_fk", "tableFrom": "issue_create_idempotency_keys", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -29740,9 +31001,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_documents_document_uq": { "name": "issue_documents_document_uq", @@ -29755,9 +31016,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_documents_company_issue_updated_idx": { "name": "issue_documents_company_issue_updated_idx", @@ -29782,50 +31043,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_documents_company_id_companies_id_fk": { "name": "issue_documents_company_id_companies_id_fk", "tableFrom": "issue_documents", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_documents_issue_id_issues_id_fk": { "name": "issue_documents_issue_id_issues_id_fk", "tableFrom": "issue_documents", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_documents_document_id_documents_id_fk": { "name": "issue_documents_document_id_documents_id_fk", "tableFrom": "issue_documents", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -29932,9 +31193,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_execution_decisions_stage_idx": { "name": "issue_execution_decisions_stage_idx", @@ -29959,63 +31220,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_execution_decisions_company_id_companies_id_fk": { "name": "issue_execution_decisions_company_id_companies_id_fk", "tableFrom": "issue_execution_decisions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_execution_decisions_issue_id_issues_id_fk": { "name": "issue_execution_decisions_issue_id_issues_id_fk", "tableFrom": "issue_execution_decisions", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_execution_decisions_actor_agent_id_agents_id_fk": { "name": "issue_execution_decisions_actor_agent_id_agents_id_fk", "tableFrom": "issue_execution_decisions", + "tableTo": "agents", "columnsFrom": [ "actor_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_execution_decisions_created_by_run_id_heartbeat_runs_id_fk": { "name": "issue_execution_decisions_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_execution_decisions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -30112,9 +31373,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_inbox_archives_company_user_idx": { "name": "issue_inbox_archives_company_user_idx", @@ -30133,9 +31394,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_inbox_archives_company_issue_user_idx": { "name": "issue_inbox_archives_company_issue_user_idx", @@ -30160,63 +31421,63 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_inbox_archives_company_id_companies_id_fk": { "name": "issue_inbox_archives_company_id_companies_id_fk", "tableFrom": "issue_inbox_archives", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_inbox_archives_issue_id_issues_id_fk": { "name": "issue_inbox_archives_issue_id_issues_id_fk", "tableFrom": "issue_inbox_archives", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_inbox_archives_archived_by_agent_id_agents_id_fk": { "name": "issue_inbox_archives_archived_by_agent_id_agents_id_fk", "tableFrom": "issue_inbox_archives", + "tableTo": "agents", "columnsFrom": [ "archived_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_inbox_archives_archived_by_run_id_heartbeat_runs_id_fk": { "name": "issue_inbox_archives_archived_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_inbox_archives", + "tableTo": "heartbeat_runs", "columnsFrom": [ "archived_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -30272,9 +31533,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_labels_label_idx": { "name": "issue_labels_label_idx", @@ -30287,9 +31548,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_labels_company_idx": { "name": "issue_labels_company_idx", @@ -30302,50 +31563,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_labels_issue_id_issues_id_fk": { "name": "issue_labels_issue_id_issues_id_fk", "tableFrom": "issue_labels", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_labels_label_id_labels_id_fk": { "name": "issue_labels_label_id_labels_id_fk", "tableFrom": "issue_labels", + "tableTo": "labels", "columnsFrom": [ "label_id" ], - "tableTo": "labels", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_labels_company_id_companies_id_fk": { "name": "issue_labels_company_id_companies_id_fk", "tableFrom": "issue_labels", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": { @@ -30494,9 +31755,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_plan_decompositions_active_owner_idx": { "name": "issue_plan_decompositions_active_owner_idx", @@ -30515,10 +31776,10 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"issue_plan_decompositions\".\"status\" = 'in_flight'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issue_plan_decompositions_source_revision_uq": { "name": "issue_plan_decompositions_source_revision_uq", @@ -30543,89 +31804,89 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_plan_decompositions_company_id_companies_id_fk": { "name": "issue_plan_decompositions_company_id_companies_id_fk", "tableFrom": "issue_plan_decompositions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_plan_decompositions_source_issue_id_issues_id_fk": { "name": "issue_plan_decompositions_source_issue_id_issues_id_fk", "tableFrom": "issue_plan_decompositions", + "tableTo": "issues", "columnsFrom": [ "source_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_plan_decompositions_accepted_plan_revision_id_document_revisions_id_fk": { "name": "issue_plan_decompositions_accepted_plan_revision_id_document_revisions_id_fk", "tableFrom": "issue_plan_decompositions", + "tableTo": "document_revisions", "columnsFrom": [ "accepted_plan_revision_id" ], - "tableTo": "document_revisions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_plan_decompositions_accepted_interaction_id_issue_thread_interactions_id_fk": { "name": "issue_plan_decompositions_accepted_interaction_id_issue_thread_interactions_id_fk", "tableFrom": "issue_plan_decompositions", + "tableTo": "issue_thread_interactions", "columnsFrom": [ "accepted_interaction_id" ], - "tableTo": "issue_thread_interactions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_plan_decompositions_owner_agent_id_agents_id_fk": { "name": "issue_plan_decompositions_owner_agent_id_agents_id_fk", "tableFrom": "issue_plan_decompositions", + "tableTo": "agents", "columnsFrom": [ "owner_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_plan_decompositions_owner_run_id_heartbeat_runs_id_fk": { "name": "issue_plan_decompositions_owner_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_plan_decompositions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "owner_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -30765,9 +32026,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_question_response_deliveries_correlation_uq": { "name": "issue_question_response_deliveries_correlation_uq", @@ -30780,9 +32041,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_question_response_deliveries_pending_idx": { "name": "issue_question_response_deliveries_pending_idx", @@ -30801,9 +32062,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_question_response_deliveries_company_issue_idx": { "name": "issue_question_response_deliveries_company_issue_idx", @@ -30828,76 +32089,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_question_response_deliveries_company_id_companies_id_fk": { "name": "issue_question_response_deliveries_company_id_companies_id_fk", "tableFrom": "issue_question_response_deliveries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_question_response_deliveries_issue_id_issues_id_fk": { "name": "issue_question_response_deliveries_issue_id_issues_id_fk", "tableFrom": "issue_question_response_deliveries", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_question_response_deliveries_interaction_id_issue_thread_interactions_id_fk": { "name": "issue_question_response_deliveries_interaction_id_issue_thread_interactions_id_fk", "tableFrom": "issue_question_response_deliveries", + "tableTo": "issue_thread_interactions", "columnsFrom": [ "interaction_id" ], - "tableTo": "issue_thread_interactions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_question_response_deliveries_source_run_id_heartbeat_runs_id_fk": { "name": "issue_question_response_deliveries_source_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_question_response_deliveries", + "tableTo": "heartbeat_runs", "columnsFrom": [ "source_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_question_response_deliveries_target_run_id_heartbeat_runs_id_fk": { "name": "issue_question_response_deliveries_target_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_question_response_deliveries", + "tableTo": "heartbeat_runs", "columnsFrom": [ "target_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -30984,9 +32245,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_read_states_company_user_idx": { "name": "issue_read_states_company_user_idx", @@ -31005,9 +32266,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_read_states_company_issue_user_idx": { "name": "issue_read_states_company_issue_user_idx", @@ -31032,37 +32293,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_read_states_company_id_companies_id_fk": { "name": "issue_read_states_company_id_companies_id_fk", "tableFrom": "issue_read_states", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_read_states_issue_id_issues_id_fk": { "name": "issue_read_states_issue_id_issues_id_fk", "tableFrom": "issue_read_states", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -31263,9 +32524,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_recovery_actions_company_owner_status_idx": { "name": "issue_recovery_actions_company_owner_status_idx", @@ -31290,9 +32551,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_recovery_actions_company_recovery_issue_idx": { "name": "issue_recovery_actions_company_recovery_issue_idx", @@ -31311,9 +32572,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_recovery_actions_active_source_uq": { "name": "issue_recovery_actions_active_source_uq", @@ -31332,10 +32593,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issue_recovery_actions\".\"status\" in ('active', 'escalated')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issue_recovery_actions_active_fingerprint_uq": { "name": "issue_recovery_actions_active_fingerprint_uq", @@ -31366,90 +32627,90 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issue_recovery_actions\".\"status\" in ('active', 'escalated')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "issue_recovery_actions_company_id_companies_id_fk": { "name": "issue_recovery_actions_company_id_companies_id_fk", "tableFrom": "issue_recovery_actions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_recovery_actions_source_issue_id_issues_id_fk": { "name": "issue_recovery_actions_source_issue_id_issues_id_fk", "tableFrom": "issue_recovery_actions", + "tableTo": "issues", "columnsFrom": [ "source_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_recovery_actions_recovery_issue_id_issues_id_fk": { "name": "issue_recovery_actions_recovery_issue_id_issues_id_fk", "tableFrom": "issue_recovery_actions", + "tableTo": "issues", "columnsFrom": [ "recovery_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_recovery_actions_owner_agent_id_agents_id_fk": { "name": "issue_recovery_actions_owner_agent_id_agents_id_fk", "tableFrom": "issue_recovery_actions", + "tableTo": "agents", "columnsFrom": [ "owner_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_recovery_actions_previous_owner_agent_id_agents_id_fk": { "name": "issue_recovery_actions_previous_owner_agent_id_agents_id_fk", "tableFrom": "issue_recovery_actions", + "tableTo": "agents", "columnsFrom": [ "previous_owner_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_recovery_actions_return_owner_agent_id_agents_id_fk": { "name": "issue_recovery_actions_return_owner_agent_id_agents_id_fk", "tableFrom": "issue_recovery_actions", + "tableTo": "agents", "columnsFrom": [ "return_owner_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -31544,9 +32805,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_reference_mentions_company_target_issue_idx": { "name": "issue_reference_mentions_company_target_issue_idx", @@ -31565,9 +32826,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_reference_mentions_company_issue_pair_idx": { "name": "issue_reference_mentions_company_issue_pair_idx", @@ -31592,9 +32853,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_reference_mentions_company_source_mention_record_uq": { "name": "issue_reference_mentions_company_source_mention_record_uq", @@ -31631,10 +32892,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issue_reference_mentions\".\"source_record_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issue_reference_mentions_company_source_mention_null_record_uq": { "name": "issue_reference_mentions_company_source_mention_null_record_uq", @@ -31665,51 +32926,51 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issue_reference_mentions\".\"source_record_id\" is null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "issue_reference_mentions_company_id_companies_id_fk": { "name": "issue_reference_mentions_company_id_companies_id_fk", "tableFrom": "issue_reference_mentions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_reference_mentions_source_issue_id_issues_id_fk": { "name": "issue_reference_mentions_source_issue_id_issues_id_fk", "tableFrom": "issue_reference_mentions", + "tableTo": "issues", "columnsFrom": [ "source_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_reference_mentions_target_issue_id_issues_id_fk": { "name": "issue_reference_mentions_target_issue_id_issues_id_fk", "tableFrom": "issue_reference_mentions", + "tableTo": "issues", "columnsFrom": [ "target_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -31798,9 +33059,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_relations_company_related_issue_idx": { "name": "issue_relations_company_related_issue_idx", @@ -31819,9 +33080,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_relations_company_type_idx": { "name": "issue_relations_company_type_idx", @@ -31840,9 +33101,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_relations_company_edge_uq": { "name": "issue_relations_company_edge_uq", @@ -31873,63 +33134,63 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_relations_company_id_companies_id_fk": { "name": "issue_relations_company_id_companies_id_fk", "tableFrom": "issue_relations", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_relations_issue_id_issues_id_fk": { "name": "issue_relations_issue_id_issues_id_fk", "tableFrom": "issue_relations", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_relations_related_issue_id_issues_id_fk": { "name": "issue_relations_related_issue_id_issues_id_fk", "tableFrom": "issue_relations", + "tableTo": "issues", "columnsFrom": [ "related_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_relations_created_by_agent_id_agents_id_fk": { "name": "issue_relations_created_by_agent_id_agents_id_fk", "tableFrom": "issue_relations", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -32139,9 +33400,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_thread_interactions_company_issue_created_at_idx": { "name": "issue_thread_interactions_company_issue_created_at_idx", @@ -32166,9 +33427,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_thread_interactions_company_issue_status_idx": { "name": "issue_thread_interactions_company_issue_status_idx", @@ -32193,9 +33454,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_thread_interactions_company_issue_idempotency_uq": { "name": "issue_thread_interactions_company_issue_idempotency_uq", @@ -32220,10 +33481,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issue_thread_interactions\".\"idempotency_key\" IS NOT NULL", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issue_thread_interactions_source_comment_idx": { "name": "issue_thread_interactions_source_comment_idx", @@ -32236,9 +33497,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_thread_interactions_addressee_agent_idx": { "name": "issue_thread_interactions_addressee_agent_idx", @@ -32251,9 +33512,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_thread_interactions_addressee_user_idx": { "name": "issue_thread_interactions_addressee_user_idx", @@ -32266,115 +33527,115 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_thread_interactions_company_id_companies_id_fk": { "name": "issue_thread_interactions_company_id_companies_id_fk", "tableFrom": "issue_thread_interactions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_thread_interactions_issue_id_issues_id_fk": { "name": "issue_thread_interactions_issue_id_issues_id_fk", "tableFrom": "issue_thread_interactions", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_thread_interactions_source_comment_id_issue_comments_id_fk": { "name": "issue_thread_interactions_source_comment_id_issue_comments_id_fk", "tableFrom": "issue_thread_interactions", + "tableTo": "issue_comments", "columnsFrom": [ "source_comment_id" ], - "tableTo": "issue_comments", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_thread_interactions_source_run_id_heartbeat_runs_id_fk": { "name": "issue_thread_interactions_source_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_thread_interactions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "source_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_thread_interactions_created_by_agent_id_agents_id_fk": { "name": "issue_thread_interactions_created_by_agent_id_agents_id_fk", "tableFrom": "issue_thread_interactions", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_thread_interactions_addressee_agent_id_agents_id_fk": { "name": "issue_thread_interactions_addressee_agent_id_agents_id_fk", "tableFrom": "issue_thread_interactions", + "tableTo": "agents", "columnsFrom": [ "addressee_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_thread_interactions_resolved_by_agent_id_agents_id_fk": { "name": "issue_thread_interactions_resolved_by_agent_id_agents_id_fk", "tableFrom": "issue_thread_interactions", + "tableTo": "agents", "columnsFrom": [ "resolved_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_thread_interactions_resolved_by_run_id_heartbeat_runs_id_fk": { "name": "issue_thread_interactions_resolved_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_thread_interactions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "resolved_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -32506,9 +33767,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_tree_hold_members_company_issue_idx": { "name": "issue_tree_hold_members_company_issue_idx", @@ -32527,9 +33788,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_tree_hold_members_hold_depth_idx": { "name": "issue_tree_hold_members_hold_depth_idx", @@ -32548,89 +33809,89 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_tree_hold_members_company_id_companies_id_fk": { "name": "issue_tree_hold_members_company_id_companies_id_fk", "tableFrom": "issue_tree_hold_members", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_tree_hold_members_hold_id_issue_tree_holds_id_fk": { "name": "issue_tree_hold_members_hold_id_issue_tree_holds_id_fk", "tableFrom": "issue_tree_hold_members", + "tableTo": "issue_tree_holds", "columnsFrom": [ "hold_id" ], - "tableTo": "issue_tree_holds", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_tree_hold_members_issue_id_issues_id_fk": { "name": "issue_tree_hold_members_issue_id_issues_id_fk", "tableFrom": "issue_tree_hold_members", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_tree_hold_members_parent_issue_id_issues_id_fk": { "name": "issue_tree_hold_members_parent_issue_id_issues_id_fk", "tableFrom": "issue_tree_hold_members", + "tableTo": "issues", "columnsFrom": [ "parent_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_tree_hold_members_assignee_agent_id_agents_id_fk": { "name": "issue_tree_hold_members_assignee_agent_id_agents_id_fk", "tableFrom": "issue_tree_hold_members", + "tableTo": "agents", "columnsFrom": [ "assignee_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_tree_hold_members_active_run_id_heartbeat_runs_id_fk": { "name": "issue_tree_hold_members_active_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_tree_hold_members", + "tableTo": "heartbeat_runs", "columnsFrom": [ "active_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -32793,9 +34054,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_tree_holds_company_status_mode_idx": { "name": "issue_tree_holds_company_status_mode_idx", @@ -32820,89 +34081,89 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_tree_holds_company_id_companies_id_fk": { "name": "issue_tree_holds_company_id_companies_id_fk", "tableFrom": "issue_tree_holds", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_tree_holds_root_issue_id_issues_id_fk": { "name": "issue_tree_holds_root_issue_id_issues_id_fk", "tableFrom": "issue_tree_holds", + "tableTo": "issues", "columnsFrom": [ "root_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_tree_holds_created_by_agent_id_agents_id_fk": { "name": "issue_tree_holds_created_by_agent_id_agents_id_fk", "tableFrom": "issue_tree_holds", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_tree_holds_created_by_run_id_heartbeat_runs_id_fk": { "name": "issue_tree_holds_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_tree_holds", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_tree_holds_released_by_agent_id_agents_id_fk": { "name": "issue_tree_holds_released_by_agent_id_agents_id_fk", "tableFrom": "issue_tree_holds", + "tableTo": "agents", "columnsFrom": [ "released_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_tree_holds_released_by_run_id_heartbeat_runs_id_fk": { "name": "issue_tree_holds_released_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_tree_holds", + "tableTo": "heartbeat_runs", "columnsFrom": [ "released_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -33071,9 +34332,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_watchdogs_company_status_idx": { "name": "issue_watchdogs_company_status_idx", @@ -33092,9 +34353,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_watchdogs_company_agent_idx": { "name": "issue_watchdogs_company_agent_idx", @@ -33113,9 +34374,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_watchdogs_company_watchdog_issue_uq": { "name": "issue_watchdogs_company_watchdog_issue_uq", @@ -33134,116 +34395,116 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issue_watchdogs\".\"watchdog_issue_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "issue_watchdogs_company_id_companies_id_fk": { "name": "issue_watchdogs_company_id_companies_id_fk", "tableFrom": "issue_watchdogs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_watchdogs_issue_id_issues_id_fk": { "name": "issue_watchdogs_issue_id_issues_id_fk", "tableFrom": "issue_watchdogs", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_watchdogs_watchdog_agent_id_agents_id_fk": { "name": "issue_watchdogs_watchdog_agent_id_agents_id_fk", "tableFrom": "issue_watchdogs", + "tableTo": "agents", "columnsFrom": [ "watchdog_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_watchdogs_watchdog_issue_id_issues_id_fk": { "name": "issue_watchdogs_watchdog_issue_id_issues_id_fk", "tableFrom": "issue_watchdogs", + "tableTo": "issues", "columnsFrom": [ "watchdog_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_watchdogs_created_by_agent_id_agents_id_fk": { "name": "issue_watchdogs_created_by_agent_id_agents_id_fk", "tableFrom": "issue_watchdogs", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_watchdogs_created_by_run_id_heartbeat_runs_id_fk": { "name": "issue_watchdogs_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_watchdogs", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_watchdogs_updated_by_agent_id_agents_id_fk": { "name": "issue_watchdogs_updated_by_agent_id_agents_id_fk", "tableFrom": "issue_watchdogs", + "tableTo": "agents", "columnsFrom": [ "updated_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_watchdogs_updated_by_run_id_heartbeat_runs_id_fk": { "name": "issue_watchdogs_updated_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_watchdogs", + "tableTo": "heartbeat_runs", "columnsFrom": [ "updated_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -33413,9 +34674,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_work_products_company_execution_workspace_type_idx": { "name": "issue_work_products_company_execution_workspace_type_idx", @@ -33440,9 +34701,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_work_products_company_provider_external_id_idx": { "name": "issue_work_products_company_provider_external_id_idx", @@ -33467,9 +34728,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issue_work_products_company_updated_idx": { "name": "issue_work_products_company_updated_idx", @@ -33488,89 +34749,89 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "issue_work_products_company_id_companies_id_fk": { "name": "issue_work_products_company_id_companies_id_fk", "tableFrom": "issue_work_products", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issue_work_products_project_id_projects_id_fk": { "name": "issue_work_products_project_id_projects_id_fk", "tableFrom": "issue_work_products", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_work_products_issue_id_issues_id_fk": { "name": "issue_work_products_issue_id_issues_id_fk", "tableFrom": "issue_work_products", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "issue_work_products_execution_workspace_id_execution_workspaces_id_fk": { "name": "issue_work_products_execution_workspace_id_execution_workspaces_id_fk", "tableFrom": "issue_work_products", + "tableTo": "execution_workspaces", "columnsFrom": [ "execution_workspace_id" ], - "tableTo": "execution_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_work_products_runtime_service_id_workspace_runtime_services_id_fk": { "name": "issue_work_products_runtime_service_id_workspace_runtime_services_id_fk", "tableFrom": "issue_work_products", + "tableTo": "workspace_runtime_services", "columnsFrom": [ "runtime_service_id" ], - "tableTo": "workspace_runtime_services", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issue_work_products_created_by_run_id_heartbeat_runs_id_fk": { "name": "issue_work_products_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "issue_work_products", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -34012,9 +35273,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_status_idx": { "name": "issues_company_status_idx", @@ -34033,9 +35294,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_harness_kind_idx": { "name": "issues_company_harness_kind_idx", @@ -34054,9 +35315,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_assignee_status_idx": { "name": "issues_company_assignee_status_idx", @@ -34081,9 +35342,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_assignee_user_status_idx": { "name": "issues_company_assignee_user_status_idx", @@ -34108,9 +35369,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_responsible_user_idx": { "name": "issues_company_responsible_user_idx", @@ -34129,9 +35390,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_parent_idx": { "name": "issues_company_parent_idx", @@ -34150,9 +35411,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_privacy_parent_idx": { "name": "issues_company_privacy_parent_idx", @@ -34171,9 +35432,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_privacy_root_idx": { "name": "issues_company_privacy_root_idx", @@ -34192,9 +35453,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_project_idx": { "name": "issues_company_project_idx", @@ -34213,9 +35474,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_origin_idx": { "name": "issues_company_origin_idx", @@ -34240,9 +35501,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_project_workspace_idx": { "name": "issues_company_project_workspace_idx", @@ -34261,9 +35522,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_execution_workspace_idx": { "name": "issues_company_execution_workspace_idx", @@ -34282,9 +35543,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_monitor_due_idx": { "name": "issues_company_monitor_due_idx", @@ -34303,9 +35564,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_updated_idx": { "name": "issues_company_updated_idx", @@ -34324,9 +35585,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_company_created_idx": { "name": "issues_company_created_idx", @@ -34345,9 +35606,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_open_normalized_title_created_idx": { "name": "issues_open_normalized_title_created_idx", @@ -34366,8 +35627,8 @@ }, { "expression": "lower(regexp_replace(btrim(\"title\"), '\\s+', ' ', 'g'))", - "isExpression": true, "asc": true, + "isExpression": true, "nulls": "last" }, { @@ -34378,10 +35639,10 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"issues\".\"hidden_at\" is null and \"issues\".\"status\" not in ('done', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issues_company_priority_idx": { "name": "issues_company_priority_idx", @@ -34400,9 +35661,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_identifier_idx": { "name": "issues_identifier_idx", @@ -34415,9 +35676,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "issues_title_search_idx": { "name": "issues_title_search_idx", @@ -34431,9 +35692,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} }, "issues_identifier_search_idx": { "name": "issues_identifier_search_idx", @@ -34447,9 +35708,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} }, "issues_description_search_idx": { "name": "issues_description_search_idx", @@ -34463,9 +35724,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} }, "issues_open_routine_execution_uq": { "name": "issues_open_routine_execution_uq", @@ -34496,10 +35757,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issues\".\"origin_kind\" = 'routine_execution'\n and \"issues\".\"origin_id\" is not null\n and \"issues\".\"hidden_at\" is null\n and \"issues\".\"execution_run_id\" is not null\n and \"issues\".\"status\" in ('backlog', 'todo', 'in_progress', 'in_review', 'blocked')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issues_active_liveness_recovery_incident_uq": { "name": "issues_active_liveness_recovery_incident_uq", @@ -34524,10 +35785,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issues\".\"origin_kind\" = 'harness_liveness_escalation'\n and \"issues\".\"origin_id\" is not null\n and \"issues\".\"hidden_at\" is null\n and \"issues\".\"status\" not in ('done', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issues_active_liveness_recovery_leaf_uq": { "name": "issues_active_liveness_recovery_leaf_uq", @@ -34552,10 +35813,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issues\".\"origin_kind\" = 'harness_liveness_escalation'\n and \"issues\".\"origin_fingerprint\" <> 'default'\n and \"issues\".\"hidden_at\" is null\n and \"issues\".\"status\" not in ('done', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issues_active_stale_run_evaluation_uq": { "name": "issues_active_stale_run_evaluation_uq", @@ -34580,10 +35841,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issues\".\"origin_kind\" = 'stale_active_run_evaluation'\n and \"issues\".\"origin_id\" is not null\n and \"issues\".\"hidden_at\" is null\n and \"issues\".\"status\" not in ('done', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issues_active_task_watchdog_uq": { "name": "issues_active_task_watchdog_uq", @@ -34608,10 +35869,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issues\".\"origin_kind\" = 'task_watchdog'\n and \"issues\".\"origin_id\" is not null\n and \"issues\".\"hidden_at\" is null\n and \"issues\".\"status\" not in ('done', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issues_active_productivity_review_uq": { "name": "issues_active_productivity_review_uq", @@ -34636,10 +35897,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issues\".\"origin_kind\" = 'issue_productivity_review'\n and \"issues\".\"origin_id\" is not null\n and \"issues\".\"hidden_at\" is null\n and \"issues\".\"status\" not in ('done', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issues_active_stranded_issue_recovery_uq": { "name": "issues_active_stranded_issue_recovery_uq", @@ -34664,10 +35925,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issues\".\"origin_kind\" = 'stranded_issue_recovery'\n and \"issues\".\"origin_id\" is not null\n and \"issues\".\"hidden_at\" is null\n and \"issues\".\"status\" not in ('done', 'cancelled')", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "issues_onboarding_first_task_uq": { "name": "issues_onboarding_first_task_uq", @@ -34680,192 +35941,192 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"issues\".\"origin_kind\" = 'onboarding_first_task'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "issues_company_id_companies_id_fk": { "name": "issues_company_id_companies_id_fk", "tableFrom": "issues", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issues_conversation_agent_id_agents_id_fk": { "name": "issues_conversation_agent_id_agents_id_fk", "tableFrom": "issues", + "tableTo": "agents", "columnsFrom": [ "conversation_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issues_project_id_projects_id_fk": { "name": "issues_project_id_projects_id_fk", "tableFrom": "issues", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issues_project_workspace_id_project_workspaces_id_fk": { "name": "issues_project_workspace_id_project_workspaces_id_fk", "tableFrom": "issues", + "tableTo": "project_workspaces", "columnsFrom": [ "project_workspace_id" ], - "tableTo": "project_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issues_goal_id_goals_id_fk": { "name": "issues_goal_id_goals_id_fk", "tableFrom": "issues", + "tableTo": "goals", "columnsFrom": [ "goal_id" ], - "tableTo": "goals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issues_parent_id_issues_id_fk": { "name": "issues_parent_id_issues_id_fk", "tableFrom": "issues", + "tableTo": "issues", "columnsFrom": [ "parent_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issues_privacy_root_issue_id_issues_id_fk": { "name": "issues_privacy_root_issue_id_issues_id_fk", "tableFrom": "issues", + "tableTo": "issues", "columnsFrom": [ "privacy_root_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issues_privacy_parent_issue_id_issues_id_fk": { "name": "issues_privacy_parent_issue_id_issues_id_fk", "tableFrom": "issues", + "tableTo": "issues", "columnsFrom": [ "privacy_parent_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issues_assignee_agent_id_agents_id_fk": { "name": "issues_assignee_agent_id_agents_id_fk", "tableFrom": "issues", + "tableTo": "agents", "columnsFrom": [ "assignee_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issues_checkout_run_id_heartbeat_runs_id_fk": { "name": "issues_checkout_run_id_heartbeat_runs_id_fk", "tableFrom": "issues", + "tableTo": "heartbeat_runs", "columnsFrom": [ "checkout_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issues_execution_run_id_heartbeat_runs_id_fk": { "name": "issues_execution_run_id_heartbeat_runs_id_fk", "tableFrom": "issues", + "tableTo": "heartbeat_runs", "columnsFrom": [ "execution_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "issues_created_by_agent_id_agents_id_fk": { "name": "issues_created_by_agent_id_agents_id_fk", "tableFrom": "issues", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "issues_execution_workspace_id_execution_workspaces_id_fk": { "name": "issues_execution_workspace_id_execution_workspaces_id_fk", "tableFrom": "issues", + "tableTo": "execution_workspaces", "columnsFrom": [ "execution_workspace_id" ], - "tableTo": "execution_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "issues_company_id_uq": { "name": "issues_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -35034,9 +36295,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "join_requests_company_status_type_created_idx": { "name": "join_requests_company_status_type_created_idx", @@ -35067,9 +36328,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "join_requests_pending_human_user_uq": { "name": "join_requests_pending_human_user_uq", @@ -35088,10 +36349,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"join_requests\".\"request_type\" = 'human' AND \"join_requests\".\"status\" = 'pending_approval' AND \"join_requests\".\"requesting_user_id\" IS NOT NULL", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "join_requests_pending_human_email_uq": { "name": "join_requests_pending_human_email_uq", @@ -35104,57 +36365,57 @@ }, { "expression": "lower(\"request_email_snapshot\")", - "isExpression": true, "asc": true, + "isExpression": true, "nulls": "last" } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"join_requests\".\"request_type\" = 'human' AND \"join_requests\".\"status\" = 'pending_approval' AND \"join_requests\".\"request_email_snapshot\" IS NOT NULL", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "join_requests_invite_id_invites_id_fk": { "name": "join_requests_invite_id_invites_id_fk", "tableFrom": "join_requests", + "tableTo": "invites", "columnsFrom": [ "invite_id" ], - "tableTo": "invites", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "join_requests_company_id_companies_id_fk": { "name": "join_requests_company_id_companies_id_fk", "tableFrom": "join_requests", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "join_requests_created_agent_id_agents_id_fk": { "name": "join_requests_created_agent_id_agents_id_fk", "tableFrom": "join_requests", + "tableTo": "agents", "columnsFrom": [ "created_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -35219,9 +36480,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "labels_company_name_idx": { "name": "labels_company_name_idx", @@ -35240,24 +36501,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "labels_company_id_companies_id_fk": { "name": "labels_company_id_companies_id_fk", "tableFrom": "labels", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -35407,9 +36668,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "managed_agent_profiles_company_key_uq": { "name": "managed_agent_profiles_company_key_uq", @@ -35428,9 +36689,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "managed_agent_profiles_company_resource_uq": { "name": "managed_agent_profiles_company_resource_uq", @@ -35461,37 +36722,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "managed_agent_profiles_company_id_companies_id_fk": { "name": "managed_agent_profiles_company_id_companies_id_fk", "tableFrom": "managed_agent_profiles", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "managed_agent_profiles_api_key_secret_id_company_secrets_id_fk": { "name": "managed_agent_profiles_api_key_secret_id_company_secrets_id_fk", "tableFrom": "managed_agent_profiles", + "tableTo": "company_secrets", "columnsFrom": [ "api_key_secret_id" ], - "tableTo": "company_secrets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -35677,99 +36938,100 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"native_run_finalizations\".\"control_deadline_at\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "native_run_finalizations_company_id_companies_id_fk": { "name": "native_run_finalizations_company_id_companies_id_fk", "tableFrom": "native_run_finalizations", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "native_run_finalizations_issue_company_fk": { "name": "native_run_finalizations_issue_company_fk", "tableFrom": "native_run_finalizations", + "tableTo": "issues", "columnsFrom": [ "company_id", "issue_id" ], - "tableTo": "issues", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "native_run_finalizations_run_owner_fk": { "name": "native_run_finalizations_run_owner_fk", "tableFrom": "native_run_finalizations", + "tableTo": "heartbeat_runs", "columnsFrom": [ "company_id", "issue_id", "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "company_id", "native_issue_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "native_run_finalizations_result_owner_fk": { "name": "native_run_finalizations_result_owner_fk", "tableFrom": "native_run_finalizations", + "tableTo": "native_run_results", "columnsFrom": [ "company_id", "issue_id", "run_id", "result_id" ], - "tableTo": "native_run_results", "columnsTo": [ "company_id", "issue_id", "run_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "native_run_finalizations_assessment_owner_fk": { "name": "native_run_finalizations_assessment_owner_fk", "tableFrom": "native_run_finalizations", + "tableTo": "work_assessments", "columnsFrom": [ "company_id", "issue_id", "run_id", "assessment_id" ], - "tableTo": "work_assessments", "columnsTo": [ "company_id", "issue_id", "run_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "native_run_finalizations_decision_owner_fk": { "name": "native_run_finalizations_decision_owner_fk", "tableFrom": "native_run_finalizations", + "tableTo": "status_decisions", "columnsFrom": [ "company_id", "issue_id", @@ -35777,7 +37039,6 @@ "assessment_id", "decision_id" ], - "tableTo": "status_decisions", "columnsTo": [ "company_id", "issue_id", @@ -35785,8 +37046,8 @@ "assessment_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -35913,9 +37174,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "native_run_results_run_caller_result_uq": { "name": "native_run_results_run_caller_result_uq", @@ -35934,9 +37195,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "native_run_results_run_caller_dedupe_uq": { "name": "native_run_results_run_caller_dedupe_uq", @@ -35955,88 +37216,88 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "native_run_results_company_id_companies_id_fk": { "name": "native_run_results_company_id_companies_id_fk", "tableFrom": "native_run_results", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "native_run_results_issue_company_fk": { "name": "native_run_results_issue_company_fk", "tableFrom": "native_run_results", + "tableTo": "issues", "columnsFrom": [ "company_id", "issue_id" ], - "tableTo": "issues", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "native_run_results_run_contract_owner_fk": { "name": "native_run_results_run_contract_owner_fk", "tableFrom": "native_run_results", + "tableTo": "heartbeat_runs", "columnsFrom": [ "company_id", "issue_id", "run_id", "completion_contract_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "company_id", "native_issue_id", "id", "completion_contract_id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "native_run_results_completion_contract_owner_fk": { "name": "native_run_results_completion_contract_owner_fk", "tableFrom": "native_run_results", + "tableTo": "completion_contracts", "columnsFrom": [ "company_id", "issue_id", "completion_contract_id" ], - "tableTo": "completion_contracts", "columnsTo": [ "company_id", "issue_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "native_run_results_company_issue_run_id_uq": { "name": "native_run_results_company_issue_run_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "issue_id", "run_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -36154,9 +37415,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_automation_executions_company_case_idx": { "name": "pipeline_automation_executions_company_case_idx", @@ -36175,9 +37436,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_automation_executions_routine_idx": { "name": "pipeline_automation_executions_routine_idx", @@ -36190,9 +37451,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_automation_executions_execution_issue_idx": { "name": "pipeline_automation_executions_execution_issue_idx", @@ -36205,9 +37466,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_automation_executions_retry_of_execution_idx": { "name": "pipeline_automation_executions_retry_of_execution_idx", @@ -36220,63 +37481,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "pipeline_automation_executions_company_id_companies_id_fk": { "name": "pipeline_automation_executions_company_id_companies_id_fk", "tableFrom": "pipeline_automation_executions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_automation_executions_case_id_pipeline_cases_id_fk": { "name": "pipeline_automation_executions_case_id_pipeline_cases_id_fk", "tableFrom": "pipeline_automation_executions", + "tableTo": "pipeline_cases", "columnsFrom": [ "case_id" ], - "tableTo": "pipeline_cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_automation_executions_routine_id_routines_id_fk": { "name": "pipeline_automation_executions_routine_id_routines_id_fk", "tableFrom": "pipeline_automation_executions", + "tableTo": "routines", "columnsFrom": [ "routine_id" ], - "tableTo": "routines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_automation_executions_execution_issue_id_issues_id_fk": { "name": "pipeline_automation_executions_execution_issue_id_issues_id_fk", "tableFrom": "pipeline_automation_executions", + "tableTo": "issues", "columnsFrom": [ "execution_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -36352,9 +37613,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_case_blockers_blocked_by_idx": { "name": "pipeline_case_blockers_blocked_by_idx", @@ -36367,9 +37628,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_case_blockers_company_case_idx": { "name": "pipeline_case_blockers_company_case_idx", @@ -36388,50 +37649,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "pipeline_case_blockers_company_id_companies_id_fk": { "name": "pipeline_case_blockers_company_id_companies_id_fk", "tableFrom": "pipeline_case_blockers", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_case_blockers_case_id_pipeline_cases_id_fk": { "name": "pipeline_case_blockers_case_id_pipeline_cases_id_fk", "tableFrom": "pipeline_case_blockers", + "tableTo": "pipeline_cases", "columnsFrom": [ "case_id" ], - "tableTo": "pipeline_cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_case_blockers_blocked_by_case_id_pipeline_cases_id_fk": { "name": "pipeline_case_blockers_blocked_by_case_id_pipeline_cases_id_fk", "tableFrom": "pipeline_case_blockers", + "tableTo": "pipeline_cases", "columnsFrom": [ "blocked_by_case_id" ], - "tableTo": "pipeline_cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -36519,9 +37780,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_case_documents_document_uq": { "name": "pipeline_case_documents_document_uq", @@ -36534,9 +37795,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_case_documents_company_case_updated_idx": { "name": "pipeline_case_documents_company_case_updated_idx", @@ -36561,50 +37822,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "pipeline_case_documents_company_id_companies_id_fk": { "name": "pipeline_case_documents_company_id_companies_id_fk", "tableFrom": "pipeline_case_documents", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_case_documents_case_id_pipeline_cases_id_fk": { "name": "pipeline_case_documents_case_id_pipeline_cases_id_fk", "tableFrom": "pipeline_case_documents", + "tableTo": "pipeline_cases", "columnsFrom": [ "case_id" ], - "tableTo": "pipeline_cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_case_documents_document_id_documents_id_fk": { "name": "pipeline_case_documents_document_id_documents_id_fk", "tableFrom": "pipeline_case_documents", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -36718,9 +37979,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_case_events_company_case_idx": { "name": "pipeline_case_events_company_case_idx", @@ -36739,76 +38000,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "pipeline_case_events_company_id_companies_id_fk": { "name": "pipeline_case_events_company_id_companies_id_fk", "tableFrom": "pipeline_case_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_case_events_case_id_pipeline_cases_id_fk": { "name": "pipeline_case_events_case_id_pipeline_cases_id_fk", "tableFrom": "pipeline_case_events", + "tableTo": "pipeline_cases", "columnsFrom": [ "case_id" ], - "tableTo": "pipeline_cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_case_events_actor_agent_id_agents_id_fk": { "name": "pipeline_case_events_actor_agent_id_agents_id_fk", "tableFrom": "pipeline_case_events", + "tableTo": "agents", "columnsFrom": [ "actor_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "pipeline_case_events_from_stage_id_pipeline_stages_id_fk": { "name": "pipeline_case_events_from_stage_id_pipeline_stages_id_fk", "tableFrom": "pipeline_case_events", + "tableTo": "pipeline_stages", "columnsFrom": [ "from_stage_id" ], - "tableTo": "pipeline_stages", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "pipeline_case_events_to_stage_id_pipeline_stages_id_fk": { "name": "pipeline_case_events_to_stage_id_pipeline_stages_id_fk", "tableFrom": "pipeline_case_events", + "tableTo": "pipeline_stages", "columnsFrom": [ "to_stage_id" ], - "tableTo": "pipeline_stages", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -36928,9 +38189,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_case_issue_links_issue_idx": { "name": "pipeline_case_issue_links_issue_idx", @@ -36943,9 +38204,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_case_issue_links_company_case_idx": { "name": "pipeline_case_issue_links_company_case_idx", @@ -36964,9 +38225,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_case_issue_links_automation_attempt_idx": { "name": "pipeline_case_issue_links_automation_attempt_idx", @@ -36979,50 +38240,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "pipeline_case_issue_links_company_id_companies_id_fk": { "name": "pipeline_case_issue_links_company_id_companies_id_fk", "tableFrom": "pipeline_case_issue_links", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_case_issue_links_case_id_pipeline_cases_id_fk": { "name": "pipeline_case_issue_links_case_id_pipeline_cases_id_fk", "tableFrom": "pipeline_case_issue_links", + "tableTo": "pipeline_cases", "columnsFrom": [ "case_id" ], - "tableTo": "pipeline_cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_case_issue_links_issue_id_issues_id_fk": { "name": "pipeline_case_issue_links_issue_id_issues_id_fk", "tableFrom": "pipeline_case_issue_links", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -37264,9 +38525,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_cases_parent_request_key_uq": { "name": "pipeline_cases_parent_request_key_uq", @@ -37285,10 +38546,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"pipeline_cases\".\"request_key\" is not null and \"pipeline_cases\".\"retired_at\" is null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "pipeline_cases_company_idx": { "name": "pipeline_cases_company_idx", @@ -37301,9 +38562,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_cases_pipeline_stage_idx": { "name": "pipeline_cases_pipeline_stage_idx", @@ -37322,9 +38583,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_cases_parent_idx": { "name": "pipeline_cases_parent_idx", @@ -37337,9 +38598,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_cases_automation_attempt_idx": { "name": "pipeline_cases_automation_attempt_idx", @@ -37352,9 +38613,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_cases_retired_idx": { "name": "pipeline_cases_retired_idx", @@ -37373,9 +38634,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_cases_lease_expires_idx": { "name": "pipeline_cases_lease_expires_idx", @@ -37388,90 +38649,90 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"pipeline_cases\".\"lease_expires_at\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "pipeline_cases_company_id_companies_id_fk": { "name": "pipeline_cases_company_id_companies_id_fk", "tableFrom": "pipeline_cases", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_cases_pipeline_id_pipelines_id_fk": { "name": "pipeline_cases_pipeline_id_pipelines_id_fk", "tableFrom": "pipeline_cases", + "tableTo": "pipelines", "columnsFrom": [ "pipeline_id" ], - "tableTo": "pipelines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_cases_stage_id_pipeline_stages_id_fk": { "name": "pipeline_cases_stage_id_pipeline_stages_id_fk", "tableFrom": "pipeline_cases", + "tableTo": "pipeline_stages", "columnsFrom": [ "stage_id" ], - "tableTo": "pipeline_stages", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "pipeline_cases_parent_case_id_pipeline_cases_id_fk": { "name": "pipeline_cases_parent_case_id_pipeline_cases_id_fk", "tableFrom": "pipeline_cases", + "tableTo": "pipeline_cases", "columnsFrom": [ "parent_case_id" ], - "tableTo": "pipeline_cases", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "pipeline_cases_lease_agent_id_agents_id_fk": { "name": "pipeline_cases_lease_agent_id_agents_id_fk", "tableFrom": "pipeline_cases", + "tableTo": "agents", "columnsFrom": [ "lease_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "pipeline_cases_created_by_agent_id_agents_id_fk": { "name": "pipeline_cases_created_by_agent_id_agents_id_fk", "tableFrom": "pipeline_cases", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -37563,9 +38824,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_documents_document_uq": { "name": "pipeline_documents_document_uq", @@ -37578,9 +38839,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_documents_company_pipeline_updated_idx": { "name": "pipeline_documents_company_pipeline_updated_idx", @@ -37605,50 +38866,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "pipeline_documents_company_id_companies_id_fk": { "name": "pipeline_documents_company_id_companies_id_fk", "tableFrom": "pipeline_documents", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_documents_pipeline_id_pipelines_id_fk": { "name": "pipeline_documents_pipeline_id_pipelines_id_fk", "tableFrom": "pipeline_documents", + "tableTo": "pipelines", "columnsFrom": [ "pipeline_id" ], - "tableTo": "pipelines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_documents_document_id_documents_id_fk": { "name": "pipeline_documents_document_id_documents_id_fk", "tableFrom": "pipeline_documents", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -37738,9 +38999,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_stages_pipeline_position_idx": { "name": "pipeline_stages_pipeline_position_idx", @@ -37759,24 +39020,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "pipeline_stages_pipeline_id_pipelines_id_fk": { "name": "pipeline_stages_pipeline_id_pipelines_id_fk", "tableFrom": "pipeline_stages", + "tableTo": "pipelines", "columnsFrom": [ "pipeline_id" ], - "tableTo": "pipelines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -37864,9 +39125,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_transitions_pipeline_from_idx": { "name": "pipeline_transitions_pipeline_from_idx", @@ -37885,9 +39146,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipeline_transitions_pipeline_to_idx": { "name": "pipeline_transitions_pipeline_to_idx", @@ -37906,50 +39167,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "pipeline_transitions_pipeline_id_pipelines_id_fk": { "name": "pipeline_transitions_pipeline_id_pipelines_id_fk", "tableFrom": "pipeline_transitions", + "tableTo": "pipelines", "columnsFrom": [ "pipeline_id" ], - "tableTo": "pipelines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_transitions_from_stage_id_pipeline_stages_id_fk": { "name": "pipeline_transitions_from_stage_id_pipeline_stages_id_fk", "tableFrom": "pipeline_transitions", + "tableTo": "pipeline_stages", "columnsFrom": [ "from_stage_id" ], - "tableTo": "pipeline_stages", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipeline_transitions_to_stage_id_pipeline_stages_id_fk": { "name": "pipeline_transitions_to_stage_id_pipeline_stages_id_fk", "tableFrom": "pipeline_transitions", + "tableTo": "pipeline_stages", "columnsFrom": [ "to_stage_id" ], - "tableTo": "pipeline_stages", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -38057,9 +39318,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipelines_company_idx": { "name": "pipelines_company_idx", @@ -38072,9 +39333,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "pipelines_company_project_idx": { "name": "pipelines_company_project_idx", @@ -38093,50 +39354,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "pipelines_company_id_companies_id_fk": { "name": "pipelines_company_id_companies_id_fk", "tableFrom": "pipelines", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "pipelines_project_id_projects_id_fk": { "name": "pipelines_project_id_projects_id_fk", "tableFrom": "pipelines", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "pipelines_created_by_agent_id_agents_id_fk": { "name": "pipelines_created_by_agent_id_agents_id_fk", "tableFrom": "pipelines", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -38215,9 +39476,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_company_settings_plugin_idx": { "name": "plugin_company_settings_plugin_idx", @@ -38230,9 +39491,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_company_settings_company_plugin_uq": { "name": "plugin_company_settings_company_plugin_uq", @@ -38251,37 +39512,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_company_settings_company_id_companies_id_fk": { "name": "plugin_company_settings_company_id_companies_id_fk", "tableFrom": "plugin_company_settings", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "plugin_company_settings_plugin_id_plugins_id_fk": { "name": "plugin_company_settings_plugin_id_plugins_id_fk", "tableFrom": "plugin_company_settings", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -38359,37 +39620,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_config_plugin_id_plugins_id_fk": { "name": "plugin_config_plugin_id_plugins_id_fk", "tableFrom": "plugin_config", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "plugin_config_company_id_companies_id_fk": { "name": "plugin_config_company_id_companies_id_fk", "tableFrom": "plugin_config", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -38468,9 +39729,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_database_namespaces_namespace_idx": { "name": "plugin_database_namespaces_namespace_idx", @@ -38483,9 +39744,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_database_namespaces_status_idx": { "name": "plugin_database_namespaces_status_idx", @@ -38498,24 +39759,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_database_namespaces_plugin_id_plugins_id_fk": { "name": "plugin_database_namespaces_plugin_id_plugins_id_fk", "tableFrom": "plugin_database_namespaces", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -38617,9 +39878,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_entities_company_idx": { "name": "plugin_entities_company_idx", @@ -38632,9 +39893,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_entities_type_idx": { "name": "plugin_entities_type_idx", @@ -38647,9 +39908,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_entities_scope_idx": { "name": "plugin_entities_scope_idx", @@ -38668,50 +39929,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_entities_plugin_id_plugins_id_fk": { "name": "plugin_entities_plugin_id_plugins_id_fk", "tableFrom": "plugin_entities", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "plugin_entities_company_id_companies_id_fk": { "name": "plugin_entities_company_id_companies_id_fk", "tableFrom": "plugin_entities", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "plugin_entities_external_idx": { "name": "plugin_entities_external_idx", + "nullsNotDistinct": true, "columns": [ "company_id", "plugin_id", "entity_type", "external_id" - ], - "nullsNotDistinct": true + ] } }, "policies": {}, @@ -38811,9 +40072,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_job_runs_plugin_idx": { "name": "plugin_job_runs_plugin_idx", @@ -38826,9 +40087,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_job_runs_company_idx": { "name": "plugin_job_runs_company_idx", @@ -38841,9 +40102,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_job_runs_status_idx": { "name": "plugin_job_runs_status_idx", @@ -38856,50 +40117,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_job_runs_job_id_plugin_jobs_id_fk": { "name": "plugin_job_runs_job_id_plugin_jobs_id_fk", "tableFrom": "plugin_job_runs", + "tableTo": "plugin_jobs", "columnsFrom": [ "job_id" ], - "tableTo": "plugin_jobs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "plugin_job_runs_plugin_id_plugins_id_fk": { "name": "plugin_job_runs_plugin_id_plugins_id_fk", "tableFrom": "plugin_job_runs", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "plugin_job_runs_company_id_companies_id_fk": { "name": "plugin_job_runs_company_id_companies_id_fk", "tableFrom": "plugin_job_runs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -38983,9 +40244,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_jobs_next_run_idx": { "name": "plugin_jobs_next_run_idx", @@ -38998,9 +40259,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_jobs_unique_idx": { "name": "plugin_jobs_unique_idx", @@ -39019,24 +40280,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_jobs_plugin_id_plugins_id_fk": { "name": "plugin_jobs_plugin_id_plugins_id_fk", "tableFrom": "plugin_jobs", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -39081,37 +40342,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_lifecycle_acknowledgments_plugin_id_plugins_id_fk": { "name": "plugin_lifecycle_acknowledgments_plugin_id_plugins_id_fk", "tableFrom": "plugin_lifecycle_acknowledgments", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "plugin_lifecycle_acknowledgments_event_id_resource_lifecycle_events_id_fk": { "name": "plugin_lifecycle_acknowledgments_event_id_resource_lifecycle_events_id_fk", "tableFrom": "plugin_lifecycle_acknowledgments", + "tableTo": "resource_lifecycle_events", "columnsFrom": [ "event_id" ], - "tableTo": "resource_lifecycle_events", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": { @@ -39196,9 +40457,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_logs_company_idx": { "name": "plugin_logs_company_idx", @@ -39211,9 +40472,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_logs_level_idx": { "name": "plugin_logs_level_idx", @@ -39226,37 +40487,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_logs_plugin_id_plugins_id_fk": { "name": "plugin_logs_plugin_id_plugins_id_fk", "tableFrom": "plugin_logs", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "plugin_logs_company_id_companies_id_fk": { "name": "plugin_logs_company_id_companies_id_fk", "tableFrom": "plugin_logs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -39346,9 +40607,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_managed_resources_plugin_idx": { "name": "plugin_managed_resources_plugin_idx", @@ -39361,9 +40622,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_managed_resources_resource_idx": { "name": "plugin_managed_resources_resource_idx", @@ -39382,9 +40643,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_managed_resources_company_plugin_resource_uq": { "name": "plugin_managed_resources_company_plugin_resource_uq", @@ -39415,37 +40676,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_managed_resources_company_id_companies_id_fk": { "name": "plugin_managed_resources_company_id_companies_id_fk", "tableFrom": "plugin_managed_resources", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "plugin_managed_resources_plugin_id_plugins_id_fk": { "name": "plugin_managed_resources_plugin_id_plugins_id_fk", "tableFrom": "plugin_managed_resources", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -39545,9 +40806,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_migrations_plugin_idx": { "name": "plugin_migrations_plugin_idx", @@ -39560,9 +40821,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_migrations_status_idx": { "name": "plugin_migrations_status_idx", @@ -39575,24 +40836,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_migrations_plugin_id_plugins_id_fk": { "name": "plugin_migrations_plugin_id_plugins_id_fk", "tableFrom": "plugin_migrations", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -39675,38 +40936,38 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_state_plugin_id_plugins_id_fk": { "name": "plugin_state_plugin_id_plugins_id_fk", "tableFrom": "plugin_state", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "plugin_state_unique_entry_idx": { "name": "plugin_state_unique_entry_idx", + "nullsNotDistinct": true, "columns": [ "plugin_id", "scope_kind", "scope_id", "namespace", "state_key" - ], - "nullsNotDistinct": true + ] } }, "policies": {}, @@ -39812,9 +41073,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_webhook_deliveries_company_idx": { "name": "plugin_webhook_deliveries_company_idx", @@ -39827,9 +41088,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_webhook_deliveries_status_idx": { "name": "plugin_webhook_deliveries_status_idx", @@ -39842,9 +41103,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugin_webhook_deliveries_key_idx": { "name": "plugin_webhook_deliveries_key_idx", @@ -39857,37 +41118,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "plugin_webhook_deliveries_plugin_id_plugins_id_fk": { "name": "plugin_webhook_deliveries_plugin_id_plugins_id_fk", "tableFrom": "plugin_webhook_deliveries", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "plugin_webhook_deliveries_company_id_companies_id_fk": { "name": "plugin_webhook_deliveries_company_id_companies_id_fk", "tableFrom": "plugin_webhook_deliveries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -39997,9 +41258,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "plugins_status_idx": { "name": "plugins_status_idx", @@ -40012,9 +41273,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": {}, @@ -40116,9 +41377,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "principal_permission_grants_company_permission_idx": { "name": "principal_permission_grants_company_permission_idx", @@ -40137,24 +41398,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "principal_permission_grants_company_id_companies_id_fk": { "name": "principal_permission_grants_company_id_companies_id_fk", "tableFrom": "principal_permission_grants", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -40230,9 +41491,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_access_members_subject_lookup_idx": { "name": "project_access_members_subject_lookup_idx", @@ -40263,37 +41524,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "project_access_members_company_id_companies_id_fk": { "name": "project_access_members_company_id_companies_id_fk", "tableFrom": "project_access_members", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "project_access_members_project_id_projects_id_fk": { "name": "project_access_members_project_id_projects_id_fk", "tableFrom": "project_access_members", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -40356,9 +41617,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_goals_goal_idx": { "name": "project_goals_goal_idx", @@ -40371,9 +41632,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_goals_company_idx": { "name": "project_goals_company_idx", @@ -40386,50 +41647,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "project_goals_project_id_projects_id_fk": { "name": "project_goals_project_id_projects_id_fk", "tableFrom": "project_goals", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "project_goals_goal_id_goals_id_fk": { "name": "project_goals_goal_id_goals_id_fk", "tableFrom": "project_goals", + "tableTo": "goals", "columnsFrom": [ "goal_id" ], - "tableTo": "goals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "project_goals_company_id_companies_id_fk": { "name": "project_goals_company_id_companies_id_fk", "tableFrom": "project_goals", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": { @@ -40521,9 +41782,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_memberships_company_user_starred_idx": { "name": "project_memberships_company_user_starred_idx", @@ -40548,9 +41809,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_memberships_project_idx": { "name": "project_memberships_project_idx", @@ -40563,9 +41824,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_memberships_company_user_project_uq": { "name": "project_memberships_company_user_project_uq", @@ -40590,37 +41851,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "project_memberships_company_id_companies_id_fk": { "name": "project_memberships_company_id_companies_id_fk", "tableFrom": "project_memberships", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "project_memberships_project_id_projects_id_fk": { "name": "project_memberships_project_id_projects_id_fk", "tableFrom": "project_memberships", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -40772,9 +42033,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_workspaces_project_primary_idx": { "name": "project_workspaces_project_primary_idx", @@ -40793,9 +42054,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_workspaces_project_source_type_idx": { "name": "project_workspaces_project_source_type_idx", @@ -40814,9 +42075,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_workspaces_company_shared_key_idx": { "name": "project_workspaces_company_shared_key_idx", @@ -40835,9 +42096,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "project_workspaces_project_remote_ref_idx": { "name": "project_workspaces_project_remote_ref_idx", @@ -40862,37 +42123,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "project_workspaces_company_id_companies_id_fk": { "name": "project_workspaces_company_id_companies_id_fk", "tableFrom": "project_workspaces", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "project_workspaces_project_id_projects_id_fk": { "name": "project_workspaces_project_id_projects_id_fk", "tableFrom": "project_workspaces", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -41043,9 +42304,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "projects_company_personal_owner_uq": { "name": "projects_company_personal_owner_uq", @@ -41064,51 +42325,51 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"projects\".\"personal_owner_user_id\" is not null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "projects_company_id_companies_id_fk": { "name": "projects_company_id_companies_id_fk", "tableFrom": "projects", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "projects_goal_id_goals_id_fk": { "name": "projects_goal_id_goals_id_fk", "tableFrom": "projects", + "tableTo": "goals", "columnsFrom": [ "goal_id" ], - "tableTo": "goals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "projects_lead_agent_id_agents_id_fk": { "name": "projects_lead_agent_id_agents_id_fk", "tableFrom": "projects", + "tableTo": "agents", "columnsFrom": [ "lead_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -41235,9 +42496,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "provider_trace_records_expiry_idx": { "name": "provider_trace_records_expiry_idx", @@ -41256,9 +42517,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "provider_trace_records_company_created_idx": { "name": "provider_trace_records_company_created_idx", @@ -41277,37 +42538,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "provider_trace_records_company_id_companies_id_fk": { "name": "provider_trace_records_company_id_companies_id_fk", "tableFrom": "provider_trace_records", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "provider_trace_records_run_id_heartbeat_runs_id_fk": { "name": "provider_trace_records_run_id_heartbeat_runs_id_fk", "tableFrom": "provider_trace_records", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -41418,9 +42679,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "remote_agent_profiles_company_key_uq": { "name": "remote_agent_profiles_company_key_uq", @@ -41439,24 +42700,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "remote_agent_profiles_company_id_companies_id_fk": { "name": "remote_agent_profiles_company_id_companies_id_fk", "tableFrom": "remote_agent_profiles", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -41484,15 +42745,15 @@ "primaryKey": true, "notNull": true, "identity": { + "type": "always", "name": "resource_lifecycle_events_id_seq", + "schema": "public", "increment": "1", + "startWith": "1", "minValue": "1", "maxValue": "9223372036854775807", - "startWith": "1", "cache": "1", - "cycle": false, - "schema": "public", - "type": "always" + "cycle": false } }, "company_id": { @@ -41551,10 +42812,10 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"resource_lifecycle_events\".\"action\" = 'create'", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} }, "resource_lifecycle_events_company_idx": { "name": "resource_lifecycle_events_company_idx", @@ -41573,9 +42834,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "resource_lifecycle_events_resource_order_idx": { "name": "resource_lifecycle_events_resource_order_idx", @@ -41606,24 +42867,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "resource_lifecycle_events_company_id_companies_id_fk": { "name": "resource_lifecycle_events_company_id_companies_id_fk", "tableFrom": "resource_lifecycle_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -41715,9 +42976,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_documents_document_uq": { "name": "routine_documents_document_uq", @@ -41730,9 +42991,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_documents_company_routine_updated_idx": { "name": "routine_documents_company_routine_updated_idx", @@ -41757,50 +43018,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "routine_documents_company_id_companies_id_fk": { "name": "routine_documents_company_id_companies_id_fk", "tableFrom": "routine_documents", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "routine_documents_routine_id_routines_id_fk": { "name": "routine_documents_routine_id_routines_id_fk", "tableFrom": "routine_documents", + "tableTo": "routines", "columnsFrom": [ "routine_id" ], - "tableTo": "routines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routine_documents_document_id_documents_id_fk": { "name": "routine_documents_document_id_documents_id_fk", "tableFrom": "routine_documents", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -41918,9 +43179,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_revisions_company_routine_created_idx": { "name": "routine_revisions_company_routine_created_idx", @@ -41945,9 +43206,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_revisions_company_responsible_user_idx": { "name": "routine_revisions_company_responsible_user_idx", @@ -41972,76 +43233,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "routine_revisions_company_id_companies_id_fk": { "name": "routine_revisions_company_id_companies_id_fk", "tableFrom": "routine_revisions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routine_revisions_routine_id_routines_id_fk": { "name": "routine_revisions_routine_id_routines_id_fk", "tableFrom": "routine_revisions", + "tableTo": "routines", "columnsFrom": [ "routine_id" ], - "tableTo": "routines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routine_revisions_restored_from_revision_id_routine_revisions_id_fk": { "name": "routine_revisions_restored_from_revision_id_routine_revisions_id_fk", "tableFrom": "routine_revisions", + "tableTo": "routine_revisions", "columnsFrom": [ "restored_from_revision_id" ], - "tableTo": "routine_revisions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routine_revisions_created_by_agent_id_agents_id_fk": { "name": "routine_revisions_created_by_agent_id_agents_id_fk", "tableFrom": "routine_revisions", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routine_revisions_created_by_run_id_heartbeat_runs_id_fk": { "name": "routine_revisions_created_by_run_id_heartbeat_runs_id_fk", "tableFrom": "routine_revisions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "created_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -42192,9 +43453,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_runs_revision_idx": { "name": "routine_runs_revision_idx", @@ -42207,9 +43468,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_runs_company_responsible_user_idx": { "name": "routine_runs_company_responsible_user_idx", @@ -42234,9 +43495,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_runs_trigger_idx": { "name": "routine_runs_trigger_idx", @@ -42255,9 +43516,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_runs_dispatch_fingerprint_idx": { "name": "routine_runs_dispatch_fingerprint_idx", @@ -42276,9 +43537,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_runs_linked_issue_idx": { "name": "routine_runs_linked_issue_idx", @@ -42291,9 +43552,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_runs_trigger_idempotency_idx": { "name": "routine_runs_trigger_idempotency_idx", @@ -42312,76 +43573,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "routine_runs_company_id_companies_id_fk": { "name": "routine_runs_company_id_companies_id_fk", "tableFrom": "routine_runs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routine_runs_routine_id_routines_id_fk": { "name": "routine_runs_routine_id_routines_id_fk", "tableFrom": "routine_runs", + "tableTo": "routines", "columnsFrom": [ "routine_id" ], - "tableTo": "routines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routine_runs_trigger_id_routine_triggers_id_fk": { "name": "routine_runs_trigger_id_routine_triggers_id_fk", "tableFrom": "routine_runs", + "tableTo": "routine_triggers", "columnsFrom": [ "trigger_id" ], - "tableTo": "routine_triggers", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routine_runs_routine_revision_id_routine_revisions_id_fk": { "name": "routine_runs_routine_revision_id_routine_revisions_id_fk", "tableFrom": "routine_runs", + "tableTo": "routine_revisions", "columnsFrom": [ "routine_revision_id" ], - "tableTo": "routine_revisions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routine_runs_linked_issue_id_issues_id_fk": { "name": "routine_runs_linked_issue_id_issues_id_fk", "tableFrom": "routine_runs", + "tableTo": "issues", "columnsFrom": [ "linked_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -42569,9 +43830,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_triggers_company_kind_idx": { "name": "routine_triggers_company_kind_idx", @@ -42590,9 +43851,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_triggers_next_run_idx": { "name": "routine_triggers_next_run_idx", @@ -42605,9 +43866,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_triggers_public_id_idx": { "name": "routine_triggers_public_id_idx", @@ -42620,9 +43881,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routine_triggers_public_id_uq": { "name": "routine_triggers_public_id_uq", @@ -42635,76 +43896,76 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "routine_triggers_company_id_companies_id_fk": { "name": "routine_triggers_company_id_companies_id_fk", "tableFrom": "routine_triggers", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routine_triggers_routine_id_routines_id_fk": { "name": "routine_triggers_routine_id_routines_id_fk", "tableFrom": "routine_triggers", + "tableTo": "routines", "columnsFrom": [ "routine_id" ], - "tableTo": "routines", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routine_triggers_secret_id_company_secrets_id_fk": { "name": "routine_triggers_secret_id_company_secrets_id_fk", "tableFrom": "routine_triggers", + "tableTo": "company_secrets", "columnsFrom": [ "secret_id" ], - "tableTo": "company_secrets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routine_triggers_created_by_agent_id_agents_id_fk": { "name": "routine_triggers_created_by_agent_id_agents_id_fk", "tableFrom": "routine_triggers", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routine_triggers_updated_by_agent_id_agents_id_fk": { "name": "routine_triggers_updated_by_agent_id_agents_id_fk", "tableFrom": "routine_triggers", + "tableTo": "agents", "columnsFrom": [ "updated_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -42768,37 +44029,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "routine_webhook_test_receipts_company_id_companies_id_fk": { "name": "routine_webhook_test_receipts_company_id_companies_id_fk", "tableFrom": "routine_webhook_test_receipts", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routine_webhook_test_receipts_trigger_id_routine_triggers_id_fk": { "name": "routine_webhook_test_receipts_trigger_id_routine_triggers_id_fk", "tableFrom": "routine_webhook_test_receipts", + "tableTo": "routine_triggers", "columnsFrom": [ "trigger_id" ], - "tableTo": "routine_triggers", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -43022,9 +44283,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routines_company_assignee_idx": { "name": "routines_company_assignee_idx", @@ -43043,9 +44304,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routines_company_project_idx": { "name": "routines_company_project_idx", @@ -43064,9 +44325,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routines_company_folder_idx": { "name": "routines_company_folder_idx", @@ -43085,9 +44346,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routines_company_responsible_user_idx": { "name": "routines_company_responsible_user_idx", @@ -43106,9 +44367,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "routines_company_origin_idx": { "name": "routines_company_origin_idx", @@ -43133,115 +44394,115 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "routines_company_id_companies_id_fk": { "name": "routines_company_id_companies_id_fk", "tableFrom": "routines", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routines_project_id_projects_id_fk": { "name": "routines_project_id_projects_id_fk", "tableFrom": "routines", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "routines_folder_id_folders_id_fk": { "name": "routines_folder_id_folders_id_fk", "tableFrom": "routines", + "tableTo": "folders", "columnsFrom": [ "folder_id" ], - "tableTo": "folders", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routines_goal_id_goals_id_fk": { "name": "routines_goal_id_goals_id_fk", "tableFrom": "routines", + "tableTo": "goals", "columnsFrom": [ "goal_id" ], - "tableTo": "goals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routines_parent_issue_id_issues_id_fk": { "name": "routines_parent_issue_id_issues_id_fk", "tableFrom": "routines", + "tableTo": "issues", "columnsFrom": [ "parent_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routines_assignee_agent_id_agents_id_fk": { "name": "routines_assignee_agent_id_agents_id_fk", "tableFrom": "routines", + "tableTo": "agents", "columnsFrom": [ "assignee_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "routines_created_by_agent_id_agents_id_fk": { "name": "routines_created_by_agent_id_agents_id_fk", "tableFrom": "routines", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "routines_updated_by_agent_id_agents_id_fk": { "name": "routines_updated_by_agent_id_agents_id_fk", "tableFrom": "routines", + "tableTo": "agents", "columnsFrom": [ "updated_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -43354,9 +44615,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "run_identity_contexts_run_correlation_idx": { "name": "run_identity_contexts_run_correlation_idx", @@ -43375,9 +44636,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "run_identity_contexts_company_run_idx": { "name": "run_identity_contexts_company_run_idx", @@ -43396,24 +44657,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "run_identity_contexts_company_id_companies_id_fk": { "name": "run_identity_contexts_company_id_companies_id_fk", "tableFrom": "run_identity_contexts", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -43477,50 +44738,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "runner_api_response_reservations_company_id_companies_id_fk": { "name": "runner_api_response_reservations_company_id_companies_id_fk", "tableFrom": "runner_api_response_reservations", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "runner_api_response_reservations_run_id_heartbeat_runs_id_fk": { "name": "runner_api_response_reservations_run_id_heartbeat_runs_id_fk", "tableFrom": "runner_api_response_reservations", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "runner_api_response_reservations_asset_id_assets_id_fk": { "name": "runner_api_response_reservations_asset_id_assets_id_fk", "tableFrom": "runner_api_response_reservations", + "tableTo": "assets", "columnsFrom": [ "asset_id" ], - "tableTo": "assets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -43687,9 +44948,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "secret_access_events_secret_created_idx": { "name": "secret_access_events_secret_created_idx", @@ -43708,9 +44969,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "secret_access_events_user_definition_created_idx": { "name": "secret_access_events_user_definition_created_idx", @@ -43729,9 +44990,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "secret_access_events_company_credential_owner_idx": { "name": "secret_access_events_company_credential_owner_idx", @@ -43756,9 +45017,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "secret_access_events_consumer_idx": { "name": "secret_access_events_consumer_idx", @@ -43783,9 +45044,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "secret_access_events_run_idx": { "name": "secret_access_events_run_idx", @@ -43798,89 +45059,89 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "secret_access_events_company_id_companies_id_fk": { "name": "secret_access_events_company_id_companies_id_fk", "tableFrom": "secret_access_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "secret_access_events_secret_id_company_secrets_id_fk": { "name": "secret_access_events_secret_id_company_secrets_id_fk", "tableFrom": "secret_access_events", + "tableTo": "company_secrets", "columnsFrom": [ "secret_id" ], - "tableTo": "company_secrets", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "secret_access_events_user_secret_definition_id_user_secret_definitions_id_fk": { "name": "secret_access_events_user_secret_definition_id_user_secret_definitions_id_fk", "tableFrom": "secret_access_events", + "tableTo": "user_secret_definitions", "columnsFrom": [ "user_secret_definition_id" ], - "tableTo": "user_secret_definitions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "secret_access_events_issue_id_issues_id_fk": { "name": "secret_access_events_issue_id_issues_id_fk", "tableFrom": "secret_access_events", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "secret_access_events_heartbeat_run_id_heartbeat_runs_id_fk": { "name": "secret_access_events_heartbeat_run_id_heartbeat_runs_id_fk", "tableFrom": "secret_access_events", + "tableTo": "heartbeat_runs", "columnsFrom": [ "heartbeat_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "secret_access_events_plugin_id_plugins_id_fk": { "name": "secret_access_events_plugin_id_plugins_id_fk", "tableFrom": "secret_access_events", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -43981,9 +45242,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "smoke_run_steps_company_path_idx": { "name": "smoke_run_steps_company_path_idx", @@ -44002,37 +45263,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "smoke_run_steps_company_id_companies_id_fk": { "name": "smoke_run_steps_company_id_companies_id_fk", "tableFrom": "smoke_run_steps", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "smoke_run_steps_run_id_smoke_runs_id_fk": { "name": "smoke_run_steps_run_id_smoke_runs_id_fk", "tableFrom": "smoke_run_steps", + "tableTo": "smoke_runs", "columnsFrom": [ "run_id" ], - "tableTo": "smoke_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -44124,9 +45385,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "smoke_runs_company_status_idx": { "name": "smoke_runs_company_status_idx", @@ -44145,24 +45406,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "smoke_runs_company_id_companies_id_fk": { "name": "smoke_runs_company_id_companies_id_fk", "tableFrom": "smoke_runs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -44302,9 +45563,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "status_card_updates_generation_issue_idx": { "name": "status_card_updates_generation_issue_idx", @@ -44317,50 +45578,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "status_card_updates_card_id_status_cards_id_fk": { "name": "status_card_updates_card_id_status_cards_id_fk", "tableFrom": "status_card_updates", + "tableTo": "status_cards", "columnsFrom": [ "card_id" ], - "tableTo": "status_cards", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "status_card_updates_generation_issue_id_issues_id_fk": { "name": "status_card_updates_generation_issue_id_issues_id_fk", "tableFrom": "status_card_updates", + "tableTo": "issues", "columnsFrom": [ "generation_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "status_card_updates_run_id_heartbeat_runs_id_fk": { "name": "status_card_updates_run_id_heartbeat_runs_id_fk", "tableFrom": "status_card_updates", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -44593,9 +45854,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "status_cards_company_next_eval_idx": { "name": "status_cards_company_next_eval_idx", @@ -44614,102 +45875,102 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "status_cards_company_id_companies_id_fk": { "name": "status_cards_company_id_companies_id_fk", "tableFrom": "status_cards", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "status_cards_created_by_agent_id_agents_id_fk": { "name": "status_cards_created_by_agent_id_agents_id_fk", "tableFrom": "status_cards", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "status_cards_query_compiled_by_agent_id_agents_id_fk": { "name": "status_cards_query_compiled_by_agent_id_agents_id_fk", "tableFrom": "status_cards", + "tableTo": "agents", "columnsFrom": [ "query_compiled_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "status_cards_agent_id_agents_id_fk": { "name": "status_cards_agent_id_agents_id_fk", "tableFrom": "status_cards", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "status_cards_document_id_documents_id_fk": { "name": "status_cards_document_id_documents_id_fk", "tableFrom": "status_cards", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "status_cards_generating_issue_id_issues_id_fk": { "name": "status_cards_generating_issue_id_issues_id_fk", "tableFrom": "status_cards", + "tableTo": "issues", "columnsFrom": [ "generating_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "status_cards_archived_by_agent_id_agents_id_fk": { "name": "status_cards_archived_by_agent_id_agents_id_fk", "tableFrom": "status_cards", + "tableTo": "agents", "columnsFrom": [ "archived_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -44848,9 +46109,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "status_decision_effects_company_idempotency_uq": { "name": "status_decision_effects_company_idempotency_uq", @@ -44869,56 +46130,56 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "status_decision_effects_company_id_companies_id_fk": { "name": "status_decision_effects_company_id_companies_id_fk", "tableFrom": "status_decision_effects", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "status_decision_effects_issue_company_fk": { "name": "status_decision_effects_issue_company_fk", "tableFrom": "status_decision_effects", + "tableTo": "issues", "columnsFrom": [ "company_id", "issue_id" ], - "tableTo": "issues", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "status_decision_effects_decision_owner_fk": { "name": "status_decision_effects_decision_owner_fk", "tableFrom": "status_decision_effects", + "tableTo": "status_decisions", "columnsFrom": [ "company_id", "issue_id", "decision_id" ], - "tableTo": "status_decisions", "columnsTo": [ "company_id", "issue_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -45055,9 +46316,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "status_decisions_company_assessment_uq": { "name": "status_decisions_company_assessment_uq", @@ -45076,9 +46337,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "status_decisions_company_issue_digest_uq": { "name": "status_decisions_company_issue_digest_uq", @@ -45103,98 +46364,98 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "status_decisions_company_id_companies_id_fk": { "name": "status_decisions_company_id_companies_id_fk", "tableFrom": "status_decisions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "status_decisions_issue_company_fk": { "name": "status_decisions_issue_company_fk", "tableFrom": "status_decisions", + "tableTo": "issues", "columnsFrom": [ "company_id", "issue_id" ], - "tableTo": "issues", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "status_decisions_assessment_owner_fk": { "name": "status_decisions_assessment_owner_fk", "tableFrom": "status_decisions", + "tableTo": "work_assessments", "columnsFrom": [ "company_id", "issue_id", "run_id", "assessment_id" ], - "tableTo": "work_assessments", "columnsTo": [ "company_id", "issue_id", "run_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "status_decisions_supersedes_owner_fk": { "name": "status_decisions_supersedes_owner_fk", "tableFrom": "status_decisions", + "tableTo": "status_decisions", "columnsFrom": [ "company_id", "issue_id", "supersedes_decision_id" ], - "tableTo": "status_decisions", "columnsTo": [ "company_id", "issue_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "status_decisions_company_issue_id_uq": { "name": "status_decisions_company_issue_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "issue_id", "id" - ], - "nullsNotDistinct": false + ] }, "status_decisions_company_issue_run_assessment_id_uq": { "name": "status_decisions_company_issue_run_assessment_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "issue_id", "run_id", "assessment_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -45306,9 +46567,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "summary_slots_company_scope_idx": { "name": "summary_slots_company_scope_idx", @@ -45333,9 +46594,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "summary_slots_company_generating_issue_idx": { "name": "summary_slots_company_generating_issue_idx", @@ -45354,9 +46615,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "summary_slots_company_updated_idx": { "name": "summary_slots_company_updated_idx", @@ -45375,76 +46636,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "summary_slots_company_id_companies_id_fk": { "name": "summary_slots_company_id_companies_id_fk", "tableFrom": "summary_slots", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "summary_slots_document_id_documents_id_fk": { "name": "summary_slots_document_id_documents_id_fk", "tableFrom": "summary_slots", + "tableTo": "documents", "columnsFrom": [ "document_id" ], - "tableTo": "documents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "summary_slots_generating_issue_id_issues_id_fk": { "name": "summary_slots_generating_issue_id_issues_id_fk", "tableFrom": "summary_slots", + "tableTo": "issues", "columnsFrom": [ "generating_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "summary_slots_last_generated_by_agent_id_agents_id_fk": { "name": "summary_slots_last_generated_by_agent_id_agents_id_fk", "tableFrom": "summary_slots", + "tableTo": "agents", "columnsFrom": [ "last_generated_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "summary_slots_company_scope_slot_uq": { "name": "summary_slots_company_scope_slot_uq", + "nullsNotDistinct": true, "columns": [ "company_id", "scope_kind", "scope_id", "slot_key" - ], - "nullsNotDistinct": true + ] } }, "policies": {}, @@ -45574,9 +46835,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_access_audit_connection_idx": { "name": "tool_access_audit_connection_idx", @@ -45589,9 +46850,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_access_audit_gateway_idx": { "name": "tool_access_audit_gateway_idx", @@ -45610,76 +46871,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_access_audit_events_company_id_companies_id_fk": { "name": "tool_access_audit_events_company_id_companies_id_fk", "tableFrom": "tool_access_audit_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_access_audit_events_gateway_id_tool_mcp_gateways_id_fk": { "name": "tool_access_audit_events_gateway_id_tool_mcp_gateways_id_fk", "tableFrom": "tool_access_audit_events", + "tableTo": "tool_mcp_gateways", "columnsFrom": [ "gateway_id" ], - "tableTo": "tool_mcp_gateways", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_access_audit_events_gateway_token_id_tool_mcp_gateway_tokens_id_fk": { "name": "tool_access_audit_events_gateway_token_id_tool_mcp_gateway_tokens_id_fk", "tableFrom": "tool_access_audit_events", + "tableTo": "tool_mcp_gateway_tokens", "columnsFrom": [ "gateway_token_id" ], - "tableTo": "tool_mcp_gateway_tokens", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_access_audit_events_connection_id_tool_connections_id_fk": { "name": "tool_access_audit_events_connection_id_tool_connections_id_fk", "tableFrom": "tool_access_audit_events", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_access_audit_events_catalog_entry_id_tool_catalog_entries_id_fk": { "name": "tool_access_audit_events_catalog_entry_id_tool_catalog_entries_id_fk", "tableFrom": "tool_access_audit_events", + "tableTo": "tool_catalog_entries", "columnsFrom": [ "catalog_entry_id" ], - "tableTo": "tool_catalog_entries", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -45748,63 +47009,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_action_deliveries_action_request_id_tool_action_requests_id_fk": { "name": "tool_action_deliveries_action_request_id_tool_action_requests_id_fk", "tableFrom": "tool_action_deliveries", + "tableTo": "tool_action_requests", "columnsFrom": [ "action_request_id" ], - "tableTo": "tool_action_requests", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_action_deliveries_company_id_companies_id_fk": { "name": "tool_action_deliveries_company_id_companies_id_fk", "tableFrom": "tool_action_deliveries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_action_deliveries_issue_id_issues_id_fk": { "name": "tool_action_deliveries_issue_id_issues_id_fk", "tableFrom": "tool_action_deliveries", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_action_deliveries_interaction_id_issue_thread_interactions_id_fk": { "name": "tool_action_deliveries_interaction_id_issue_thread_interactions_id_fk", "tableFrom": "tool_action_deliveries", + "tableTo": "issue_thread_interactions", "columnsFrom": [ "interaction_id" ], - "tableTo": "issue_thread_interactions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -45972,9 +47233,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_action_requests_invocation_idx": { "name": "tool_action_requests_invocation_idx", @@ -45987,9 +47248,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_action_requests_issue_idx": { "name": "tool_action_requests_issue_idx", @@ -46008,115 +47269,115 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_action_requests_company_id_companies_id_fk": { "name": "tool_action_requests_company_id_companies_id_fk", "tableFrom": "tool_action_requests", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_action_requests_invocation_id_tool_invocations_id_fk": { "name": "tool_action_requests_invocation_id_tool_invocations_id_fk", "tableFrom": "tool_action_requests", + "tableTo": "tool_invocations", "columnsFrom": [ "invocation_id" ], - "tableTo": "tool_invocations", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_action_requests_issue_id_issues_id_fk": { "name": "tool_action_requests_issue_id_issues_id_fk", "tableFrom": "tool_action_requests", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_action_requests_interaction_id_issue_thread_interactions_id_fk": { "name": "tool_action_requests_interaction_id_issue_thread_interactions_id_fk", "tableFrom": "tool_action_requests", + "tableTo": "issue_thread_interactions", "columnsFrom": [ "interaction_id" ], - "tableTo": "issue_thread_interactions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_action_requests_approval_id_approvals_id_fk": { "name": "tool_action_requests_approval_id_approvals_id_fk", "tableFrom": "tool_action_requests", + "tableTo": "approvals", "columnsFrom": [ "approval_id" ], - "tableTo": "approvals", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_action_requests_requested_by_agent_id_agents_id_fk": { "name": "tool_action_requests_requested_by_agent_id_agents_id_fk", "tableFrom": "tool_action_requests", + "tableTo": "agents", "columnsFrom": [ "requested_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_action_requests_resolved_by_agent_id_agents_id_fk": { "name": "tool_action_requests_resolved_by_agent_id_agents_id_fk", "tableFrom": "tool_action_requests", + "tableTo": "agents", "columnsFrom": [ "resolved_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_action_requests_decided_by_agent_id_agents_id_fk": { "name": "tool_action_requests_decided_by_agent_id_agents_id_fk", "tableFrom": "tool_action_requests", + "tableTo": "agents", "columnsFrom": [ "decided_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -46231,9 +47492,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_applications_company_status_idx": { "name": "tool_applications_company_status_idx", @@ -46252,9 +47513,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_applications_company_name_uq": { "name": "tool_applications_company_name_uq", @@ -46273,9 +47534,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_applications_company_key_uq": { "name": "tool_applications_company_key_uq", @@ -46294,50 +47555,50 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_applications_company_id_companies_id_fk": { "name": "tool_applications_company_id_companies_id_fk", "tableFrom": "tool_applications", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_applications_plugin_id_plugins_id_fk": { "name": "tool_applications_plugin_id_plugins_id_fk", "tableFrom": "tool_applications", + "tableTo": "plugins", "columnsFrom": [ "plugin_id" ], - "tableTo": "plugins", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_applications_owner_agent_id_agents_id_fk": { "name": "tool_applications_owner_agent_id_agents_id_fk", "tableFrom": "tool_applications", + "tableTo": "agents", "columnsFrom": [ "owner_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -46632,9 +47893,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_call_events_run_idx": { "name": "tool_call_events_run_idx", @@ -46653,9 +47914,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_call_events_issue_idx": { "name": "tool_call_events_issue_idx", @@ -46674,9 +47935,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_call_events_invocation_idx": { "name": "tool_call_events_invocation_idx", @@ -46689,9 +47950,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_call_events_gateway_idx": { "name": "tool_call_events_gateway_idx", @@ -46710,167 +47971,167 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_call_events_company_id_companies_id_fk": { "name": "tool_call_events_company_id_companies_id_fk", "tableFrom": "tool_call_events", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_call_events_agent_id_agents_id_fk": { "name": "tool_call_events_agent_id_agents_id_fk", "tableFrom": "tool_call_events", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_run_id_heartbeat_runs_id_fk": { "name": "tool_call_events_run_id_heartbeat_runs_id_fk", "tableFrom": "tool_call_events", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_issue_id_issues_id_fk": { "name": "tool_call_events_issue_id_issues_id_fk", "tableFrom": "tool_call_events", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_gateway_id_tool_mcp_gateways_id_fk": { "name": "tool_call_events_gateway_id_tool_mcp_gateways_id_fk", "tableFrom": "tool_call_events", + "tableTo": "tool_mcp_gateways", "columnsFrom": [ "gateway_id" ], - "tableTo": "tool_mcp_gateways", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_gateway_token_id_tool_mcp_gateway_tokens_id_fk": { "name": "tool_call_events_gateway_token_id_tool_mcp_gateway_tokens_id_fk", "tableFrom": "tool_call_events", + "tableTo": "tool_mcp_gateway_tokens", "columnsFrom": [ "gateway_token_id" ], - "tableTo": "tool_mcp_gateway_tokens", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_application_id_tool_applications_id_fk": { "name": "tool_call_events_application_id_tool_applications_id_fk", "tableFrom": "tool_call_events", + "tableTo": "tool_applications", "columnsFrom": [ "application_id" ], - "tableTo": "tool_applications", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_connection_id_tool_connections_id_fk": { "name": "tool_call_events_connection_id_tool_connections_id_fk", "tableFrom": "tool_call_events", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_catalog_entry_id_tool_catalog_entries_id_fk": { "name": "tool_call_events_catalog_entry_id_tool_catalog_entries_id_fk", "tableFrom": "tool_call_events", + "tableTo": "tool_catalog_entries", "columnsFrom": [ "catalog_entry_id" ], - "tableTo": "tool_catalog_entries", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_invocation_id_tool_invocations_id_fk": { "name": "tool_call_events_invocation_id_tool_invocations_id_fk", "tableFrom": "tool_call_events", + "tableTo": "tool_invocations", "columnsFrom": [ "invocation_id" ], - "tableTo": "tool_invocations", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_action_request_id_tool_action_requests_id_fk": { "name": "tool_call_events_action_request_id_tool_action_requests_id_fk", "tableFrom": "tool_call_events", + "tableTo": "tool_action_requests", "columnsFrom": [ "action_request_id" ], - "tableTo": "tool_action_requests", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_call_events_runtime_slot_id_tool_runtime_slots_id_fk": { "name": "tool_call_events_runtime_slot_id_tool_runtime_slots_id_fk", "tableFrom": "tool_call_events", + "tableTo": "tool_runtime_slots", "columnsFrom": [ "runtime_slot_id" ], - "tableTo": "tool_runtime_slots", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -47083,9 +48344,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_catalog_entries_application_idx": { "name": "tool_catalog_entries_application_idx", @@ -47098,9 +48359,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_catalog_entries_connection_idx": { "name": "tool_catalog_entries_connection_idx", @@ -47113,9 +48374,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_catalog_entries_company_status_idx": { "name": "tool_catalog_entries_company_status_idx", @@ -47134,9 +48395,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_catalog_entries_connection_name_uq": { "name": "tool_catalog_entries_connection_name_uq", @@ -47155,63 +48416,63 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_catalog_entries_company_id_companies_id_fk": { "name": "tool_catalog_entries_company_id_companies_id_fk", "tableFrom": "tool_catalog_entries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_catalog_entries_application_id_tool_applications_id_fk": { "name": "tool_catalog_entries_application_id_tool_applications_id_fk", "tableFrom": "tool_catalog_entries", + "tableTo": "tool_applications", "columnsFrom": [ "application_id" ], - "tableTo": "tool_applications", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_catalog_entries_connection_id_tool_connections_id_fk": { "name": "tool_catalog_entries_connection_id_tool_connections_id_fk", "tableFrom": "tool_catalog_entries", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_catalog_entries_reviewed_by_agent_id_agents_id_fk": { "name": "tool_catalog_entries_reviewed_by_agent_id_agents_id_fk", "tableFrom": "tool_catalog_entries", + "tableTo": "agents", "columnsFrom": [ "reviewed_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -47318,39 +48579,39 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_connection_app_snapshots_company_id_companies_id_fk": { "name": "tool_connection_app_snapshots_company_id_companies_id_fk", "tableFrom": "tool_connection_app_snapshots", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_connection_app_snapshots_company_connection_fk": { "name": "tool_connection_app_snapshots_company_connection_fk", "tableFrom": "tool_connection_app_snapshots", + "tableTo": "tool_connections", "columnsFrom": [ "company_id", "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -47471,39 +48732,39 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_connection_app_syncs_company_id_companies_id_fk": { "name": "tool_connection_app_syncs_company_id_companies_id_fk", "tableFrom": "tool_connection_app_syncs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_connection_app_syncs_company_connection_fk": { "name": "tool_connection_app_syncs_company_connection_fk", "tableFrom": "tool_connection_app_syncs", + "tableTo": "tool_connections", "columnsFrom": [ "company_id", "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -47591,9 +48852,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_connection_installs_connection_idx": { "name": "tool_connection_installs_connection_idx", @@ -47612,9 +48873,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_connection_installs_target_uq": { "name": "tool_connection_installs_target_uq", @@ -47645,50 +48906,50 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_connection_installs_company_id_companies_id_fk": { "name": "tool_connection_installs_company_id_companies_id_fk", "tableFrom": "tool_connection_installs", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_connection_installs_connection_id_tool_connections_id_fk": { "name": "tool_connection_installs_connection_id_tool_connections_id_fk", "tableFrom": "tool_connection_installs", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_connection_installs_created_by_agent_id_agents_id_fk": { "name": "tool_connection_installs_created_by_agent_id_agents_id_fk", "tableFrom": "tool_connection_installs", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -47915,9 +49176,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_connections_application_idx": { "name": "tool_connections_application_idx", @@ -47930,9 +49191,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_connections_company_enabled_idx": { "name": "tool_connections_company_enabled_idx", @@ -47951,9 +49212,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_connections_company_uid_uq": { "name": "tool_connections_company_uid_uq", @@ -47972,61 +49233,61 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_connections_company_id_companies_id_fk": { "name": "tool_connections_company_id_companies_id_fk", "tableFrom": "tool_connections", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_connections_application_id_tool_applications_id_fk": { "name": "tool_connections_application_id_tool_applications_id_fk", "tableFrom": "tool_connections", + "tableTo": "tool_applications", "columnsFrom": [ "application_id" ], - "tableTo": "tool_applications", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "tool_connections_created_by_agent_id_agents_id_fk": { "name": "tool_connections_created_by_agent_id_agents_id_fk", "tableFrom": "tool_connections", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "tool_connections_company_id_uq": { "name": "tool_connections_company_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -48147,9 +49408,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_gateway_rate_limit_counters_window_uq": { "name": "tool_gateway_rate_limit_counters_window_uq", @@ -48174,24 +49435,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_gateway_rate_limit_counters_company_id_companies_id_fk": { "name": "tool_gateway_rate_limit_counters_company_id_companies_id_fk", "tableFrom": "tool_gateway_rate_limit_counters", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -48340,9 +49601,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_gateway_sessions_company_agent_idx": { "name": "tool_gateway_sessions_company_agent_idx", @@ -48361,9 +49622,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_gateway_sessions_company_expires_idx": { "name": "tool_gateway_sessions_company_expires_idx", @@ -48382,9 +49643,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_gateway_sessions_run_idx": { "name": "tool_gateway_sessions_run_idx", @@ -48403,9 +49664,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_gateway_sessions_issue_idx": { "name": "tool_gateway_sessions_issue_idx", @@ -48424,9 +49685,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_gateway_sessions_gateway_idx": { "name": "tool_gateway_sessions_gateway_idx", @@ -48445,102 +49706,102 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_gateway_sessions_company_id_companies_id_fk": { "name": "tool_gateway_sessions_company_id_companies_id_fk", "tableFrom": "tool_gateway_sessions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_gateway_sessions_agent_id_agents_id_fk": { "name": "tool_gateway_sessions_agent_id_agents_id_fk", "tableFrom": "tool_gateway_sessions", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_gateway_sessions_run_id_heartbeat_runs_id_fk": { "name": "tool_gateway_sessions_run_id_heartbeat_runs_id_fk", "tableFrom": "tool_gateway_sessions", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_gateway_sessions_issue_id_issues_id_fk": { "name": "tool_gateway_sessions_issue_id_issues_id_fk", "tableFrom": "tool_gateway_sessions", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_gateway_sessions_project_id_projects_id_fk": { "name": "tool_gateway_sessions_project_id_projects_id_fk", "tableFrom": "tool_gateway_sessions", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_gateway_sessions_gateway_id_tool_mcp_gateways_id_fk": { "name": "tool_gateway_sessions_gateway_id_tool_mcp_gateways_id_fk", "tableFrom": "tool_gateway_sessions", + "tableTo": "tool_mcp_gateways", "columnsFrom": [ "gateway_id" ], - "tableTo": "tool_mcp_gateways", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_gateway_sessions_gateway_token_id_tool_mcp_gateway_tokens_id_fk": { "name": "tool_gateway_sessions_gateway_token_id_tool_mcp_gateway_tokens_id_fk", "tableFrom": "tool_gateway_sessions", + "tableTo": "tool_mcp_gateway_tokens", "columnsFrom": [ "gateway_token_id" ], - "tableTo": "tool_mcp_gateway_tokens", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -48855,9 +50116,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_invocations_run_idx": { "name": "tool_invocations_run_idx", @@ -48876,9 +50137,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_invocations_issue_idx": { "name": "tool_invocations_issue_idx", @@ -48897,9 +50158,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_invocations_gateway_idx": { "name": "tool_invocations_gateway_idx", @@ -48918,9 +50179,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_invocations_company_idempotency_uq": { "name": "tool_invocations_company_idempotency_uq", @@ -48939,128 +50200,128 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_invocations_company_id_companies_id_fk": { "name": "tool_invocations_company_id_companies_id_fk", "tableFrom": "tool_invocations", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_invocations_agent_id_agents_id_fk": { "name": "tool_invocations_agent_id_agents_id_fk", "tableFrom": "tool_invocations", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_invocations_issue_id_issues_id_fk": { "name": "tool_invocations_issue_id_issues_id_fk", "tableFrom": "tool_invocations", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_invocations_run_id_heartbeat_runs_id_fk": { "name": "tool_invocations_run_id_heartbeat_runs_id_fk", "tableFrom": "tool_invocations", + "tableTo": "heartbeat_runs", "columnsFrom": [ "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_invocations_gateway_id_tool_mcp_gateways_id_fk": { "name": "tool_invocations_gateway_id_tool_mcp_gateways_id_fk", "tableFrom": "tool_invocations", + "tableTo": "tool_mcp_gateways", "columnsFrom": [ "gateway_id" ], - "tableTo": "tool_mcp_gateways", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_invocations_gateway_token_id_tool_mcp_gateway_tokens_id_fk": { "name": "tool_invocations_gateway_token_id_tool_mcp_gateway_tokens_id_fk", "tableFrom": "tool_invocations", + "tableTo": "tool_mcp_gateway_tokens", "columnsFrom": [ "gateway_token_id" ], - "tableTo": "tool_mcp_gateway_tokens", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_invocations_application_id_tool_applications_id_fk": { "name": "tool_invocations_application_id_tool_applications_id_fk", "tableFrom": "tool_invocations", + "tableTo": "tool_applications", "columnsFrom": [ "application_id" ], - "tableTo": "tool_applications", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_invocations_connection_id_tool_connections_id_fk": { "name": "tool_invocations_connection_id_tool_connections_id_fk", "tableFrom": "tool_invocations", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_invocations_catalog_entry_id_tool_catalog_entries_id_fk": { "name": "tool_invocations_catalog_entry_id_tool_catalog_entries_id_fk", "tableFrom": "tool_invocations", + "tableTo": "tool_catalog_entries", "columnsFrom": [ "catalog_entry_id" ], - "tableTo": "tool_catalog_entries", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -49226,9 +50487,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_mcp_gateway_tokens_expiry_idx": { "name": "tool_mcp_gateway_tokens_expiry_idx", @@ -49247,9 +50508,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_mcp_gateway_tokens_gateway_idx": { "name": "tool_mcp_gateway_tokens_gateway_idx", @@ -49268,9 +50529,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_mcp_gateway_tokens_subject_idx": { "name": "tool_mcp_gateway_tokens_subject_idx", @@ -49295,9 +50556,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_mcp_gateway_tokens_company_expires_idx": { "name": "tool_mcp_gateway_tokens_company_expires_idx", @@ -49316,63 +50577,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_mcp_gateway_tokens_company_id_companies_id_fk": { "name": "tool_mcp_gateway_tokens_company_id_companies_id_fk", "tableFrom": "tool_mcp_gateway_tokens", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_mcp_gateway_tokens_gateway_id_tool_mcp_gateways_id_fk": { "name": "tool_mcp_gateway_tokens_gateway_id_tool_mcp_gateways_id_fk", "tableFrom": "tool_mcp_gateway_tokens", + "tableTo": "tool_mcp_gateways", "columnsFrom": [ "gateway_id" ], - "tableTo": "tool_mcp_gateways", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_mcp_gateway_tokens_expiry_override_by_agent_id_agents_id_fk": { "name": "tool_mcp_gateway_tokens_expiry_override_by_agent_id_agents_id_fk", "tableFrom": "tool_mcp_gateway_tokens", + "tableTo": "agents", "columnsFrom": [ "expiry_override_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_mcp_gateway_tokens_created_by_agent_id_agents_id_fk": { "name": "tool_mcp_gateway_tokens_created_by_agent_id_agents_id_fk", "tableFrom": "tool_mcp_gateway_tokens", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -49567,9 +50828,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_mcp_gateways_company_status_idx": { "name": "tool_mcp_gateways_company_status_idx", @@ -49588,9 +50849,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_mcp_gateways_profile_idx": { "name": "tool_mcp_gateways_profile_idx", @@ -49609,9 +50870,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_mcp_gateways_public_id_uq": { "name": "tool_mcp_gateways_public_id_uq", @@ -49624,9 +50885,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_mcp_gateways_company_slug_uq": { "name": "tool_mcp_gateways_company_slug_uq", @@ -49645,9 +50906,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_mcp_gateways_company_name_uq": { "name": "tool_mcp_gateways_company_name_uq", @@ -49666,102 +50927,102 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_mcp_gateways_company_id_companies_id_fk": { "name": "tool_mcp_gateways_company_id_companies_id_fk", "tableFrom": "tool_mcp_gateways", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_mcp_gateways_profile_id_tool_profiles_id_fk": { "name": "tool_mcp_gateways_profile_id_tool_profiles_id_fk", "tableFrom": "tool_mcp_gateways", + "tableTo": "tool_profiles", "columnsFrom": [ "profile_id" ], - "tableTo": "tool_profiles", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "restrict" + "onDelete": "restrict", + "onUpdate": "no action" }, "tool_mcp_gateways_agent_id_agents_id_fk": { "name": "tool_mcp_gateways_agent_id_agents_id_fk", "tableFrom": "tool_mcp_gateways", + "tableTo": "agents", "columnsFrom": [ "agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_mcp_gateways_project_id_projects_id_fk": { "name": "tool_mcp_gateways_project_id_projects_id_fk", "tableFrom": "tool_mcp_gateways", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_mcp_gateways_issue_id_issues_id_fk": { "name": "tool_mcp_gateways_issue_id_issues_id_fk", "tableFrom": "tool_mcp_gateways", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_mcp_gateways_approval_issue_id_issues_id_fk": { "name": "tool_mcp_gateways_approval_issue_id_issues_id_fk", "tableFrom": "tool_mcp_gateways", + "tableTo": "issues", "columnsFrom": [ "approval_issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_mcp_gateways_created_by_agent_id_agents_id_fk": { "name": "tool_mcp_gateways_created_by_agent_id_agents_id_fk", "tableFrom": "tool_mcp_gateways", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -49878,9 +51139,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_oauth_states_connection_idx": { "name": "tool_oauth_states_connection_idx", @@ -49893,9 +51154,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_oauth_states_actor_idx": { "name": "tool_oauth_states_actor_idx", @@ -49914,9 +51175,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_oauth_states_subject_agent_idx": { "name": "tool_oauth_states_subject_agent_idx", @@ -49935,9 +51196,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_oauth_states_expires_at_idx": { "name": "tool_oauth_states_expires_at_idx", @@ -49950,50 +51211,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_oauth_states_company_id_companies_id_fk": { "name": "tool_oauth_states_company_id_companies_id_fk", "tableFrom": "tool_oauth_states", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_oauth_states_connection_id_tool_connections_id_fk": { "name": "tool_oauth_states_connection_id_tool_connections_id_fk", "tableFrom": "tool_oauth_states", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_oauth_states_subject_agent_id_agents_id_fk": { "name": "tool_oauth_states_subject_agent_id_agents_id_fk", "tableFrom": "tool_oauth_states", + "tableTo": "agents", "columnsFrom": [ "subject_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -50115,9 +51376,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_policies_company_type_idx": { "name": "tool_policies_company_type_idx", @@ -50136,9 +51397,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_policies_company_name_uq": { "name": "tool_policies_company_name_uq", @@ -50157,37 +51418,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_policies_company_id_companies_id_fk": { "name": "tool_policies_company_id_companies_id_fk", "tableFrom": "tool_policies", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_policies_created_by_agent_id_agents_id_fk": { "name": "tool_policies_created_by_agent_id_agents_id_fk", "tableFrom": "tool_policies", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -50296,9 +51557,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_profile_bindings_target_profile_uq": { "name": "tool_profile_bindings_target_profile_uq", @@ -50329,50 +51590,50 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_profile_bindings_company_id_companies_id_fk": { "name": "tool_profile_bindings_company_id_companies_id_fk", "tableFrom": "tool_profile_bindings", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_profile_bindings_profile_id_tool_profiles_id_fk": { "name": "tool_profile_bindings_profile_id_tool_profiles_id_fk", "tableFrom": "tool_profile_bindings", + "tableTo": "tool_profiles", "columnsFrom": [ "profile_id" ], - "tableTo": "tool_profiles", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_profile_bindings_created_by_agent_id_agents_id_fk": { "name": "tool_profile_bindings_created_by_agent_id_agents_id_fk", "tableFrom": "tool_profile_bindings", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -50486,9 +51747,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_profile_entries_application_idx": { "name": "tool_profile_entries_application_idx", @@ -50507,9 +51768,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_profile_entries_connection_idx": { "name": "tool_profile_entries_connection_idx", @@ -50528,9 +51789,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_profile_entries_catalog_entry_idx": { "name": "tool_profile_entries_catalog_entry_idx", @@ -50549,76 +51810,76 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_profile_entries_company_id_companies_id_fk": { "name": "tool_profile_entries_company_id_companies_id_fk", "tableFrom": "tool_profile_entries", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_profile_entries_profile_id_tool_profiles_id_fk": { "name": "tool_profile_entries_profile_id_tool_profiles_id_fk", "tableFrom": "tool_profile_entries", + "tableTo": "tool_profiles", "columnsFrom": [ "profile_id" ], - "tableTo": "tool_profiles", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_profile_entries_application_id_tool_applications_id_fk": { "name": "tool_profile_entries_application_id_tool_applications_id_fk", "tableFrom": "tool_profile_entries", + "tableTo": "tool_applications", "columnsFrom": [ "application_id" ], - "tableTo": "tool_applications", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_profile_entries_connection_id_tool_connections_id_fk": { "name": "tool_profile_entries_connection_id_tool_connections_id_fk", "tableFrom": "tool_profile_entries", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_profile_entries_catalog_entry_id_tool_catalog_entries_id_fk": { "name": "tool_profile_entries_catalog_entry_id_tool_catalog_entries_id_fk", "tableFrom": "tool_profile_entries", + "tableTo": "tool_catalog_entries", "columnsFrom": [ "catalog_entry_id" ], - "tableTo": "tool_catalog_entries", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -50722,9 +51983,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_profiles_company_key_uq": { "name": "tool_profiles_company_key_uq", @@ -50743,9 +52004,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_profiles_company_name_uq": { "name": "tool_profiles_company_name_uq", @@ -50764,24 +52025,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_profiles_company_id_companies_id_fk": { "name": "tool_profiles_company_id_companies_id_fk", "tableFrom": "tool_profiles", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -50888,9 +52149,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_rate_limit_counters_window_uq": { "name": "tool_rate_limit_counters_window_uq", @@ -50927,37 +52188,37 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_rate_limit_counters_company_id_companies_id_fk": { "name": "tool_rate_limit_counters_company_id_companies_id_fk", "tableFrom": "tool_rate_limit_counters", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_rate_limit_counters_policy_id_tool_policies_id_fk": { "name": "tool_rate_limit_counters_policy_id_tool_policies_id_fk", "tableFrom": "tool_rate_limit_counters", + "tableTo": "tool_policies", "columnsFrom": [ "policy_id" ], - "tableTo": "tool_policies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -51041,9 +52302,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_runtime_metric_counters_bucket_uq": { "name": "tool_runtime_metric_counters_bucket_uq", @@ -51068,24 +52329,24 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_runtime_metric_counters_company_id_companies_id_fk": { "name": "tool_runtime_metric_counters_company_id_companies_id_fk", "tableFrom": "tool_runtime_metric_counters", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -51311,9 +52572,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_runtime_slots_connection_idx": { "name": "tool_runtime_slots_connection_idx", @@ -51326,9 +52587,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_runtime_slots_execution_workspace_idx": { "name": "tool_runtime_slots_execution_workspace_idx", @@ -51347,9 +52608,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_runtime_slots_slot_key_uq": { "name": "tool_runtime_slots_slot_key_uq", @@ -51368,89 +52629,89 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_runtime_slots_company_id_companies_id_fk": { "name": "tool_runtime_slots_company_id_companies_id_fk", "tableFrom": "tool_runtime_slots", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_runtime_slots_application_id_tool_applications_id_fk": { "name": "tool_runtime_slots_application_id_tool_applications_id_fk", "tableFrom": "tool_runtime_slots", + "tableTo": "tool_applications", "columnsFrom": [ "application_id" ], - "tableTo": "tool_applications", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_runtime_slots_connection_id_tool_connections_id_fk": { "name": "tool_runtime_slots_connection_id_tool_connections_id_fk", "tableFrom": "tool_runtime_slots", + "tableTo": "tool_connections", "columnsFrom": [ "connection_id" ], - "tableTo": "tool_connections", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_runtime_slots_project_workspace_id_project_workspaces_id_fk": { "name": "tool_runtime_slots_project_workspace_id_project_workspaces_id_fk", "tableFrom": "tool_runtime_slots", + "tableTo": "project_workspaces", "columnsFrom": [ "project_workspace_id" ], - "tableTo": "project_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_runtime_slots_execution_workspace_id_execution_workspaces_id_fk": { "name": "tool_runtime_slots_execution_workspace_id_execution_workspaces_id_fk", "tableFrom": "tool_runtime_slots", + "tableTo": "execution_workspaces", "columnsFrom": [ "execution_workspace_id" ], - "tableTo": "execution_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "tool_runtime_slots_issue_id_issues_id_fk": { "name": "tool_runtime_slots_issue_id_issues_id_fk", "tableFrom": "tool_runtime_slots", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -51573,9 +52834,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_stdio_command_templates_company_status_idx": { "name": "tool_stdio_command_templates_company_status_idx", @@ -51594,9 +52855,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "tool_stdio_command_templates_company_key_uq": { "name": "tool_stdio_command_templates_company_key_uq", @@ -51615,37 +52876,160 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "tool_stdio_command_templates_company_id_companies_id_fk": { "name": "tool_stdio_command_templates_company_id_companies_id_fk", "tableFrom": "tool_stdio_command_templates", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "tool_stdio_command_templates_created_by_agent_id_agents_id_fk": { "name": "tool_stdio_command_templates_created_by_agent_id_agents_id_fk", "tableFrom": "tool_stdio_command_templates", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_company_preferences": { + "name": "user_company_preferences", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "company_id": { + "name": "company_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "primary_agent_id": { + "name": "primary_agent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "primary_agent_initialized": { + "name": "primary_agent_initialized", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "user_company_preferences_company_user_uq": { + "name": "user_company_preferences_company_user_uq", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_company_preferences_primary_agent_idx": { + "name": "user_company_preferences_primary_agent_idx", + "columns": [ + { + "expression": "primary_agent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_company_preferences_company_id_companies_id_fk": { + "name": "user_company_preferences_company_id_companies_id_fk", + "tableFrom": "user_company_preferences", + "tableTo": "companies", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_company_preferences_primary_agent_id_agents_id_fk": { + "name": "user_company_preferences_primary_agent_id_agents_id_fk", + "tableFrom": "user_company_preferences", + "tableTo": "agents", + "columnsFrom": [ + "primary_agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -51724,9 +53108,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "user_inbox_agent_policies_allowed_agent_ids_idx": { "name": "user_inbox_agent_policies_allowed_agent_ids_idx", @@ -51739,24 +53123,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "gin", - "concurrently": false + "with": {} } }, "foreignKeys": { "user_inbox_agent_policies_company_id_companies_id_fk": { "name": "user_inbox_agent_policies_company_id_companies_id_fk", "tableFrom": "user_inbox_agent_policies", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -51871,9 +53255,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "user_secret_declarations_definition_idx": { "name": "user_secret_declarations_definition_idx", @@ -51886,9 +53270,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "user_secret_declarations_target_idx": { "name": "user_secret_declarations_target_idx", @@ -51913,9 +53297,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "user_secret_declarations_company_required_idx": { "name": "user_secret_declarations_company_required_idx", @@ -51934,9 +53318,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "user_secret_declarations_target_path_uq": { "name": "user_secret_declarations_target_path_uq", @@ -51967,9 +53351,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "user_secret_declarations_required_override_idx": { "name": "user_secret_declarations_required_override_idx", @@ -51988,38 +53372,38 @@ } ], "isUnique": false, - "with": {}, - "method": "btree", "where": "\"user_secret_declarations\".\"allow_missing_override\" = true", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "user_secret_declarations_company_id_companies_id_fk": { "name": "user_secret_declarations_company_id_companies_id_fk", "tableFrom": "user_secret_declarations", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "user_secret_declarations_user_secret_definition_id_user_secret_definitions_id_fk": { "name": "user_secret_declarations_user_secret_definition_id_user_secret_definitions_id_fk", "tableFrom": "user_secret_declarations", + "tableTo": "user_secret_definitions", "columnsFrom": [ "user_secret_definition_id" ], - "tableTo": "user_secret_definitions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -52165,9 +53549,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "user_secret_definitions_company_provider_idx": { "name": "user_secret_definitions_company_provider_idx", @@ -52186,9 +53570,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "user_secret_definitions_provider_config_idx": { "name": "user_secret_definitions_provider_config_idx", @@ -52201,9 +53585,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "user_secret_definitions_company_key_uq": { "name": "user_secret_definitions_company_key_uq", @@ -52222,64 +53606,64 @@ } ], "isUnique": true, - "with": {}, - "method": "btree", "where": "\"user_secret_definitions\".\"deleted_at\" is null", - "concurrently": false + "concurrently": false, + "method": "btree", + "with": {} } }, "foreignKeys": { "user_secret_definitions_company_id_companies_id_fk": { "name": "user_secret_definitions_company_id_companies_id_fk", "tableFrom": "user_secret_definitions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "user_secret_definitions_provider_config_id_company_secret_provider_configs_id_fk": { "name": "user_secret_definitions_provider_config_id_company_secret_provider_configs_id_fk", "tableFrom": "user_secret_definitions", + "tableTo": "company_secret_provider_configs", "columnsFrom": [ "provider_config_id" ], - "tableTo": "company_secret_provider_configs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "user_secret_definitions_created_by_agent_id_agents_id_fk": { "name": "user_secret_definitions_created_by_agent_id_agents_id_fk", "tableFrom": "user_secret_definitions", + "tableTo": "agents", "columnsFrom": [ "created_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "user_secret_definitions_updated_by_agent_id_agents_id_fk": { "name": "user_secret_definitions_updated_by_agent_id_agents_id_fk", "tableFrom": "user_secret_definitions", + "tableTo": "agents", "columnsFrom": [ "updated_by_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -52339,9 +53723,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": {}, @@ -52496,137 +53880,137 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "work_assessments_company_id_companies_id_fk": { "name": "work_assessments_company_id_companies_id_fk", "tableFrom": "work_assessments", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "work_assessments_trigger_actor_company_id_companies_id_fk": { "name": "work_assessments_trigger_actor_company_id_companies_id_fk", "tableFrom": "work_assessments", + "tableTo": "companies", "columnsFrom": [ "trigger_actor_company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "work_assessments_issue_company_fk": { "name": "work_assessments_issue_company_fk", "tableFrom": "work_assessments", + "tableTo": "issues", "columnsFrom": [ "company_id", "issue_id" ], - "tableTo": "issues", "columnsTo": [ "company_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "work_assessments_run_owner_fk": { "name": "work_assessments_run_owner_fk", "tableFrom": "work_assessments", + "tableTo": "heartbeat_runs", "columnsFrom": [ "company_id", "issue_id", "run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "company_id", "native_issue_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "work_assessments_contract_owner_fk": { "name": "work_assessments_contract_owner_fk", "tableFrom": "work_assessments", + "tableTo": "completion_contracts", "columnsFrom": [ "company_id", "issue_id", "contract_id" ], - "tableTo": "completion_contracts", "columnsTo": [ "company_id", "issue_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "work_assessments_result_owner_fk": { "name": "work_assessments_result_owner_fk", "tableFrom": "work_assessments", + "tableTo": "native_run_results", "columnsFrom": [ "company_id", "issue_id", "run_id", "result_id" ], - "tableTo": "native_run_results", "columnsTo": [ "company_id", "issue_id", "run_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "work_assessments_supersedes_owner_fk": { "name": "work_assessments_supersedes_owner_fk", "tableFrom": "work_assessments", + "tableTo": "work_assessments", "columnsFrom": [ "company_id", "issue_id", "run_id", "supersedes_assessment_id" ], - "tableTo": "work_assessments", "columnsTo": [ "company_id", "issue_id", "run_id", "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": { "work_assessments_company_issue_run_id_uq": { "name": "work_assessments_company_issue_run_id_uq", + "nullsNotDistinct": false, "columns": [ "company_id", "issue_id", "run_id", "id" - ], - "nullsNotDistinct": false + ] } }, "policies": {}, @@ -52805,9 +54189,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "workspace_operations_company_workspace_started_idx": { "name": "workspace_operations_company_workspace_started_idx", @@ -52832,9 +54216,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "workspace_operations_company_workspace_issue_started_idx": { "name": "workspace_operations_company_workspace_issue_started_idx", @@ -52865,63 +54249,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "workspace_operations_company_id_companies_id_fk": { "name": "workspace_operations_company_id_companies_id_fk", "tableFrom": "workspace_operations", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "workspace_operations_execution_workspace_id_execution_workspaces_id_fk": { "name": "workspace_operations_execution_workspace_id_execution_workspaces_id_fk", "tableFrom": "workspace_operations", + "tableTo": "execution_workspaces", "columnsFrom": [ "execution_workspace_id" ], - "tableTo": "execution_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "workspace_operations_heartbeat_run_id_heartbeat_runs_id_fk": { "name": "workspace_operations_heartbeat_run_id_heartbeat_runs_id_fk", "tableFrom": "workspace_operations", + "tableTo": "heartbeat_runs", "columnsFrom": [ "heartbeat_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "workspace_operations_issue_id_issues_id_fk": { "name": "workspace_operations_issue_id_issues_id_fk", "tableFrom": "workspace_operations", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -53144,9 +54528,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "workspace_runtime_services_company_execution_workspace_status_idx": { "name": "workspace_runtime_services_company_execution_workspace_status_idx", @@ -53171,9 +54555,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "workspace_runtime_services_company_project_status_idx": { "name": "workspace_runtime_services_company_project_status_idx", @@ -53198,9 +54582,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "workspace_runtime_services_run_idx": { "name": "workspace_runtime_services_run_idx", @@ -53213,9 +54597,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "workspace_runtime_services_company_updated_idx": { "name": "workspace_runtime_services_company_updated_idx", @@ -53234,102 +54618,102 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "workspace_runtime_services_company_id_companies_id_fk": { "name": "workspace_runtime_services_company_id_companies_id_fk", "tableFrom": "workspace_runtime_services", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "no action" + "onDelete": "no action", + "onUpdate": "no action" }, "workspace_runtime_services_project_id_projects_id_fk": { "name": "workspace_runtime_services_project_id_projects_id_fk", "tableFrom": "workspace_runtime_services", + "tableTo": "projects", "columnsFrom": [ "project_id" ], - "tableTo": "projects", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "workspace_runtime_services_project_workspace_id_project_workspaces_id_fk": { "name": "workspace_runtime_services_project_workspace_id_project_workspaces_id_fk", "tableFrom": "workspace_runtime_services", + "tableTo": "project_workspaces", "columnsFrom": [ "project_workspace_id" ], - "tableTo": "project_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "workspace_runtime_services_execution_workspace_id_execution_workspaces_id_fk": { "name": "workspace_runtime_services_execution_workspace_id_execution_workspaces_id_fk", "tableFrom": "workspace_runtime_services", + "tableTo": "execution_workspaces", "columnsFrom": [ "execution_workspace_id" ], - "tableTo": "execution_workspaces", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "workspace_runtime_services_issue_id_issues_id_fk": { "name": "workspace_runtime_services_issue_id_issues_id_fk", "tableFrom": "workspace_runtime_services", + "tableTo": "issues", "columnsFrom": [ "issue_id" ], - "tableTo": "issues", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "workspace_runtime_services_owner_agent_id_agents_id_fk": { "name": "workspace_runtime_services_owner_agent_id_agents_id_fk", "tableFrom": "workspace_runtime_services", + "tableTo": "agents", "columnsFrom": [ "owner_agent_id" ], - "tableTo": "agents", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" }, "workspace_runtime_services_started_by_run_id_heartbeat_runs_id_fk": { "name": "workspace_runtime_services_started_by_run_id_heartbeat_runs_id_fk", "tableFrom": "workspace_runtime_services", + "tableTo": "heartbeat_runs", "columnsFrom": [ "started_by_run_id" ], - "tableTo": "heartbeat_runs", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "set null" + "onDelete": "set null", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -53465,9 +54849,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_attachment_upload_expiry_idx": { "name": "mcp_attachment_upload_expiry_idx", @@ -53480,37 +54864,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_attachment_uploads_company_id_companies_id_fk": { "name": "mcp_attachment_uploads_company_id_companies_id_fk", "tableFrom": "mcp_attachment_uploads", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_attachment_uploads_user_id_user_id_fk": { "name": "mcp_attachment_uploads_user_id_user_id_fk", "tableFrom": "mcp_attachment_uploads", + "tableTo": "user", "columnsFrom": [ "user_id" ], - "tableTo": "user", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -53586,9 +54970,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_event_admissions_grant_idx": { "name": "mcp_event_admissions_grant_idx", @@ -53601,9 +54985,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_event_admissions_company_idx": { "name": "mcp_event_admissions_company_idx", @@ -53616,37 +55000,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_event_admissions_company_id_companies_id_fk": { "name": "mcp_event_admissions_company_id_companies_id_fk", "tableFrom": "mcp_event_admissions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_event_admissions_grant_id_mcp_oauth_grants_id_fk": { "name": "mcp_event_admissions_grant_id_mcp_oauth_grants_id_fk", "tableFrom": "mcp_event_admissions", + "tableTo": "mcp_oauth_grants", "columnsFrom": [ "grant_id" ], - "tableTo": "mcp_oauth_grants", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -53676,7 +55060,13 @@ "name": "activity_id", "type": "uuid", "primaryKey": false, - "notNull": true + "notNull": false + }, + "mailbox_item_id": { + "name": "mailbox_item_id", + "type": "integer", + "primaryKey": false, + "notNull": false }, "event": { "name": "event", @@ -53712,6 +55102,27 @@ } }, "indexes": { + "mcp_event_deliveries_mailbox_uq": { + "name": "mcp_event_deliveries_mailbox_uq", + "columns": [ + { + "expression": "subscription_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "mailbox_item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, "mcp_event_deliveries_activity_uq": { "name": "mcp_event_deliveries_activity_uq", "columns": [ @@ -53729,9 +55140,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_event_deliveries_due_idx": { "name": "mcp_event_deliveries_due_idx", @@ -53744,30 +55155,35 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_event_deliveries_subscription_id_mcp_event_subscriptions_id_fk": { "name": "mcp_event_deliveries_subscription_id_mcp_event_subscriptions_id_fk", "tableFrom": "mcp_event_deliveries", + "tableTo": "mcp_event_subscriptions", "columnsFrom": [ "subscription_id" ], - "tableTo": "mcp_event_subscriptions", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": {}, "policies": {}, - "checkConstraints": {}, + "checkConstraints": { + "mcp_delivery_source_check": { + "name": "mcp_delivery_source_check", + "value": "(\"mcp_event_deliveries\".\"activity_id\" IS NOT NULL AND \"mcp_event_deliveries\".\"mailbox_item_id\" IS NULL) OR (\"mcp_event_deliveries\".\"activity_id\" IS NULL AND \"mcp_event_deliveries\".\"mailbox_item_id\" IS NOT NULL)" + } + }, "isRLSEnabled": false }, "public.mcp_event_subscriptions": { @@ -53802,7 +55218,13 @@ "name": "task_id", "type": "uuid", "primaryKey": false, - "notNull": true + "notNull": false + }, + "binding_id": { + "name": "binding_id", + "type": "uuid", + "primaryKey": false, + "notNull": false }, "arguments": { "name": "arguments", @@ -53861,9 +55283,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_event_subscriptions_company_idx": { "name": "mcp_event_subscriptions_company_idx", @@ -53876,43 +55298,48 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_event_subscriptions_company_id_companies_id_fk": { "name": "mcp_event_subscriptions_company_id_companies_id_fk", "tableFrom": "mcp_event_subscriptions", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_event_subscriptions_grant_id_mcp_oauth_grants_id_fk": { "name": "mcp_event_subscriptions_grant_id_mcp_oauth_grants_id_fk", "tableFrom": "mcp_event_subscriptions", + "tableTo": "mcp_oauth_grants", "columnsFrom": [ "grant_id" ], - "tableTo": "mcp_oauth_grants", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": {}, "policies": {}, - "checkConstraints": {}, + "checkConstraints": { + "mcp_subscription_resource_check": { + "name": "mcp_subscription_resource_check", + "value": "(\"mcp_event_subscriptions\".\"task_id\" IS NOT NULL AND \"mcp_event_subscriptions\".\"binding_id\" IS NULL) OR (\"mcp_event_subscriptions\".\"task_id\" IS NULL AND \"mcp_event_subscriptions\".\"binding_id\" IS NOT NULL)" + } + }, "isRLSEnabled": false }, "public.mcp_file_tickets": { @@ -53975,9 +55402,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_file_ticket_grant_idx": { "name": "mcp_file_ticket_grant_idx", @@ -53990,50 +55417,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_file_tickets_company_id_companies_id_fk": { "name": "mcp_file_tickets_company_id_companies_id_fk", "tableFrom": "mcp_file_tickets", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_file_tickets_grant_id_mcp_oauth_grants_id_fk": { "name": "mcp_file_tickets_grant_id_mcp_oauth_grants_id_fk", "tableFrom": "mcp_file_tickets", + "tableTo": "mcp_oauth_grants", "columnsFrom": [ "grant_id" ], - "tableTo": "mcp_oauth_grants", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_file_tickets_upload_id_mcp_attachment_uploads_id_fk": { "name": "mcp_file_tickets_upload_id_mcp_attachment_uploads_id_fk", "tableFrom": "mcp_file_tickets", + "tableTo": "mcp_attachment_uploads", "columnsFrom": [ "upload_id" ], - "tableTo": "mcp_attachment_uploads", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -54140,9 +55567,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_mutation_receipts_company_idx": { "name": "mcp_mutation_receipts_company_idx", @@ -54155,50 +55582,50 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_mutation_receipts_company_id_companies_id_fk": { "name": "mcp_mutation_receipts_company_id_companies_id_fk", "tableFrom": "mcp_mutation_receipts", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_mutation_receipts_user_id_user_id_fk": { "name": "mcp_mutation_receipts_user_id_user_id_fk", "tableFrom": "mcp_mutation_receipts", + "tableTo": "user", "columnsFrom": [ "user_id" ], - "tableTo": "user", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_mutation_receipts_grant_id_mcp_oauth_grants_id_fk": { "name": "mcp_mutation_receipts_grant_id_mcp_oauth_grants_id_fk", "tableFrom": "mcp_mutation_receipts", + "tableTo": "mcp_oauth_grants", "columnsFrom": [ "grant_id" ], - "tableTo": "mcp_oauth_grants", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -54364,9 +55791,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_oauth_user_code_uq": { "name": "mcp_oauth_user_code_uq", @@ -54379,9 +55806,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_oauth_device_expiry_idx": { "name": "mcp_oauth_device_expiry_idx", @@ -54394,37 +55821,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_oauth_device_requests_client_id_mcp_oauth_clients_id_fk": { "name": "mcp_oauth_device_requests_client_id_mcp_oauth_clients_id_fk", "tableFrom": "mcp_oauth_device_requests", + "tableTo": "mcp_oauth_clients", "columnsFrom": [ "client_id" ], - "tableTo": "mcp_oauth_clients", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_oauth_device_requests_grant_id_mcp_oauth_grants_id_fk": { "name": "mcp_oauth_device_requests_grant_id_mcp_oauth_grants_id_fk", "tableFrom": "mcp_oauth_device_requests", + "tableTo": "mcp_oauth_grants", "columnsFrom": [ "grant_id" ], - "tableTo": "mcp_oauth_grants", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -54468,6 +55895,19 @@ "primaryKey": false, "notNull": true }, + "purpose": { + "name": "purpose", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'personal'" + }, + "agent_id": { + "name": "agent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, "scopes": { "name": "scopes", "type": "jsonb", @@ -54506,50 +55946,63 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_oauth_grants_company_id_companies_id_fk": { "name": "mcp_oauth_grants_company_id_companies_id_fk", "tableFrom": "mcp_oauth_grants", + "tableTo": "companies", "columnsFrom": [ "company_id" ], - "tableTo": "companies", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_oauth_grants_user_id_user_id_fk": { "name": "mcp_oauth_grants_user_id_user_id_fk", "tableFrom": "mcp_oauth_grants", + "tableTo": "user", "columnsFrom": [ "user_id" ], - "tableTo": "user", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_oauth_grants_client_id_mcp_oauth_clients_id_fk": { "name": "mcp_oauth_grants_client_id_mcp_oauth_clients_id_fk", "tableFrom": "mcp_oauth_grants", + "tableTo": "mcp_oauth_clients", "columnsFrom": [ "client_id" ], - "tableTo": "mcp_oauth_clients", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mcp_oauth_grants_agent_id_agents_id_fk": { + "name": "mcp_oauth_grants_agent_id_agents_id_fk", + "tableFrom": "mcp_oauth_grants", + "tableTo": "agents", + "columnsFrom": [ + "agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -54594,9 +56047,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": {}, @@ -54708,9 +56161,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_oauth_requests_expiry_idx": { "name": "mcp_oauth_requests_expiry_idx", @@ -54723,37 +56176,37 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_oauth_requests_client_id_mcp_oauth_clients_id_fk": { "name": "mcp_oauth_requests_client_id_mcp_oauth_clients_id_fk", "tableFrom": "mcp_oauth_requests", + "tableTo": "mcp_oauth_clients", "columnsFrom": [ "client_id" ], - "tableTo": "mcp_oauth_clients", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" }, "mcp_oauth_requests_grant_id_mcp_oauth_grants_id_fk": { "name": "mcp_oauth_requests_grant_id_mcp_oauth_grants_id_fk", "tableFrom": "mcp_oauth_requests", + "tableTo": "mcp_oauth_grants", "columnsFrom": [ "grant_id" ], - "tableTo": "mcp_oauth_grants", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -54801,7 +56254,7 @@ "name": "expires_at", "type": "timestamp with time zone", "primaryKey": false, - "notNull": true + "notNull": false }, "created_at": { "name": "created_at", @@ -54823,9 +56276,9 @@ } ], "isUnique": true, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_oauth_tokens_grant_idx": { "name": "mcp_oauth_tokens_grant_idx", @@ -54838,9 +56291,9 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} }, "mcp_oauth_tokens_expiry_idx": { "name": "mcp_oauth_tokens_expiry_idx", @@ -54853,24 +56306,24 @@ } ], "isUnique": false, - "with": {}, + "concurrently": false, "method": "btree", - "concurrently": false + "with": {} } }, "foreignKeys": { "mcp_oauth_tokens_grant_id_mcp_oauth_grants_id_fk": { "name": "mcp_oauth_tokens_grant_id_mcp_oauth_grants_id_fk", "tableFrom": "mcp_oauth_tokens", + "tableTo": "mcp_oauth_grants", "columnsFrom": [ "grant_id" ], - "tableTo": "mcp_oauth_grants", "columnsTo": [ "id" ], - "onUpdate": "no action", - "onDelete": "cascade" + "onDelete": "cascade", + "onUpdate": "no action" } }, "compositePrimaryKeys": {}, @@ -54882,21 +56335,21 @@ }, "enums": {}, "schemas": {}, - "views": {}, "sequences": { "public.chat_telegram_draft_ids": { "name": "chat_telegram_draft_ids", + "schema": "public", "increment": "1", + "startWith": "1", "minValue": "1", "maxValue": "2147483647", - "startWith": "1", "cache": "1", - "cycle": false, - "schema": "public" + "cycle": false } }, "roles": {}, "policies": {}, + "views": {}, "_meta": { "columns": {}, "schemas": {}, diff --git a/packages/db/src/migrations/meta/_journal.json b/packages/db/src/migrations/meta/_journal.json index 9d56189c1b9..ce7a0e57d4b 100644 --- a/packages/db/src/migrations/meta/_journal.json +++ b/packages/db/src/migrations/meta/_journal.json @@ -2220,6 +2220,13 @@ "when": 1791456875836, "tag": "0318_strong_blacklash", "breakpoints": true + }, + { + "idx": 319, + "version": "7", + "when": 1791490887468, + "tag": "0319_heavy_captain_midlands", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/db/src/schema/public_mcp.ts b/packages/db/src/schema/public_mcp.ts index 0725d5e0ae1..0fe918cda71 100644 --- a/packages/db/src/schema/public_mcp.ts +++ b/packages/db/src/schema/public_mcp.ts @@ -65,7 +65,8 @@ export const mcpOauthTokens = pgTable("mcp_oauth_tokens", { tokenHash: text("token_hash").notNull(), kind: text("kind").$type<"access" | "refresh">().notNull(), usedAt: timestamp("used_at", { withTimezone: true }), - expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(), + // Null only for renewable agent connection refresh tokens; access tokens expire. + expiresAt: timestamp("expires_at", { withTimezone: true }), createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(), }, (t) => [ uniqueIndex("mcp_oauth_tokens_hash_uq").on(t.tokenHash), diff --git a/packages/paperclip-runner/src/drivers/dot/runnerd-dot-driver.test.ts b/packages/paperclip-runner/src/drivers/dot/runnerd-dot-driver.test.ts index 1ac5da7d976..72bd5aa98d5 100644 --- a/packages/paperclip-runner/src/drivers/dot/runnerd-dot-driver.test.ts +++ b/packages/paperclip-runner/src/drivers/dot/runnerd-dot-driver.test.ts @@ -1,5 +1,6 @@ +import { spawn } from "node:child_process"; import { randomUUID } from "node:crypto"; -import { mkdtemp, rm, writeFile } from "node:fs/promises"; +import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { expect, it, vi } from "vitest"; @@ -125,7 +126,7 @@ it.each(["shutdown", "unexpected exit"] as const)("classifies a real Rust %s bef } }, 45000); -it("reattaches the same Rust bridge without duplicating a settled operation and refuses a lost checkpoint", async () => { +it.each(["local", "custom local directory", "external launcher"])("reattaches the %s Rust bridge without duplicate operations and refuses lost checkpoints", async launch => { const root = await mkdtemp(join(tmpdir(), "dot-driver-recovery-")); await writeFile(join(root, "AGENTS.md"), "Use only the synthetic counter."); const input = execution(root); @@ -151,6 +152,26 @@ it("reattaches the same Rust bridge without duplicating a settled operation and port: { dispatch: async event => { dispatches.push(event); }, settle: async event => { settlements.set(String(event.payload.requestId), event.payload.outcome); }, attach: async callback => { send = callback; return async () => { send = undefined; }; } }, }; + const runnerState = launch === "local" ? join(root, "state/runner") : join(root, "external-runtime/runner"); + if (launch === "custom local directory") options.runnerStateDirectory = runnerState; + if (launch === "external launcher") { + await mkdir(runnerState, { recursive: true }); + options.runnerStateDirectory = runnerState; + options.readProviderState = async () => { + try { return JSON.parse(await readFile(join(runnerState, "dot-provider-state.json"), "utf8")); } + catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") return null; throw error; } + }; + options.runnerProcessLauncher = spec => { + expect(spec.environment).not.toHaveProperty("OPENAI_API_KEY"); + expect(spec.args).toContain(runnerState); + const child = spawn(spec.command, [...spec.args], { cwd: runnerState, env: spec.environment, stdio: "ignore" }); + const startedAt = new Date().toISOString(); + spawned = { pid: child.pid!, processGroupId: null, startedAt }; + return { child, startedAt, completion: new Promise((resolve, reject) => { + child.once("error", reject); child.once("exit", (code, signal) => resolve({ code, signal, stdout: "", stderr: "" })); + }) }; + }; + } const driver = new RunnerdDotDriver(options); let session = await driver.openSession({ runId: input.binding.runId, normalizedSessionId: input.session.normalizedSessionId! }); const operation = (action: ExternalProviderOperation["action"], args: Record): ExternalProviderOperation => ({ @@ -176,7 +197,7 @@ it("reattaches the same Rust bridge without duplicating a settled operation and expect(dispatches).toHaveLength(1); await session.interrupt!({ reason: "Synthetic test complete" }); await session.close({ reason: "Synthetic test complete" }); - await rm(join(root, "state/runner/dot-provider-state.json")); + await rm(join(runnerState, "dot-provider-state.json")); expect(await recoveredDriver.recoverSession(snapshot, { signal: new AbortController().signal })).toMatchObject({ recovered: false }); } finally { await session.close({ reason: "Test cleanup", force: true }).catch(() => {}); diff --git a/packages/paperclip-runner/src/drivers/dot/runnerd-dot-driver.ts b/packages/paperclip-runner/src/drivers/dot/runnerd-dot-driver.ts index 91d0e2b2b0d..d56a15a33f4 100644 --- a/packages/paperclip-runner/src/drivers/dot/runnerd-dot-driver.ts +++ b/packages/paperclip-runner/src/drivers/dot/runnerd-dot-driver.ts @@ -19,6 +19,10 @@ export interface RunnerdDotDriverOptions { identity: DurableRecoveryIdentity; port: ExternalProviderPort; runnerBinary?: string; + runnerStateDirectory?: string; + runnerProcessLauncher?: CapabilityRunnerdCodexTransportOptions["runnerProcessLauncher"]; + /** Reads the checkpoint from the execution target. Missing state cannot authorize replay. */ + readProviderState?: () => Promise | null>; controlPlaneRegistration?: CapabilityRunnerdCodexTransportOptions["controlPlaneRegistration"]; onSpawn?: CodexNativeSessionBackendOptions["onSpawn"]; dynamicTools?: CodexNativeSessionBackendOptions["dynamicTools"]; @@ -59,10 +63,10 @@ export class RunnerdDotDriver implements HarnessDriver { || snapshot.driverSessionId !== this.options.identity.normalizedSessionId || snapshot.providerSessionId != null) { return { recovered: false, reason: "Dot bridge checkpoint identity mismatch" }; } - const path = resolve(this.options.stateDirectory, "runner/dot-provider-state.json"); - if (!existsSync(path) || statSync(path).size > 32 * 1024 * 1024) return { recovered: false, reason: "Dot bridge checkpoint missing; external work requires reconciliation" }; - let saved: Record; - try { saved = JSON.parse(readFileSync(path, "utf8")); } catch { return { recovered: false, reason: "Dot bridge checkpoint invalid; external work requires reconciliation" }; } + let saved: Record | null; + try { saved = await readProviderCheckpoint(this.options); } + catch { return { recovered: false, reason: "Dot bridge checkpoint invalid; external work requires reconciliation" }; } + if (!saved) return { recovered: false, reason: "Dot bridge checkpoint missing; external work requires reconciliation" }; if (saved.schema !== "paperclip.runner.dot-provider-state.v1" || saved.runId !== snapshot.runId || saved.sessionId !== snapshot.driverSessionId || saved.turnId !== this.options.identity.turnId) { return { recovered: false, reason: "Dot bridge checkpoint authority mismatch" }; } @@ -71,6 +75,14 @@ export class RunnerdDotDriver implements HarnessDriver { } } +async function readProviderCheckpoint(options: RunnerdDotDriverOptions): Promise | null> { + if (options.readProviderState) return options.readProviderState(); + const path = resolve(options.runnerStateDirectory ?? resolve(options.stateDirectory, "runner"), "dot-provider-state.json"); + if (!existsSync(path)) return null; + if (statSync(path).size > 32 * 1024 * 1024) throw new Error("dot_provider_checkpoint_too_large"); + return JSON.parse(readFileSync(path, "utf8")); +} + class RunnerdDotSession implements HarnessSession { #core: DurablePrpControlPlane | null = null; #process: RunnerProcessHandle | null = null; @@ -86,8 +98,8 @@ class RunnerdDotSession implements HarnessSession { async open(signal?: AbortSignal) { const o = this.options; mkdirSync(o.stateDirectory, { recursive: true, mode: 0o700 }); - const runnerState = resolve(o.stateDirectory, "runner"); - mkdirSync(runnerState, { recursive: true, mode: 0o700 }); + const runnerState = o.runnerStateDirectory ?? resolve(o.stateDirectory, "runner"); + if (!o.runnerProcessLauncher) mkdirSync(runnerState, { recursive: true, mode: 0o700 }); const binary = o.runnerBinary ?? defaultCapabilityRunnerdBinary(); const artifact = readRunnerdArtifactBinding(binary); const core = this.#core = new DurablePrpControlPlane({ @@ -125,7 +137,8 @@ class RunnerdDotSession implements HarnessSession { if (!registration) await core.start(); signal?.throwIfAborted(); if (!o.adoptExistingRunner) { - this.#process = spawnRunner({ connectUrl: registration?.connectUrl ?? core.connectUrl, + this.#process = spawnRunner({ + processLauncher: o.runnerProcessLauncher, connectUrl: registration?.connectUrl ?? core.connectUrl, connection: registration?.connection, stateDirectory: runnerState, identity: o.identity, ticket: core.issueBootstrapTicket(60_000), runnerBinaryPath: binary, runnerVersion: artifact.version, runnerDigest: artifact.digest, @@ -135,7 +148,7 @@ class RunnerdDotSession implements HarnessSession { environment: { PATH: process.env.PATH }, }); const pid = this.#process.child.pid; - if (pid) await o.onSpawn?.({ pid, processGroupId: this.#process.processGroupId ?? null, + if (pid && !o.runnerProcessLauncher) await o.onSpawn?.({ pid, processGroupId: this.#process.processGroupId ?? null, startedAt: this.#process.startedAt ?? new Date().toISOString() }); void this.#process.completion.then(result => { if (this.#closed) return; @@ -152,9 +165,16 @@ class RunnerdDotSession implements HarnessSession { } else if (!await o.adoptExistingRunner.isAlive()) { throw new Error("dot_runner_adoption_failed"); } await registration?.activate?.(); await registration?.ready?.(); + if (registration?.failure) void registration.failure.catch(error => { + if (!this.#closed) { this.#failure = error instanceof Error ? error : new Error("dot_runner_transport_failed"); this.#wake(); } + }); + const checkpoint = await readProviderCheckpoint(o); + if (checkpoint && (checkpoint.schema !== "paperclip.runner.dot-provider-state.v1" + || checkpoint.runId !== o.identity.runId || checkpoint.sessionId !== o.identity.normalizedSessionId + || checkpoint.turnId !== o.identity.turnId)) throw new Error("dot_runner_checkpoint_authority_mismatch"); this.#detachPort = await o.port.attach(async operation => { await this.#command("external_provider.operation", { ...operation }, `dot_operation_${operation.requestId}`); - }, () => this.interrupt(), existsSync(resolve(runnerState, "dot-provider-state.json"))); + }, () => this.interrupt(), !!checkpoint); await this.#command("run.prepare", { provider: { kind: "openai_dot", ...o.execution.provider.binding, instructions: `${nativeSystemInstructions(o.execution)}\n\nAccept the assignment before calling tools. Invoke paperclip_finish or paperclip_block, then submit the same structured result with paperclip_dot_finish. Keep request IDs stable across retries.` }, diff --git a/packages/shared/src/agent-appearance.test.ts b/packages/shared/src/agent-appearance.test.ts index 82edbdfbf83..95cb8b22a18 100644 --- a/packages/shared/src/agent-appearance.test.ts +++ b/packages/shared/src/agent-appearance.test.ts @@ -14,6 +14,12 @@ describe("agent appearance", () => { expect(legacyAgentAppearance("agent-1")).toEqual(legacyAgentAppearance("agent-1")); expect(agentAvatarUrl(appearance, 24, 2)).toBe("/api/agent-avatars/cap-v1/deep-tide/rest.png?size=24&scale=2"); }); + it("uses a private asset URL for custom avatars while retaining the fallback palette", () => { + const appearance = { ...appearanceForPalette("deep-tide"), customAvatarAssetId: "22222222-2222-4222-8222-222222222222" }; + expect(resolveAgentAppearance(appearance)).toEqual(appearance); + expect(agentAvatarUrl(appearance, 128, 2)).toBe("/api/assets/22222222-2222-4222-8222-222222222222/content"); + expect(agentAppearanceSchema.safeParse({ ...appearance, customAvatarAssetId: "https://example.test/image" }).success).toBe(false); + }); it("renders without a browser and preserves logical-size detail at high density", () => { const appearance = appearanceForPalette("bubblegum-sky"); // ClipLab v0.2.0 draws an enlarged compact face from 16px; only 12px and diff --git a/packages/shared/src/agent-appearance.ts b/packages/shared/src/agent-appearance.ts index 44042ef8df4..d45525d26e5 100644 --- a/packages/shared/src/agent-appearance.ts +++ b/packages/shared/src/agent-appearance.ts @@ -14,6 +14,8 @@ export const agentAppearanceSchema = z.object({ schemaVersion: z.literal(1), characterVersion: z.literal("cap-v1"), paletteId: z.enum(AGENT_PALETTE_IDS), + /** Company-scoped normalized image, set through the avatar upload service. */ + customAvatarAssetId: z.uuid().optional(), }).strict(); export type AgentAppearance = z.infer; @@ -39,6 +41,7 @@ export function resolveAgentAppearance(appearance: unknown, id = "agent"): Agent return parsed.success ? parsed.data : legacyAgentAppearance(id); } export function agentAvatarUrl(appearance: AgentAppearance, size: AgentAvatarSize = 512, scale: 1 | 2 = 1, pose: CharacterState = "rest", muted = false, background: AgentAvatarBackground = "transparent"): string { + if (appearance.customAvatarAssetId) return `/api/assets/${appearance.customAvatarAssetId}/content`; return `/api/agent-avatars/${appearance.characterVersion}/${muted ? "muted-dream" : appearance.paletteId}/${pose}.png?size=${size}&scale=${scale}${background === "paperclip-dark" ? "&background=paperclip-dark" : ""}`; } export function characterStateForAgent(status: string): CharacterState { diff --git a/packages/shared/src/agent-avatar-upload.ts b/packages/shared/src/agent-avatar-upload.ts new file mode 100644 index 00000000000..7146d88adf3 --- /dev/null +++ b/packages/shared/src/agent-avatar-upload.ts @@ -0,0 +1,10 @@ +import { z } from "zod"; + +export const MAX_AGENT_AVATAR_BYTES = 512 * 1024; +/** Raw PNG/JPEG/WebP bytes, not a URL or a data URL. Null restores the Paperclip character. */ +export const setAgentAvatarSchema = z.object({ + imageBase64: z.string().min(4).max(4 * Math.ceil(MAX_AGENT_AVATAR_BYTES / 3)) + .regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/) + .nullable(), +}).strict(); +export type SetAgentAvatarInput = z.infer; diff --git a/packages/shared/src/dot-invitations.ts b/packages/shared/src/dot-invitations.ts new file mode 100644 index 00000000000..469eb5df94c --- /dev/null +++ b/packages/shared/src/dot-invitations.ts @@ -0,0 +1,22 @@ +/** JSON responses for the operator-owned Dot invitation flow. Pairing capabilities are transient. */ +export interface DotBinding { + id: string; + status: string; + connected: boolean; + subscriptionVerified: boolean; + hasPendingChallenge: boolean; + pairingExpiresAt: string | null; + challengeExpiresAt: string | null; +} +export interface DotInvitation { + agent: { id: string; name: string; status: string }; + approvalId: string | null; + binding: DotBinding | null; +} +export interface DotConnection { + enabled: boolean; + resourceUrl: string | null; + agentStatus: string; + binding: DotBinding | null; +} +export interface DotPairing { bindingId: string; pairingCode: string; expiresAt: string } diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index cbbcc890bc6..a94a156b7fe 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -2854,3 +2854,7 @@ export * from "./connection-instructions.js"; export * from "./customer-success.js"; export * from "./decision-models.js"; export { updatePrimaryAgentSchema, type UpdatePrimaryAgent, type PrimaryAgentPreference } from "./primary-agent.js"; + +export * from "./agent-avatar-upload.js"; + +export type { DotBinding, DotInvitation, DotConnection, DotPairing } from "./dot-invitations.js"; diff --git a/server/src/__tests__/agent-profile-avatar.test.ts b/server/src/__tests__/agent-profile-avatar.test.ts new file mode 100644 index 00000000000..756cb9846e1 --- /dev/null +++ b/server/src/__tests__/agent-profile-avatar.test.ts @@ -0,0 +1,156 @@ +import { randomUUID } from "node:crypto"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import express, { type Request, type ErrorRequestHandler } from "express"; +import request from "supertest"; +import sharp from "sharp"; +import { eq } from "drizzle-orm"; +import { afterAll, beforeAll, expect, it, vi } from "vitest"; +import { createDb, agents, companies, assets, activityLog, authUsers, companyMemberships, mcpOauthClients, mcpOauthGrants, dotAgentBindings, principalPermissionGrants } from "@paperclipai/db"; +import { appearanceForPalette, MAX_AGENT_AVATAR_BYTES } from "@paperclipai/shared"; +import { startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js"; +import { createLocalDiskStorageProvider } from "../storage/local-disk-provider.js"; +import { createStorageService } from "../storage/service.js"; +import type { StorageService } from "../storage/types.js"; +import { normalizeAgentAvatar, setAgentProfileAvatar } from "../services/agent-profile-avatar.js"; +import { agentProfileAvatarRoutes } from "../routes/agent-profile-avatar.js"; +import { assetRoutes } from "../routes/assets.js"; +import { agentService } from "../services/agents.js"; +import { instanceSettingsService } from "../services/instance-settings.js"; +import { createDotRunnerMcpTools } from "../services/dot-runner-broker.js"; +import type { McpPrincipal } from "../services/public-mcp/oauth.js"; +import { isSecretSensitiveHttpRequest } from "../middleware/http-log-policy.js"; + +let storage: StorageService; +vi.mock("../storage/index.js", () => ({ getStorageService: () => storage })); +let temporary: Awaited>; +let db: ReturnType; +let root: string; +let imageBase64: string; +beforeAll(async () => { + temporary = await startEmbeddedPostgresTestDatabase("paperclip-profile-avatar-"); + db = createDb(temporary.connectionString); + root = await mkdtemp(join(tmpdir(), "profile-avatar-")); + storage = createStorageService(createLocalDiskStorageProvider(root)); + imageBase64 = (await sharp({ create: { width: 800, height: 600, channels: 3, background: "orange" } }).png().toBuffer()).toString("base64"); + await instanceSettingsService(db).updateExperimental({ enablePublicMcp: true, enableOpenAiDot: true }); +}, 120000); +afterAll(async () => { await temporary?.cleanup(); if (root) await rm(root, { recursive: true, force: true }); }); +async function fixture() { + const [company] = await db.insert(companies).values({ name: "Avatar test", issuePrefix: randomUUID().slice(0, 8) }).returning(); + const [agent] = await db.insert(agents).values({ companyId: company!.id, name: "Dot", status: "active", adapterType: "paperclip_runner", appearance: appearanceForPalette("deep-tide") }).returning(); + const actor = { actorType: "agent" as const, actorId: agent!.id, agentId: agent!.id }; + return { company: company!, agent: agent!, actor }; +} +function appFor(actor: Request["actor"]) { + const app = express(); + app.use(express.json({ limit: "2mb" })); + app.use((req, _res, next) => { req.actor = actor; next(); }); + app.use("/api", agentProfileAvatarRoutes(db, storage), assetRoutes(db, storage)); + app.use(((error, _req, res, _next) => res.status(error.status ?? 400).json({ error: error.message })) as ErrorRequestHandler); + return app; +} + +it("uploads, normalizes, serves privately, retries without duplication, and resets the avatar", async () => { + const f = await fixture(); + const app = appFor({ type: "agent", agentId: f.agent.id, companyId: f.company.id }); + const path = `/api/companies/${f.company.id}/agents/${f.agent.id}/avatar`; + const upload = await request(app).put(path).send({ imageBase64 }).expect(200); + expect(upload.body.appearance.paletteId).toBe(f.agent.appearance?.paletteId); + const retry = await request(app).put(path).send({ imageBase64 }).expect(200); + expect(retry.body).toEqual(upload.body); + expect(await db.select().from(assets).where(eq(assets.companyId, f.company.id))).toHaveLength(1); + const audit = await db.select().from(activityLog).where(eq(activityLog.companyId, f.company.id)); + expect(audit.filter(row => row.action === "agent.avatar_updated")).toHaveLength(1); + expect(JSON.stringify(audit)).not.toContain(imageBase64); + const content = await request(app).get(upload.body.avatarUrl).expect(200); + expect(content.headers["cache-control"]).toContain("private"); + expect(await sharp(content.body).metadata()).toMatchObject({ format: "png", width: 512, height: 384 }); + expect((await agentService(db).getById(f.agent.id))?.avatarUrl).toBe(upload.body.avatarUrl); + const reset = await request(app).put(path).send({ imageBase64: null }).expect(200); + expect(reset.body.appearance).toEqual(f.agent.appearance); + expect(reset.body.avatarUrl).toContain("/api/agent-avatars/"); +}); + +it("rejects other agents, companies, viewers, and foreign asset references", async () => { + const f = await fixture(); const other = await fixture(); + const path = `/api/companies/${f.company.id}/agents/${f.agent.id}/avatar`; + for (const actor of [ + { type: "agent", agentId: other.agent.id, companyId: f.company.id }, + { type: "agent", agentId: other.agent.id, companyId: other.company.id }, + { type: "board", source: "session", companyIds: [f.company.id], memberships: [{ companyId: f.company.id, status: "active", membershipRole: "viewer" }] }, + ] satisfies Request["actor"][]) await request(appFor(actor)).put(path).send({ imageBase64 }).expect(403); + await request(appFor({ type: "none" })).put(path).send({ imageBase64 }).expect(401); + const foreign = await setAgentProfileAvatar(db, storage, other.company.id, other.agent.id, { imageBase64 }, other.actor); + await expect(agentService(db).update(f.agent.id, { appearance: foreign.appearance })).rejects.toThrow("avatar upload"); + await request(appFor({ type: "agent", agentId: f.agent.id, companyId: f.company.id })).get(foreign.avatarUrl).expect(404); +}); + +it("requires an agent configuration grant for board avatar changes", async () => { + const f = await fixture(); + const userId = randomUUID(); + await db.insert(authUsers).values({ id: userId, name: "Member", email: `${userId}@example.test`, createdAt: new Date(), updatedAt: new Date() }); + await db.insert(companyMemberships).values({ companyId: f.company.id, principalType: "user", principalId: userId, membershipRole: "member", status: "active" }); + const app = appFor({ type: "board", source: "session", userId, companyIds: [f.company.id], memberships: [{ companyId: f.company.id, status: "active", membershipRole: "member" }] }); + const path = `/api/companies/${f.company.id}/agents/${f.agent.id}/avatar`; + await request(app).put(path).send({ imageBase64 }).expect(403); + await request(app).put(path).send({ imageBase64: null }).expect(403); + expect(await db.select().from(assets).where(eq(assets.companyId, f.company.id))).toHaveLength(0); + await db.insert(principalPermissionGrants).values({ companyId: f.company.id, principalType: "user", principalId: userId, permissionKey: "agents:suggest-changes" }); + await request(app).put(path).send({ imageBase64 }).expect(403); + await db.insert(principalPermissionGrants).values({ companyId: f.company.id, principalType: "user", principalId: userId, permissionKey: "agents:configure" }); + await request(app).put(path).send({ imageBase64 }).expect(200); + await request(app).put(path).send({ imageBase64: null }).expect(200); +}); + +it.each([ + { kind: "task_bridge" as const, parentIssueId: randomUUID() }, + { kind: "skill_test" as const, issueId: randomUUID() }, +])("rejects profile changes by restricted %s credentials", async keyScope => { + const f = await fixture(); + const app = appFor({ type: "agent", agentId: f.agent.id, companyId: f.company.id, keyScope }); + const path = `/api/companies/${f.company.id}/agents/${f.agent.id}/avatar`; + await request(app).put(path).send({ imageBase64 }).expect(403); + await request(app).put(path).send({ imageBase64: null }).expect(403); + expect(await db.select().from(assets).where(eq(assets.companyId, f.company.id))).toHaveLength(0); + expect(await db.select().from(activityLog).where(eq(activityLog.companyId, f.company.id))).toHaveLength(0); + expect((await agentService(db).getById(f.agent.id))?.appearance).toEqual(f.agent.appearance); +}); + +it("rejects URLs, SVG, corrupt and oversized images, unsupported fields and inactive agents", async () => { + for (const input of ["https://example.test/avatar.png", Buffer.from("").toString("base64"), Buffer.from("broken").toString("base64"), Buffer.alloc(MAX_AGENT_AVATAR_BYTES + 1).toString("base64")]) { + await expect(normalizeAgentAvatar(input)).rejects.toThrow(); + } + const tooManyPixels = await sharp({ create: { width: 5000, height: 5000, channels: 3, background: "white" } }).png().toBuffer(); + await expect(normalizeAgentAvatar(tooManyPixels.toString("base64"))).rejects.toThrow("16 megapixels"); + const f = await fixture(); + const app = appFor({ type: "agent", agentId: f.agent.id, companyId: f.company.id }); + await request(app).put(`/api/companies/${f.company.id}/agents/${f.agent.id}/avatar`).send({ imageBase64, agentId: randomUUID() }).expect(400); + await db.update(agents).set({ status: "pending_approval" }).where(eq(agents.id, f.agent.id)); + await expect(setAgentProfileAvatar(db, storage, f.company.id, f.agent.id, { imageBase64 }, f.actor)).rejects.toThrow("current state"); +}); + +it("lets a paired Dot upload without an assignment, with feature and current grant authorization", async () => { + const f = await fixture(); const userId = randomUUID(); const clientId = randomUUID(); + await db.insert(authUsers).values({ id: userId, name: "Owner", email: `${userId}@example.test`, createdAt: new Date(), updatedAt: new Date() }); + await db.insert(companyMemberships).values({ companyId: f.company.id, principalType: "user", principalId: userId, membershipRole: "owner", status: "active" }); + await db.insert(mcpOauthClients).values({ id: clientId, name: "Dot", redirectUris: [] }); + const [grant] = await db.insert(mcpOauthGrants).values({ companyId: f.company.id, userId, clientId, resource: "https://paperclip.example/mcp/runner", purpose: "agent", agentId: f.agent.id, scopes: ["paperclip:agent"] }).returning(); + await db.insert(dotAgentBindings).values({ companyId: f.company.id, agentId: f.agent.id, operatorId: userId, grantId: grant!.id, status: "connected" }); + const principal: McpPrincipal = { grant: grant!, company: f.company, actor: { type: "agent", companyId: f.company.id, agentId: f.agent.id } }; + const tools = createDotRunnerMcpTools(db); + expect((await tools.listTools(principal)).find(tool => tool.name === "paperclip_dot_set_avatar")?.annotations).toMatchObject({ readOnlyHint: false }); + expect(await tools.callTool(principal, "paperclip_dot_set_avatar", { imageBase64 })).toMatchObject({ outcome: "completed", result: { agentId: f.agent.id } }); + await expect(tools.callTool(principal, "paperclip_dot_set_avatar", { imageBase64, agentId: randomUUID() })).rejects.toThrow(); + await instanceSettingsService(db).updateExperimental({ enableOpenAiDot: false }); + try { await expect(tools.callTool(principal, "paperclip_dot_set_avatar", { imageBase64 })).rejects.toThrow("disabled"); } + finally { await instanceSettingsService(db).updateExperimental({ enableOpenAiDot: true }); } + await db.update(mcpOauthGrants).set({ revokedAt: new Date() }).where(eq(mcpOauthGrants.id, grant!.id)); + await expect(tools.callTool(principal, "paperclip_dot_set_avatar", { imageBase64 })).rejects.toThrow("authority"); +}); + +it("redacts HTTP diagnostics containing image bytes", () => { + expect(isSecretSensitiveHttpRequest("PUT", "/api/companies/company/agents/agent/avatar")).toBe(true); + expect(isSecretSensitiveHttpRequest("POST", "/mcp/runner")).toBe(true); +}); diff --git a/server/src/__tests__/chat-channels.integration.test.ts b/server/src/__tests__/chat-channels.integration.test.ts index 6df10007395..cec993f591c 100644 --- a/server/src/__tests__/chat-channels.integration.test.ts +++ b/server/src/__tests__/chat-channels.integration.test.ts @@ -4192,9 +4192,9 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => { for (const canary of [configToken, signingSecret, clientSecret, f.token]) expect(publicState).not.toContain(canary); await request(f.app).patch(`/api/chat-endpoints/${f.endpoint.id}`).send({ slackApp: appDetails }).expect(409); }); - it("uploads avatar bytes without fetching a tenant-session-protected URL, after app credentials are durable", async () => { + it.each([undefined, "22222222-2222-4222-8222-222222222222"])("uploads preset bytes after credentials are durable, even with private avatar %s", async customAvatarAssetId => { const f = await fixture(); - await db.update(agents).set({ appearance: { schemaVersion: 1, characterVersion: "cap-v1", paletteId: "cherry-pop" } }).where(eq(agents.id, f.assignedAgentId)); + await db.update(agents).set({ appearance: { schemaVersion: 1, characterVersion: "cap-v1", paletteId: "cherry-pop", customAvatarAssetId } }).where(eq(agents.id, f.assignedAgentId)); f.state.beforeIcon = async () => { const row = (await f.service.slackRegistration.registration(f.endpoint.id))!; expect(row).toMatchObject({ status: "install", appId: f.appId }); diff --git a/server/src/__tests__/cli-auth-routes.test.ts b/server/src/__tests__/cli-auth-routes.test.ts index 518adc8347e..1c4834b6dc0 100644 --- a/server/src/__tests__/cli-auth-routes.test.ts +++ b/server/src/__tests__/cli-auth-routes.test.ts @@ -91,7 +91,7 @@ async function createApp(actor: any, db: any = {} as any) { } describe("cli auth routes", () => { - beforeEach(() => { + beforeEach(async () => { vi.resetModules(); vi.doUnmock("../services/index.js"); vi.doUnmock("../routes/authz.js"); @@ -99,6 +99,9 @@ describe("cli auth routes", () => { vi.doUnmock("../middleware/index.js"); registerModuleMocks(); vi.resetAllMocks(); + // Cold route transforms are fixture setup, not HTTP request latency. + // Use the hook budget while preserving the request tests' normal timeout. + await Promise.all([import("../routes/access.js"), import("../middleware/index.js")]); }); it("creates a CLI auth challenge with approval metadata", async () => { diff --git a/server/src/__tests__/company-portability.test.ts b/server/src/__tests__/company-portability.test.ts index 74a6a08308d..461da04f268 100644 --- a/server/src/__tests__/company-portability.test.ts +++ b/server/src/__tests__/company-portability.test.ts @@ -1727,20 +1727,30 @@ describe("company portability", () => { expect(exported.warnings.filter((warning) => warning.includes("could not be exported portably"))).toHaveLength(1); }); - it("round-trips the saved visual persona through the portable bundle", async () => { + it.each([undefined, "22222222-2222-4222-8222-222222222222"])("round-trips the preset without private avatar references (%s)", async customAvatarAssetId => { const appearance = { schemaVersion: 1, characterVersion: "cap-v1", paletteId: "arctic-blue" }; const source = await agentSvc.list(); - agentSvc.list.mockResolvedValue(source.map((agent: Record) => ({ ...agent, appearance }))); + agentSvc.list.mockResolvedValue(source.map((agent: Record) => ({ ...agent, appearance: { ...appearance, ...(customAvatarAssetId ? { customAvatarAssetId } : {}) } }))); const portability = companyPortabilityService({} as any); const include = { company: true, agents: true, projects: false, issues: false, skills: false }; const exported = await portability.exportBundle("company-1", { include }); expect(asTextFile(exported.files[".paperclip.yaml"])).toContain("arctic-blue"); + const extensionText = asTextFile(exported.files[".paperclip.yaml"]); + expect(extensionText).not.toContain("customAvatarAssetId"); + if (customAvatarAssetId) { + expect(exported.warnings.some(warning => warning.includes("uploaded avatar was omitted"))).toBe(true); + // Even a hand-edited package must not carry another agent's private asset into import. + exported.files[".paperclip.yaml"] = extensionText.replace(/^(\s*)paletteId:.*$/gm, + match => `${match}\n${match.match(/^\s*/)?.[0]}customAvatarAssetId: ${customAvatarAssetId}`); + expect(asTextFile(exported.files[".paperclip.yaml"])).toContain(customAvatarAssetId); + } + agentSvc.list.mockResolvedValue([]); agentSvc.create.mockImplementation(async (_companyId: string, input: Record) => ({ ...input, id: `imported-${input.name}` })); await portability.importBundle({ source: { type: "inline", files: exported.files, rootPath: exported.rootPath }, include, target: { mode: "new_company", newCompanyName: "Imported personas" }, collisionStrategy: "rename", agents: "all" }, "user-1"); expect(agentSvc.create).toHaveBeenCalled(); - for (const [, input] of agentSvc.create.mock.calls) expect(input).toMatchObject({ appearance }); + for (const [, input] of agentSvc.create.mock.calls) expect(input.appearance).toEqual(appearance); }); it("reads env inputs back from .paperclip.yaml during preview import", async () => { diff --git a/server/src/__tests__/dot-invitations.test.ts b/server/src/__tests__/dot-invitations.test.ts new file mode 100644 index 00000000000..0a31da0f2fd --- /dev/null +++ b/server/src/__tests__/dot-invitations.test.ts @@ -0,0 +1,104 @@ +import { randomBytes, randomUUID } from "node:crypto"; +import { mkdtemp, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import express from "express"; +import request from "supertest"; +import { and, eq } from "drizzle-orm"; +import { afterAll, beforeAll, expect, it, vi } from "vitest"; +import { createDb, agents, approvals, principalPermissionGrants, authUsers, companies, companyMemberships, dotAgentBindings, activityLog } from "@paperclipai/db"; +import { startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js"; +import { dotInvitationService } from "../services/dot-invitations.js"; +import { dotRunnerBroker } from "../services/dot-runner-broker.js"; +import { dotRunnerRoutes } from "../routes/dot-runner.js"; +import { instanceSettingsService } from "../services/instance-settings.js"; +import { HttpError } from "../errors.js"; +let temporary: Awaited>; +let db: ReturnType; +let root: string; +beforeAll(async () => { + temporary = await startEmbeddedPostgresTestDatabase("dot-invitations-"); + db = createDb(temporary.connectionString); + root = await mkdtemp(join(tmpdir(), "dot-invite-home-")); + vi.stubEnv("PAPERCLIP_HOME", root); + vi.stubEnv("PAPERCLIP_IN_WORKTREE", "false"); + await instanceSettingsService(db).updateExperimental({ enableOpenAiDot: true, enablePublicMcp: true }); +}, 120000); +afterAll(async () => { await temporary?.cleanup(); if (root) await rm(root, { recursive: true, force: true }); vi.unstubAllEnvs(); }); +async function fixture(requireApproval = false) { + const userId = randomUUID(); + await db.insert(authUsers).values({ id: userId, name: "Operator", email: `${userId}@example.test`, createdAt: new Date(), updatedAt: new Date() }); + const [company] = await db.insert(companies).values({ name: "Dot invitation", issuePrefix: "DI" + randomBytes(3).toString("hex"), requireBoardApprovalForNewAgents: requireApproval }).returning(); + await db.insert(companyMemberships).values({ companyId: company!.id, principalType: "user", principalId: userId, membershipRole: "owner", status: "active" }); + await db.insert(principalPermissionGrants).values({ companyId: company!.id, principalType: "user", principalId: userId, permissionKey: "agents:create" }); + return { userId, companyId: company!.id }; +} +it("atomically resumes one pending invite across retries and never persists a pairing secret", async () => { + const f = await fixture(); + const service = dotInvitationService(db); + const [a, b] = await Promise.all([service.create(f.companyId, f.userId), service.create(f.companyId, f.userId)]); + expect(a.agent.id).toBe(b.agent.id); + expect(a.agent.status).toBe("idle"); + expect(await service.resume(f.companyId, f.userId)).toMatchObject({ agent: { id: a.agent.id } }); + expect(await service.resume(f.companyId, randomUUID())).toBeNull(); + expect(await db.select().from(agents).where(eq(agents.companyId, f.companyId))).toHaveLength(1); + const code = await dotRunnerBroker(db).createPairing({ ...f, operatorId: f.userId, agentId: a.agent.id }); + const logs = await db.select().from(activityLog).where(eq(activityLog.companyId, f.companyId)); + expect(JSON.stringify(logs)).not.toContain(code.pairingCode); + expect(JSON.stringify(await service.resume(f.companyId, f.userId))).not.toContain(code.pairingCode); +}); +it("honors hiring approval before issuing a pairing capability", async () => { + const f = await fixture(true); + const invite = await dotInvitationService(db).create(f.companyId, f.userId); + expect(invite.agent.status).toBe("pending_approval"); + expect(invite.approvalId).toBeTruthy(); + const [approval] = await db.select().from(approvals).where(eq(approvals.id, invite.approvalId!)); + expect(approval).toMatchObject({ status: "pending", type: "hire_agent", payload: { agentId: invite.agent.id } }); + await expect(dotRunnerBroker(db).createPairing({ ...f, operatorId: f.userId, agentId: invite.agent.id })).rejects.toThrow("approved"); + expect((await dotInvitationService(db).create(f.companyId, f.userId)).approvalId).toBe(invite.approvalId); +}); +it("replaces only the named pending capability and refuses to revoke a connected binding", async () => { + const f = await fixture(); const broker = dotRunnerBroker(db); + const invite = await dotInvitationService(db).create(f.companyId, f.userId); + const input = { companyId: f.companyId, agentId: invite.agent.id, operatorId: f.userId }; + const first = await broker.createPairing(input); + const second = await broker.createPairing({ ...input, replaceBindingId: first.bindingId }); + expect(second.bindingId).not.toBe(first.bindingId); + const [old] = await db.select().from(dotAgentBindings).where(eq(dotAgentBindings.id, first.bindingId)); + expect(old).toMatchObject({ status: "revoked", pairingCodeHash: null }); + await expect(broker.createPairing({ ...input, replaceBindingId: first.bindingId })).rejects.toThrow("changed"); + await db.update(dotAgentBindings).set({ status: "connected" }).where(eq(dotAgentBindings.id, second.bindingId)); + await expect(broker.createPairing({ ...input, replaceBindingId: second.bindingId })).rejects.toThrow("changed"); +}); +it("keeps invite routes company-scoped and denies viewers and agent actors", async () => { + const f = await fixture(); + const app = express(); app.use(express.json()); + app.use((req, _res, next) => { + const mode = req.headers["x-test-actor"]; + req.actor = mode === "agent" ? { type: "agent", agentId: randomUUID(), companyId: f.companyId } + : { type: "board", source: "session", userId: f.userId, companyIds: [f.companyId], + memberships: [{ companyId: f.companyId, membershipRole: mode === "viewer" ? "viewer" : "owner", status: "active" }] }; + next(); + }); + app.use(dotRunnerRoutes(db, "https://paperclip.example/mcp/runner")); + app.use((error: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => { + res.status(error instanceof HttpError ? error.status : 500).json({ error: error.message }); + }); + const path = `/companies/${f.companyId}/dot-invitations`; + for (const actor of ["viewer", "agent"]) expect((await request(app).post(path).set("x-test-actor", actor).send({})).status).toBe(403); + expect((await request(app).post(`/companies/${randomUUID()}/dot-invitations`).send({})).status).toBe(403); + const result = await request(app).post(path).send({}); + expect(result.status, JSON.stringify(result.body)).toBe(200); + expect(result.body.agent.id).toBeTruthy(); + expect((await request(app).get(path)).body.agent.id).toBe(result.body.agent.id); + expect(await db.select().from(agents).where(and(eq(agents.companyId, f.companyId), eq(agents.status, "idle")))).toHaveLength(1); +}); + +it("does not trust editable agent metadata as an invitation ownership receipt", async () => { + const f = await fixture(); + const [spoof] = await db.insert(agents).values({ companyId: f.companyId, name: "Unrelated agent", adapterType: "paperclip_runner", + adapterConfig: { provider: "openai_dot" }, metadata: { dotInvitation: { operatorId: f.userId } } }).returning(); + const service = dotInvitationService(db); + expect(await service.resume(f.companyId, f.userId)).toBeNull(); + expect((await service.create(f.companyId, f.userId)).agent.id).not.toBe(spoof!.id); +}); diff --git a/server/src/__tests__/dot-oauth-onboarding.test.ts b/server/src/__tests__/dot-oauth-onboarding.test.ts index e9ea01ccf3e..2f88ebeda2d 100644 --- a/server/src/__tests__/dot-oauth-onboarding.test.ts +++ b/server/src/__tests__/dot-oauth-onboarding.test.ts @@ -1,11 +1,12 @@ +import { readFile } from "node:fs/promises"; import { createHash, randomBytes, randomUUID } from "node:crypto"; import express from "express"; import request from "supertest"; -import { and, eq } from "drizzle-orm"; +import { and, eq, sql } from "drizzle-orm"; import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; -import { createDb, authUsers, companies, companyMemberships, agents, dotAgentBindings, mcpOauthGrants, mcpOauthRequests } from "@paperclipai/db"; +import { createDb, authUsers, companies, companyMemberships, agents, dotAgentBindings, mcpOauthGrants, mcpOauthRequests, mcpOauthTokens } from "@paperclipai/db"; import { startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js"; -import { createPublicMcpOAuth, publicMcpConfig, DEVICE_GRANT } from "../services/public-mcp/oauth.js"; +import { createPublicMcpOAuth, publicMcpConfig, hashMcpSecret, DEVICE_GRANT } from "../services/public-mcp/oauth.js"; import { instanceSettingsService } from "../services/instance-settings.js"; import { dotRunnerBroker } from "../services/dot-runner-broker.js"; import { publicMcpManagementRoutes, publicMcpIngressRoutes } from "../routes/public-mcp.js"; @@ -26,7 +27,7 @@ describe("Dot onboarding with an operator-issued pairing capability", () => { await db.insert(authUsers).values({ id: userId, name: "Operator", email: userId + "@example.test", createdAt: new Date(), updatedAt: new Date() }); const [company] = await db.insert(companies).values({ name: "Dot onboarding", issuePrefix: "DO" + randomBytes(3).toString("hex") }).returning(); await db.insert(companyMemberships).values({ companyId: company!.id, principalType: "user", principalId: userId, membershipRole: "owner", status: "active" }); - const [agent] = await db.insert(agents).values({ companyId: company!.id, name: "Dot", adapterType: "paperclip_runner", status: "active" }).returning(); + const [agent] = await db.insert(agents).values({ companyId: company!.id, name: "Dot", adapterType: "paperclip_runner", adapterConfig: { provider: "openai_dot" }, status: "active" }).returning(); const oauth = createPublicMcpOAuth(db, { ...config, ...(authorizationOrigin ? { authorizationOrigin } : {}) }); const client = await oauth.register({ client_name: "Dot", redirect_uris: [callback], grant_types: ["authorization_code", "refresh_token", DEVICE_GRANT] }, randomUUID()); const verifier = randomBytes(32).toString("base64url"); @@ -37,6 +38,72 @@ describe("Dot onboarding with an operator-issued pairing capability", () => { const id = await begin(); return { userId, company: company!, agent: agent!, oauth, client, verifier, input, pairing, id, begin }; } + async function connect(f: Awaited>) { + const consent = await f.oauth.consentDotPairing(f.id, f.pairing.pairingCode); + return f.oauth.token({ grant_type: "authorization_code", client_id: f.client.client_id, + redirect_uri: callback, resource: config.resource, code: new URL(consent.redirectUrl).searchParams.get("code"), code_verifier: f.verifier }); + } + it("refreshes a Dot connection after years of inactivity, still rotates and revokes on replay", async () => { + const f = await fixture(); + const tokens = await connect(f); + const [stored] = await db.select().from(mcpOauthTokens).where(eq(mcpOauthTokens.tokenHash, hashMcpSecret(tokens.refresh_token!))); + expect(stored!.expiresAt).toBeNull(); + const refresh = { grant_type: "refresh_token", client_id: f.client.client_id, resource: config.resource, refresh_token: tokens.refresh_token }; + vi.useFakeTimers({ toFake: ["Date"] }); + try { + vi.setSystemTime(new Date(Date.now() + 2 * 365 * 24 * 60 * 60_000)); + await expect(f.oauth.authenticate(tokens.access_token)).rejects.toThrow(); + const next = await f.oauth.token(refresh); + expect(next.refresh_token).not.toBe(tokens.refresh_token); + expect(next.expires_in).toBe(900); + expect((await f.oauth.authenticate(next.access_token)).actor).toMatchObject({ type: "agent", agentId: f.agent.id }); + const [rotated] = await db.select().from(mcpOauthTokens).where(eq(mcpOauthTokens.tokenHash, hashMcpSecret(next.refresh_token!))); + expect(rotated!.expiresAt).toBeNull(); + await expect(f.oauth.token(refresh)).rejects.toThrow(); + await expect(f.oauth.authenticate(next.access_token)).rejects.toThrow(); + expect(await dotRunnerBroker(db).bindingForAgent(f.company.id, f.agent.id)).toBeNull(); + } finally { vi.useRealTimers(); } + }); + it("upgrades valid Dot refresh tokens without reviving expired, used or revoked credentials", async () => { + const f = await fixture(); + const tokens = await connect(f); + const grant = (await f.oauth.authenticate(tokens.access_token)).grant; + const validExpiry = new Date(Date.now() + 30 * 24 * 60 * 60_000); + await db.update(mcpOauthTokens).set({ expiresAt: validExpiry }).where(eq(mcpOauthTokens.tokenHash, hashMcpSecret(tokens.refresh_token!))); + const stale = await fixture(); + const staleTokens = await connect(stale); + const expired = new Date(0); + await db.update(mcpOauthTokens).set({ expiresAt: expired }).where(eq(mcpOauthTokens.tokenHash, hashMcpSecret(staleTokens.refresh_token!))); + const personalId = randomUUID(); + const revokedId = randomUUID(); + const usedHash = randomUUID(); + await db.insert(mcpOauthGrants).values([ + { ...grant, id: personalId, purpose: "personal", agentId: null, resource: config.origin + "/mcp/paperclip" }, + { ...grant, id: revokedId, revokedAt: new Date() }, + ]); + await db.insert(mcpOauthTokens).values([ + { grantId: personalId, tokenHash: randomUUID(), kind: "refresh", expiresAt: validExpiry }, + { grantId: revokedId, tokenHash: randomUUID(), kind: "refresh", expiresAt: validExpiry }, + { grantId: grant.id, tokenHash: usedHash, kind: "refresh", expiresAt: validExpiry, usedAt: new Date() }, + ]); + const migration = await readFile(new URL("../../../packages/db/src/migrations/0319_heavy_captain_midlands.sql", import.meta.url), "utf8"); + for (let attempt = 0; attempt < 2; attempt++) { + for (const statement of migration.split("--> statement-breakpoint")) await db.execute(sql.raw(statement)); + } + const [personal] = await db.select().from(mcpOauthTokens).where(eq(mcpOauthTokens.grantId, personalId)); + const [revoked] = await db.select().from(mcpOauthTokens).where(eq(mcpOauthTokens.grantId, revokedId)); + const [used] = await db.select().from(mcpOauthTokens).where(eq(mcpOauthTokens.tokenHash, usedHash)); + const [staleToken] = await db.select().from(mcpOauthTokens).where(eq(mcpOauthTokens.tokenHash, hashMcpSecret(staleTokens.refresh_token!))); + expect(personal!.expiresAt).toEqual(validExpiry); + expect(revoked!.expiresAt).toEqual(validExpiry); + expect(used!.expiresAt).toEqual(validExpiry); + expect(staleToken!.expiresAt).toEqual(expired); + await expect(stale.oauth.token({ grant_type: "refresh_token", client_id: stale.client.client_id, resource: config.resource, refresh_token: staleTokens.refresh_token })).rejects.toThrow(); + const next = await f.oauth.token({ grant_type: "refresh_token", client_id: f.client.client_id, resource: config.resource, refresh_token: tokens.refresh_token }); + expect((await f.oauth.authenticate(next.access_token)).actor).toMatchObject({ type: "agent", agentId: f.agent.id }); + await f.oauth.revokeToken(next.access_token, f.client.client_id); + await expect(f.oauth.token({ grant_type: "refresh_token", client_id: f.client.client_id, resource: config.resource, refresh_token: next.refresh_token })).rejects.toThrow(); + }); it("pins browser ingress without changing the issuer, resource or token endpoint", async () => { const browserOrigin = "https://paperclip-browser.example:10000"; const f = await fixture(browserOrigin); @@ -75,6 +142,7 @@ describe("Dot onboarding with an operator-issued pairing capability", () => { expect((await request(app).post(path).send({ pairingCode: f.pairing.pairingCode })).status).toBe(403); const preview = await request(app).post(path + "/preview").set("Origin", config.origin).send({ pairingCode: f.pairing.pairingCode }); expect(preview.status).toBe(200); + expect(preview.body.accessDuration).toBe("Ongoing until revoked. This connection does not expire from inactivity."); expect(preview.body).toMatchObject({ company: { id: f.company.id, name: f.company.name }, agent: { id: f.agent.id, name: f.agent.name } }); expect(JSON.stringify(preview.body)).not.toContain(f.pairing.pairingCode); expect(await db.select().from(mcpOauthGrants).where(eq(mcpOauthGrants.userId, f.userId))).toHaveLength(0); diff --git a/server/src/__tests__/dot-runner.test.ts b/server/src/__tests__/dot-runner.test.ts index bd105ab7848..c6b586db09b 100644 --- a/server/src/__tests__/dot-runner.test.ts +++ b/server/src/__tests__/dot-runner.test.ts @@ -10,7 +10,7 @@ import express, { type Request } from "express"; import request from "supertest"; import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; import { agents, authUsers, companies, companyMemberships, createDb, dotAgentBindings, dotMailboxItems, dotRunnerAssignments, dotRunnerOperations, - heartbeatRuns, agentWakeupRequests, issueComments, issues, nativeRunResults, nativeRunFinalizations, completionContracts, mcpEventDeliveries, workspaceOperations, workAssessments, statusDecisions, issueThreadInteractions } from "@paperclipai/db"; + heartbeatRuns, agentWakeupRequests, issueComments, issues, nativeRunResults, nativeRunFinalizations, completionContracts, mcpEventDeliveries, mcpEventSubscriptions, workspaceOperations, workAssessments, statusDecisions, issueThreadInteractions } from "@paperclipai/db"; import { startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js"; import { createPublicMcpOAuth, DEVICE_GRANT } from "../services/public-mcp/oauth.js"; import { createPublicMcpExecutor } from "../services/public-mcp/capabilities.js"; @@ -125,7 +125,7 @@ describe("durable Dot Runner integration", () => { const events = createPublicMcpEvents(db, oauth, async () => { throw new Error("personal API dispatch forbidden"); }, { enableDotRunner: true, fetch: fetcher }); const subscription = { name: "paperclip.dot.mailbox_updated", arguments: { companyId: company!.id, bindingId: pairing.bindingId }, delivery: { mode: "webhook", url: "https://example.com/dot-hook", secret } }; await events.subscribe(principal, subscription); - await broker.challenge(company!.id, agent!.id); await events.tick(); + await events.tick(); if (!received.length) throw new Error("Dot readiness delivery missing: " + JSON.stringify(await db.select({ outcome: mcpEventDeliveries.outcome, event: mcpEventDeliveries.event }).from(mcpEventDeliveries))); expect(received.at(-1)?.data.kind).toBe("readiness_challenge"); expect(received.at(-1)?.data).not.toHaveProperty("challenge"); @@ -168,6 +168,25 @@ describe("durable Dot Runner integration", () => { } }); + it.each(["revoked binding", "removed subscription"])("handles an automatic event-test race with a %s", async change => { + const f = await fixture(); + await db.update(dotAgentBindings).set({ readyAt: null, status: "connected" }).where(eq(dotAgentBindings.id, f.snapshot.bindingId)); + const readBinding = f.broker.bindingForAgent.bind(f.broker); + const read = vi.spyOn(f.broker, "bindingForAgent").mockImplementationOnce(async (companyId, agentId) => { + const state = await readBinding(companyId, agentId); + if (change === "revoked binding") await db.update(dotAgentBindings).set({ revokedAt: new Date() }).where(eq(dotAgentBindings.id, f.snapshot.bindingId)); + else await db.update(mcpEventSubscriptions).set({ stoppedAt: new Date() }).where(eq(mcpEventSubscriptions.bindingId, f.snapshot.bindingId)); + return state; + }); + try { + await expect(f.broker.challenge(f.company.id, f.agent.id, { automatic: true, bindingId: f.snapshot.bindingId })).resolves.toEqual({ status: "unavailable" }); + await expect(f.broker.challenge(f.company.id, f.agent.id)).rejects.toThrow("Connect and subscribe"); + } finally { + read.mockRestore(); + await f.events.unsubscribe(f.principal, f.subscription); await f.events.stop(); + } + }); + it("admits one durable idle intake without requiring a preassigned task", async () => { const f = await fixture(); await db.update(companies).set({ defaultResponsibleUserId: f.userId }).where(eq(companies.id, f.company.id)); diff --git a/server/src/__tests__/heartbeat-process-recovery.test.ts b/server/src/__tests__/heartbeat-process-recovery.test.ts index ec4214283a5..f02983143ee 100644 --- a/server/src/__tests__/heartbeat-process-recovery.test.ts +++ b/server/src/__tests__/heartbeat-process-recovery.test.ts @@ -7980,7 +7980,8 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => { }); expect(next?.contextSnapshot?.wakeCommentIds).toEqual([pending!.id, go!.id]); expect((await db.select().from(agentWakeupRequests).where(eq(agentWakeupRequests.id, deferred!.id)))[0]).toMatchObject({ status: "coalesced", runId: next!.id }); - await vi.waitFor(async () => expect((await heartbeat.getRun(next!.id))?.status).not.toBe("running")); + await heartbeat.drainActiveRunExecutions(); + expect((await heartbeat.getRun(next!.id))?.status).not.toBe("running"); }); it.each(["dedicated deferred donor", "non-coalescing recipient", "persistent agent conversation"] as const)( diff --git a/server/src/__tests__/openapi-routes.test.ts b/server/src/__tests__/openapi-routes.test.ts index 30ab5acbb60..cd8cdded1bb 100644 --- a/server/src/__tests__/openapi-routes.test.ts +++ b/server/src/__tests__/openapi-routes.test.ts @@ -21,6 +21,7 @@ const apiPrefixes: Record = { "agents.ts": "/api", "agent-commentary.ts": "/api", "agent-avatars.ts": "/api", + "agent-profile-avatar.ts": "/api", "announcements.ts": "/api", "ai-connections.ts": "/api", "decision-models.ts": "/api", @@ -229,10 +230,13 @@ function loadActualRoutes() { } } if (file === "dot-runner.ts") { - const basePath = /const path = "([^"]+)"/.exec(source)?.[1]; - if (!basePath) throw new Error("Dot binding route prefix is missing"); - for (const match of source.matchAll(/router\.(get|post|delete)\(path(?: \+ "([^"]+)")?/g)) { - routes.add(`${match[1].toUpperCase()} ${normalizeExpressPath(prefix + basePath + (match[2] ?? ""))}`); + for (const name of ["path", "invitePath"]) { + const basePath = new RegExp(`const ${name} = "([^"]+)"`).exec(source)?.[1]; + if (!basePath) throw new Error(`Dot ${name} route prefix is missing`); + const methods = new RegExp(`router\\.(get|post|delete)\\(${name}(?: \\+ "([^"]+)")?`, "g"); + for (const match of source.matchAll(methods)) { + routes.add(`${match[1].toUpperCase()} ${normalizeExpressPath(prefix + basePath + (match[2] ?? ""))}`); + } } } @@ -858,6 +862,19 @@ describe("openapi routes", () => { expect(path.put.responses["422"]).toBeDefined(); }); + it("documents operator Dot invitations and current pairing and event-test fields", () => { + const { spec } = loadSpecRoutes(); + const invitations = spec.paths["/api/companies/{companyId}/dot-invitations"]; + for (const operation of [invitations.get, invitations.post]) { + expect(operation["x-paperclip-authorization"]).toEqual({ actor: "board" }); + expect(operation.responses["200"]).toBeDefined(); + } + expect(invitations.post.requestBody.content["application/json"].schema.additionalProperties).toBe(false); + const base = "/api/companies/{companyId}/agents/{agentId}/dot-binding"; + expect(spec.paths[base].post.requestBody.content["application/json"].schema.properties.replaceBindingId).toMatchObject({ type: "string", format: "uuid" }); + expect(spec.paths[base + "/event-test"].post.requestBody.content["application/json"].schema.properties.bindingId).toMatchObject({ type: "string", format: "uuid" }); + }); + it("documents board-only repository discovery and selection", () => { const { spec } = loadSpecRoutes(); const discovery = spec.paths["/api/companies/{companyId}/project-repositories"].get; diff --git a/server/src/__tests__/public-mcp.test.ts b/server/src/__tests__/public-mcp.test.ts index 79debc06f17..5c8ff3d79d0 100644 --- a/server/src/__tests__/public-mcp.test.ts +++ b/server/src/__tests__/public-mcp.test.ts @@ -479,6 +479,15 @@ describe.skipIf(!support.supported)("public MCP OAuth and tool boundary", () => await expect(oauth.authenticate(next.access_token)).rejects.toThrow(); }); + it.each([new Date(0), null])("rejects personal refresh tokens with invalid expiry %s", async expiresAt => { + const f = await fixture(); + const [stored] = await db.select().from(mcpOauthTokens).where(eq(mcpOauthTokens.tokenHash, hashMcpSecret(f.tokens.refresh_token!))); + expect(stored!.expiresAt!.getTime() - Date.now()).toBeGreaterThan(29 * 24 * 60 * 60_000); + await db.update(mcpOauthTokens).set({ expiresAt }).where(eq(mcpOauthTokens.id, stored!.id)); + await expect(oauth.token({ grant_type: "refresh_token", client_id: f.client.client_id, + resource: config.resource, refresh_token: f.tokens.refresh_token })).rejects.toThrow(); + }); + it("rejects token expiry, revocation and membership loss on the next call", async () => { const f = await fixture(); await db.update(mcpOauthTokens).set({ expiresAt: new Date(0) }).where(eq(mcpOauthTokens.tokenHash, hashMcpSecret(f.tokens.access_token))); diff --git a/server/src/app.ts b/server/src/app.ts index 7cdebae7f1d..db931861787 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -8,6 +8,7 @@ import { browserUseService } from "./services/browser-use.js"; import { slackToolRoutes } from "./routes/slack-tools.js"; import { createPublicMcpOAuth, publicMcpConfig } from "./services/public-mcp/oauth.js"; import { createDotRunnerMcpTools } from "./services/dot-runner-broker.js"; +import { agentProfileAvatarRoutes } from "./routes/agent-profile-avatar.js"; import { dotRunnerRoutes } from "./routes/dot-runner.js"; import { createPublicMcpTransfers } from "./services/public-mcp/file-transfers.js"; import { createMcpApiDispatch, createPublicMcpExecutor } from "./services/public-mcp/capabilities.js"; @@ -781,6 +782,7 @@ export async function createApp( }), ); api.use(assetRoutes(db, opts.storageService)); + api.use(agentProfileAvatarRoutes(db, opts.storageService)); api.use(projectToolRoutes(db)); api.use(projectRoutes(db)); api.use(caseRoutes(db, opts.storageService)); diff --git a/server/src/middleware/http-log-policy.ts b/server/src/middleware/http-log-policy.ts index 451121b6132..7b2c4bd7ba3 100644 --- a/server/src/middleware/http-log-policy.ts +++ b/server/src/middleware/http-log-policy.ts @@ -89,6 +89,8 @@ export function isSecretSensitiveHttpRequest( if (isPrivateWebhookHttpRequest(method, url)) return true; if (url && normalizePath(url).startsWith("/mcp/files/")) return true; if (isPrivateAgentCommentaryHttpRequest(url)) return true; + // Avatar uploads and dedicated Dot MCP calls may contain private image bytes. + if (url && /^(?:\/mcp\/runner(?:\/|$)|\/api\/companies\/[^/]+\/agents\/[^/]+\/avatar(?:\/|$))/i.test(normalizePath(url).replace(/^https?:\/\/[^/]*/i, ""))) return true; if (!method || !url) return false; if (/^\/api\/chat-slack\/oauth(?:\/|$)/i.test(normalizePath(url).replace(/^https?:\/\/[^/]*/i, ""))) return true; if (/^\/api\/chat-endpoints\/[^/]+\/slack(?:\/|$)/i.test(normalizePath(url).replace(/^https?:\/\/[^/]*/i, ""))) return true; diff --git a/server/src/routes/agent-profile-avatar.ts b/server/src/routes/agent-profile-avatar.ts new file mode 100644 index 00000000000..cb984836360 --- /dev/null +++ b/server/src/routes/agent-profile-avatar.ts @@ -0,0 +1,36 @@ +import { Router } from "express"; +import type { Db } from "@paperclipai/db"; +import { setAgentAvatarSchema } from "@paperclipai/shared"; +import { z } from "zod"; +import type { StorageService } from "../storage/types.js"; +import { forbidden } from "../errors.js"; +import { assertCompanyAccess, getActorInfo } from "./authz.js"; +import { accessService } from "../services/access.js"; +import { setAgentProfileAvatar } from "../services/agent-profile-avatar.js"; + +export function agentProfileAvatarRoutes(db: Db, storage: StorageService) { + const router = Router(); + router.put("/companies/:companyId/agents/:agentId/avatar", async (req, res) => { + const companyId = z.uuid().parse(req.params.companyId); + const agentId = z.uuid().parse(req.params.agentId); + assertCompanyAccess(req, companyId); + if (req.actor.type === "agent") { + if (req.actor.keyScope?.kind === "task_bridge" || req.actor.keyScope?.kind === "skill_test") { + throw forbidden("Task-scoped credentials cannot update agent profiles"); + } + if (req.actor.agentId !== agentId) throw forbidden("Agents can update only their own avatar"); + } else if (req.actor.type !== "board" || req.actor.memberships?.find(m => m.companyId === companyId)?.membershipRole === "viewer") { + throw forbidden("Operator or agent access required"); + } + if (req.actor.type === "board") { + const decision = await accessService(db).decide({ + actor: req.actor, action: "agent_config:update", + resource: { type: "agent", companyId, agentId }, + }); + if (!decision.allowed) throw forbidden(decision.explanation); + } + const actor = getActorInfo(req); + res.json(await setAgentProfileAvatar(db, storage, companyId, agentId, setAgentAvatarSchema.parse(req.body), actor)); + }); + return router; +} diff --git a/server/src/routes/dot-runner.ts b/server/src/routes/dot-runner.ts index 11b8c8a1fd2..928806548c1 100644 --- a/server/src/routes/dot-runner.ts +++ b/server/src/routes/dot-runner.ts @@ -4,34 +4,61 @@ import type { Db } from "@paperclipai/db"; import { assertBoard, assertCompanyAccess } from "./authz.js"; import { forbidden, HttpError } from "../errors.js"; import { publicMcpConfig, McpOAuthError } from "../services/public-mcp/oauth.js"; +import { dotInvitationService } from "../services/dot-invitations.js"; +import { agentService } from "../services/agents.js"; +import { notFound } from "../errors.js"; +import { accessService } from "../services/access.js"; import { dotRunnerBroker } from "../services/dot-runner-broker.js"; export function dotRunnerRoutes(db: Db, resourceUrl?: string) { const router = Router(); const broker = dotRunnerBroker(db); const path = "/companies/:companyId/agents/:agentId/dot-binding"; - function scope(req: Request, write = false) { + function companyScope(req: Request, write = false) { const companyId = z.uuid().parse(req.params.companyId); - const agentId = z.uuid().parse(req.params.agentId); assertBoard(req); assertCompanyAccess(req, companyId); if (write && (!req.actor.userId || !["session", "cloud_tenant"].includes(req.actor.source ?? "") || req.actor.memberships?.find(m => m.companyId === companyId)?.membershipRole === "viewer")) { throw forbidden("Sign in as an operator to connect a Dot agent."); } - return { companyId, agentId, operatorId: req.actor.userId! }; + return { companyId, operatorId: req.actor.userId! }; } + function scope(req: Request, write = false) { + return { ...companyScope(req, write), agentId: z.uuid().parse(req.params.agentId) }; + } + const invitations = dotInvitationService(db); + const invitePath = "/companies/:companyId/dot-invitations"; + async function inviteScope(req: Request) { + const input = companyScope(req, true); + const decision = await accessService(db).decide({ actor: req.actor, action: "agents:create", resource: { type: "company", companyId: input.companyId } }); + if (!decision.allowed) throw forbidden(decision.explanation); + return input; + } + router.get(invitePath, async (req, res) => { + const { companyId, operatorId } = await inviteScope(req); + res.set("Cache-Control", "no-store").json(await invitations.resume(companyId, operatorId)); + }); + router.post(invitePath, async (req, res) => { + const { companyId, operatorId } = await inviteScope(req); + z.object({}).strict().parse(req.body ?? {}); + res.set("Cache-Control", "no-store").json(await invitations.create(companyId, operatorId)); + }); router.get(path, async (req, res) => { const input = scope(req); + const agent = await agentService(db).getById(input.agentId); + if (!agent || agent.companyId !== input.companyId) throw notFound("Agent not found"); const config = resourceUrl ? null : publicMcpConfig(process.env); - res.json({ enabled: await broker.enabled(), resourceUrl: resourceUrl ?? (config ? config.origin + "/mcp/runner" : null), binding: await broker.bindingForAgent(input.companyId, input.agentId) }); + res.json({ agentStatus: agent.status, enabled: await broker.enabled(), resourceUrl: resourceUrl ?? (config ? config.origin + "/mcp/runner" : null), binding: await broker.bindingForAgent(input.companyId, input.agentId) }); }); router.post(path, async (req, res) => { const input = scope(req, true); - const body = z.object({ dotUrl: z.string().max(2048).optional() }).strict().parse(req.body ?? {}); - res.status(201).json(await broker.createPairing({ ...input, ...body })); + const body = z.object({ dotUrl: z.string().max(2048).optional(), replaceBindingId: z.uuid().optional() }).strict().parse(req.body ?? {}); + res.set("Cache-Control", "no-store").status(201).json(await broker.createPairing({ ...input, ...body })); }); router.post(path + "/event-test", async (req, res) => { - const input = scope(req, true); res.json(await broker.challenge(input.companyId, input.agentId)); + const input = scope(req, true); + const body = z.object({ bindingId: z.uuid().optional() }).strict().parse(req.body ?? {}); + res.json(await broker.challenge(input.companyId, input.agentId, { bindingId: body.bindingId })); }); router.delete(path, async (req, res) => { const input = scope(req, true); await broker.revoke(input.companyId, input.agentId, input.operatorId); res.status(204).end(); diff --git a/server/src/routes/openapi.ts b/server/src/routes/openapi.ts index 81b0b5e2c4a..915e28ce507 100644 --- a/server/src/routes/openapi.ts +++ b/server/src/routes/openapi.ts @@ -30,6 +30,7 @@ import { AGENT_AVATAR_SIZES, CHARACTER_STATES, agentAppearanceSchema, + setAgentAvatarSchema, createAgentSchema, createAgentHireSchema, updateAgentSchema, @@ -1714,6 +1715,7 @@ function resolveOperationAuthLevel( || key === "POST /api/mcp/requests/{id}/dot-pairing/preview") return "public"; if (path === "/api/mcp/setup" || path === "/api/mcp/device/consent" || path.startsWith("/api/mcp/requests/") || path.startsWith("/api/mcp/connections")) return "board"; if (/^\/api\/companies\/\{companyId\}\/agents\/\{agentId\}\/dot-binding(?:\/event-test)?$/.test(path)) return "board"; + if (path === "/api/companies/{companyId}/dot-invitations") return "board"; if (PUBLIC_OPERATIONS.has(key)) return "public"; if (key === "POST /api/companies/{companyId}/agent-commentary") return "agent_heartbeat"; if (key === "POST /api/mcp/project-tools" || key === "POST /api/companies/{companyId}/slack/tasks/{issueId}/tools") return "agent_run"; @@ -2978,6 +2980,26 @@ for (const route of [ // ─── Agents ────────────────────────────────────────────────────────────────── registry.register("AgentAppearance", agentAppearanceSchema); +registry.registerPath({ + method: "put", + path: "/api/companies/{companyId}/agents/{agentId}/avatar", + tags: ["agents"], + summary: "Upload or reset an agent profile avatar", + description: "Board users require agent_config:update permission to change company agent avatars. Agents can update only their own avatar. Task bridge and skill test credentials cannot change profiles. Upload a base64 raster image, or null to restore the preset portrait. Stored avatars use company-scoped private assets.", + request: { + params: z.object({ companyId: z.string().uuid(), agentId: z.string().uuid() }), + body: jsonBody(setAgentAvatarSchema), + }, + responses: { + 200: r.ok(z.object({ agentId: z.string().uuid(), appearance: agentAppearanceSchema, avatarUrl: z.string() })), + 400: r.badRequest, + 401: r.unauthorized, + 403: r.forbidden, + 404: r.notFound, + 409: r.conflict, + }, +}); + registry.registerPath({ method: "get", path: "/api/agent-avatars/{version}/{palette}/{file}", @@ -11733,6 +11755,27 @@ registerCurrentRoute({ }, }); +const dotInvitationResponseSchema = z.object({ + agent: z.object({ id: z.string().uuid(), name: z.string(), status: z.string() }), + approvalId: z.string().uuid().nullable(), + binding: z.object({ + id: z.string().uuid(), status: z.string(), connected: z.boolean(), + subscriptionVerified: z.boolean(), hasPendingChallenge: z.boolean(), + pairingExpiresAt: z.string().datetime().nullable(), challengeExpiresAt: z.string().datetime().nullable(), + }).nullable(), +}); +registerCurrentRoute({ + method: "get", path: "/api/companies/{companyId}/dot-invitations", tags: ["agents"], + summary: "Resume the signed-in operator's unfinished Dot invitation", + responses: { 200: r.ok(dotInvitationResponseSchema.nullable()), 400: r.badRequest, 401: r.unauthorized, 403: r.forbidden }, +}); +registerCurrentRoute({ + method: "post", path: "/api/companies/{companyId}/dot-invitations", tags: ["agents"], + summary: "Create or resume a Dot invitation with company hire approval gates", + body: z.object({}).strict(), + responses: { 200: r.ok(dotInvitationResponseSchema), 400: r.badRequest, 401: r.unauthorized, 403: r.forbidden, 409: r.conflict }, +}); + registerCurrentRoute({ method: "get", path: "/api/companies/{companyId}/agents/{agentId}/dot-binding", tags: ["agents"], summary: "Read the experimental Dot agent connection and event readiness", @@ -11741,13 +11784,14 @@ registerCurrentRoute({ registerCurrentRoute({ method: "post", path: "/api/companies/{companyId}/agents/{agentId}/dot-binding", tags: ["agents"], summary: "Create a one-use Dot pairing code as a company operator", - body: z.object({ dotUrl: z.string().max(2048).optional() }).strict(), + body: z.object({ dotUrl: z.string().max(2048).optional(), replaceBindingId: z.string().uuid().optional() }).strict(), responses: { 201: r.ok(z.object({ bindingId: z.string().uuid(), pairingCode: z.string(), expiresAt: z.string().datetime(), instructions: z.string() })), 400: r.badRequest, 401: r.unauthorized, 403: r.forbidden, 404: r.notFound, 409: r.conflict }, }); registerCurrentRoute({ method: "post", path: "/api/companies/{companyId}/agents/{agentId}/dot-binding/event-test", tags: ["agents"], summary: "Request a harmless Dot readiness challenge as a company operator", + body: z.object({ bindingId: z.string().uuid().optional() }).strict(), responses: { 200: r.ok(), 400: r.badRequest, 401: r.unauthorized, 403: r.forbidden, 404: r.notFound, 409: r.conflict }, }); registerCurrentRoute({ diff --git a/server/src/services/agent-profile-avatar.ts b/server/src/services/agent-profile-avatar.ts new file mode 100644 index 00000000000..64d0b7d3d9c --- /dev/null +++ b/server/src/services/agent-profile-avatar.ts @@ -0,0 +1,76 @@ +import { createHash } from "node:crypto"; +import { and, eq } from "drizzle-orm"; +import sharp from "sharp"; +import { agents, assets, companies, type Db } from "@paperclipai/db"; +import { MAX_AGENT_AVATAR_BYTES, resolveAgentAppearance, agentAvatarUrl, setAgentAvatarSchema, type SetAgentAvatarInput } from "@paperclipai/shared"; +import { conflict, notFound, unprocessable } from "../errors.js"; +import type { StorageService } from "../storage/types.js"; +import { agentService } from "./agents.js"; +import { logActivity, publishActivity, type ActivityPublication, type LogActivityInput } from "./activity-log.js"; + +/** Decode and re-encode: exclude SVG, animation, metadata and unbounded pixel counts. No URL fetching. */ +export async function normalizeAgentAvatar(input: string) { + const bytes = Buffer.from(input, "base64"); + if (!bytes.length || bytes.length > MAX_AGENT_AVATAR_BYTES || bytes.toString("base64") !== input) { + throw unprocessable("Avatar must contain at most 512 KiB of base64-encoded image bytes"); + } + const rasterSignature = bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) + || (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) + || (bytes.toString("ascii", 0, 4) === "RIFF" && bytes.toString("ascii", 8, 12) === "WEBP"); + if (!rasterSignature) throw unprocessable("Use a PNG, JPEG, or WebP image"); + try { + const image = sharp(bytes, { limitInputPixels: 16_777_216, failOn: "warning" }); + const metadata = await image.metadata(); + if (!["png", "jpeg", "webp"].includes(metadata.format ?? "") || (metadata.pages ?? 1) !== 1) throw new Error("Unsupported image"); + return await image.rotate().resize(512, 512, { fit: "inside", withoutEnlargement: true }).png().toBuffer(); + } catch { + throw unprocessable("Use a valid static PNG, JPEG, or WebP image with at most 16 megapixels"); + } +} + +type AvatarActor = Pick; +export async function setAgentProfileAvatar(db: Db, storage: StorageService, companyId: string, agentId: string, input: SetAgentAvatarInput, actor: AvatarActor) { + const parsed = setAgentAvatarSchema.parse(input); + // Authorization belongs to the REST/MCP boundary. Validate scope and eligibility before decoding. + const [target] = await db.select().from(agents).where(and(eq(agents.id, agentId), eq(agents.companyId, companyId))); + if (!target) throw notFound("Agent not found"); + if (["terminated", "pending_approval"].includes(target.status)) throw conflict("Agent avatar cannot be updated in its current state"); + const png = parsed.imageBase64 === null ? null : await normalizeAgentAvatar(parsed.imageBase64); + const digest = png ? createHash("sha256").update(png).digest("hex") : null; + let newObjectKey: string | undefined; + const publications: ActivityPublication[] = []; + try { + const result = await db.transaction(async tx => { + const txDb = tx as unknown as Db; + const [agent] = await tx.select().from(agents).where(and(eq(agents.id, agentId), eq(agents.companyId, companyId))).for("update"); + const [company] = await tx.select().from(companies).where(eq(companies.id, companyId)); + if (!agent || company?.status !== "active" || ["terminated", "pending_approval"].includes(agent.status)) throw conflict("Agent avatar cannot be updated in its current state"); + const appearance = resolveAgentAppearance(agent.appearance, agent.id); + const current = appearance.customAvatarAssetId + ? (await tx.select().from(assets).where(and(eq(assets.id, appearance.customAvatarAssetId), eq(assets.companyId, companyId))))[0] + : null; + if ((png && current?.sha256 === digest) || (!png && !appearance.customAvatarAssetId)) { + return { agentId, appearance, avatarUrl: agentAvatarUrl(appearance) }; + } + delete appearance.customAvatarAssetId; + if (png) { + const stored = await storage.putFile({ companyId, namespace: `agent-avatars/${agentId}`, originalFilename: "avatar.png", contentType: "image/png", body: png }); + newObjectKey = stored.objectKey; + const [asset] = await tx.insert(assets).values({ ...stored, companyId, createdByAgentId: agentId, + createdByUserId: actor.actorType === "user" ? actor.actorId : null }).returning(); + appearance.customAvatarAssetId = asset!.id; + } + await agentService(txDb).update(agentId, { appearance }, { recordRevision: { + createdByAgentId: actor.agentId, createdByUserId: actor.actorType === "user" ? actor.actorId : null, source: "avatar-upload", + } }); + await logActivity(txDb, { ...actor, companyId, action: "agent.avatar_updated", entityType: "agent", entityId: agentId, + details: { assetId: appearance.customAvatarAssetId ?? null, byteSize: png?.length ?? 0 } }, publications); + return { agentId, appearance, avatarUrl: agentAvatarUrl(appearance) }; + }); + publications.forEach(publishActivity); + return result; + } catch (error) { + if (newObjectKey) await storage.deleteObject(companyId, newObjectKey).catch(() => {}); + throw error; + } +} diff --git a/server/src/services/agents.ts b/server/src/services/agents.ts index f47a20ce612..59e3a905123 100644 --- a/server/src/services/agents.ts +++ b/server/src/services/agents.ts @@ -7,6 +7,7 @@ import { and, desc, eq, gte, inArray, lt, ne, or, sql } from "drizzle-orm"; import type { Db } from "@paperclipai/db"; import { agents, + assets, toolConnectionInstalls, agentConfigRevisions, agentApiKeys, @@ -755,6 +756,15 @@ export function agentService(db: Db, budgetHooks: BudgetServiceHooks = {}) { assertBuiltInAgentMetadataMutationAllowed(existing.metadata, data.metadata, options); } + if (data.appearance?.customAvatarAssetId) { + const [asset] = await db.select().from(assets).where(and( + eq(assets.id, data.appearance.customAvatarAssetId), eq(assets.companyId, existing.companyId), + eq(assets.createdByAgentId, id), + )); + if (!asset || asset.contentType !== "image/png" || !asset.objectKey.startsWith(`${existing.companyId}/agent-avatars/${id}/`)) { + throw unprocessable("Use the avatar upload endpoint to set this agent's image"); + } + } const normalizedPatch = { ...data } as Partial; if (data.permissions !== undefined) { normalizedPatch.permissions = normalizeAgentPermissions(data.permissions); @@ -913,6 +923,7 @@ export function agentService(db: Db, budgetHooks: BudgetServiceHooks = {}) { getById, create: async (companyId: string, data: Omit, options?: CreateAgentOptions) => { + if (data.appearance?.customAvatarAssetId) throw unprocessable("Create the agent before uploading its avatar"); assertBuiltInAgentMetadataMutationAllowed(null, data.metadata, options); if (data.reportsTo) { await ensureManager(companyId, data.reportsTo); diff --git a/server/src/services/chat-slack-registration.ts b/server/src/services/chat-slack-registration.ts index 212bc4054a7..a42909e7ae2 100644 --- a/server/src/services/chat-slack-registration.ts +++ b/server/src/services/chat-slack-registration.ts @@ -218,7 +218,9 @@ export function slackChatRegistrationService(db: Db, options: { // Cloud ingress requires a tenant session. Send the preset PNG bytes so // Slack does not need to fetch an authenticated Paperclip URL. const render = options.renderAvatar ?? (avatarPool ??= createAgentAvatarPool()).render; - const png = await render({ appearance: resolveAgentAppearance(current.agentAppearance, current.endpoint.assignedAgentId), + const appearance = { ...resolveAgentAppearance(current.agentAppearance, current.endpoint.assignedAgentId) }; + delete appearance.customAvatarAssetId; // The preset renderer cannot read private uploaded assets. + const png = await render({ appearance, size: 512, scale: 1, pose: "rest", muted: false, background: "paperclip-dark" }); await endpoint(endpointId, actor); await lease.assertOwned(); diff --git a/server/src/services/company-portability.ts b/server/src/services/company-portability.ts index 7d2824afa40..ad438f88298 100644 --- a/server/src/services/company-portability.ts +++ b/server/src/services/company-portability.ts @@ -3083,6 +3083,16 @@ function readAgentSkillRefs(frontmatter: Record) { )); } +/** Uploaded avatars belong to one company/agent; portable packages retain the preset fallback. */ +function portableAgentAppearance(value: unknown, warnings: string[], slug: string) { + const appearance = agentAppearanceSchema.parse(value); + if (appearance.customAvatarAssetId) { + delete appearance.customAvatarAssetId; + warnings.push(`Agent ${slug} uploaded avatar was omitted because image assets are instance-local. Upload it again after import.`); + } + return appearance; +} + function buildManifestFromPackageFiles( files: Record, opts?: { sourceLabel?: { companyId: string; companyName: string } | null }, @@ -3241,7 +3251,7 @@ function buildManifestFromPackageFiles( role: asString(extension.role) ?? asString(frontmatter.role) ?? "agent", title, icon: asString(extension.icon), - appearance: extension.appearance == null ? undefined : agentAppearanceSchema.parse(extension.appearance), + appearance: extension.appearance == null ? undefined : portableAgentAppearance(extension.appearance, warnings, slug), capabilities: asString(extension.capabilities), reportsToSlug: asString(frontmatter.reportsTo) ?? asString(extension.reportsTo), reportsToExistingAgentId: asString(extension.reportsToExistingAgentId), @@ -4262,7 +4272,7 @@ export function companyPortabilityService(db: Db, storage?: StorageService) { const extension = stripEmptyValues({ role: agent.role !== "agent" ? agent.role : undefined, icon: agent.icon ?? null, - appearance: agent.appearance, + appearance: agent.appearance == null ? undefined : portableAgentAppearance(agent.appearance, warnings, slug), capabilities: agent.capabilities ?? null, adapter: { type: agent.adapterType, @@ -5609,7 +5619,7 @@ export function companyPortabilityService(db: Db, storage?: StorageService) { role: manifestAgent.role, title: manifestAgent.title, icon: manifestAgent.icon, - ...(manifestAgent.appearance ? { appearance: manifestAgent.appearance } : {}), + ...(manifestAgent.appearance ? { appearance: portableAgentAppearance(manifestAgent.appearance, warnings, manifestAgent.slug) } : {}), capabilities: manifestAgent.capabilities, reportsTo: null, adapterType: normalizedAdapter.adapterType, diff --git a/server/src/services/dot-invitations.ts b/server/src/services/dot-invitations.ts new file mode 100644 index 00000000000..975e7b0bc40 --- /dev/null +++ b/server/src/services/dot-invitations.ts @@ -0,0 +1,78 @@ +import { and, desc, eq, isNull, ne, sql } from "drizzle-orm"; +import { activityLog, agents, companies, dotAgentBindings, type Db } from "@paperclipai/db"; +import { agentService } from "./agents.js"; +import { approvalService } from "./approvals.js"; +import { accessService } from "./access.js"; +import { agentInstructionsService } from "./agent-instructions.js"; +import { loadDefaultAgentInstructionsBundle } from "./default-agent-instructions.js"; +import { logActivity } from "./activity-log.js"; +import { dotRunnerBroker } from "./dot-runner-broker.js"; +import { notFound, unprocessable } from "../errors.js"; + +/** One unfinished invitation per operator/company. Only non-secret references are persisted. */ +export function dotInvitationService(db: Db) { + async function pending(database: Db, companyId: string, operatorId: string) { + const rows = await database.select({ agent: agents, binding: dotAgentBindings }) + .from(agents).leftJoin(dotAgentBindings, and(eq(dotAgentBindings.agentId, agents.id), isNull(dotAgentBindings.revokedAt))) + .where(and(eq(agents.companyId, companyId), ne(agents.status, "terminated"), + eq(agents.adapterType, "paperclip_runner"), sql`${agents.adapterConfig}->>'provider' = 'openai_dot'`, + sql`exists (select 1 from ${activityLog} where ${activityLog.companyId} = ${agents.companyId} + and ${activityLog.entityId} = ${agents.id}::text and ${activityLog.entityType} = 'agent' + and ${activityLog.actorType} = 'user' and ${activityLog.actorId} = ${operatorId} + and ${activityLog.action} = 'agent.hire_created' and ${activityLog.details}->>'source' = 'dot-invitation')`)).orderBy(desc(agents.createdAt)); + return rows.find(row => row.binding?.status !== "ready")?.agent ?? null; + } + async function describe(agent: typeof agents.$inferSelect) { + const approval = await approvalService(db).findOpenHireApprovalForAgent(agent.companyId, agent.id); + return { agent: { id: agent.id, name: agent.name, status: agent.status }, approvalId: approval?.id ?? null, + binding: await dotRunnerBroker(db).bindingForAgent(agent.companyId, agent.id) }; + } + return { + async resume(companyId: string, operatorId: string) { + const agent = await pending(db, companyId, operatorId); + return agent ? describe(agent) : null; + }, + async create(companyId: string, operatorId: string) { + if (!await dotRunnerBroker(db).enabled()) throw unprocessable("Enable OpenAI Dot and Assistant connections (MCP) in experimental settings."); + const agent = await db.transaction(async tx => { + const database = tx as unknown as Db; + // SQL locking also serializes retries on different control-plane replicas. + const [company] = await tx.select().from(companies).where(eq(companies.id, companyId)).for("update"); + if (!company) throw notFound("Company not found"); + if (company.status !== "active") throw unprocessable("Activate this company before inviting Dot."); + const existing = await pending(database, companyId, operatorId); + if (existing) return existing; + const svc = agentService(database); + let created = await svc.create(companyId, { + name: "Dot", role: "general", adapterType: "paperclip_runner", + adapterConfig: { provider: "openai_dot", lifecycleMode: "per_turn", allowUnmeteredProvider: true, + dotWorkspaceAccess: false, dotAttachmentAccess: false }, + runtimeConfig: { heartbeat: { enabled: false, wakeOnDemand: true } }, + status: company.requireBoardApprovalForNewAgents ? "pending_approval" : "idle", + metadata: { dotInvitation: { operatorId } }, + }, { createdByUserId: operatorId }); + const bundle = await agentInstructionsService(database).materializeManagedBundle(created, + await loadDefaultAgentInstructionsBundle("default"), { entryFile: "AGENTS.md", replaceExisting: false }); + created = (await svc.update(created.id, { adapterConfig: bundle.adapterConfig }, { allowPendingApprovalConfigUpdate: true }))!; + const access = accessService(database); + await access.ensureMembership(companyId, "agent", created.id, "member", "active"); + await access.setPrincipalPermission(companyId, "agent", created.id, "tasks:assign", true, operatorId); + const approval = company.requireBoardApprovalForNewAgents ? await approvalService(database).create(companyId, { + type: "hire_agent", status: "pending", requestedByUserId: operatorId, + payload: { agentId: created.id, name: created.name, role: created.role, adapterType: created.adapterType, + adapterConfig: created.adapterConfig, runtimeConfig: created.runtimeConfig, metadata: created.metadata, + budgetMonthlyCents: created.budgetMonthlyCents, requestedConfigurationSnapshot: { + adapterType: created.adapterType, runtimeConfig: created.runtimeConfig, adapterConfig: created.adapterConfig, + } }, + }) : null; + await logActivity(database, { companyId, actorType: "user", actorId: operatorId, action: "agent.hire_created", + entityType: "agent", entityId: created.id, details: { name: created.name, role: created.role, + requiresApproval: !!approval, approvalId: approval?.id ?? null, source: "dot-invitation" } }); + if (approval) await logActivity(database, { companyId, actorType: "user", actorId: operatorId, action: "approval.created", + entityType: "approval", entityId: approval.id, details: { type: "hire_agent", agentId: created.id } }); + return created; + }); + return describe(agent); + }, + }; +} diff --git a/server/src/services/dot-runner-broker.ts b/server/src/services/dot-runner-broker.ts index 4edda023c0d..a65107e51d5 100644 --- a/server/src/services/dot-runner-broker.ts +++ b/server/src/services/dot-runner-broker.ts @@ -1,6 +1,9 @@ import { createHash, randomBytes, randomUUID } from "node:crypto"; import { and, asc, eq, gt, inArray, isNull, sql } from "drizzle-orm"; import { z } from "zod"; +import { setAgentAvatarSchema, type SetAgentAvatarInput } from "@paperclipai/shared"; +import { setAgentProfileAvatar } from "./agent-profile-avatar.js"; +import { getStorageService } from "../storage/index.js"; import { agents, companies, heartbeatRuns, issues, agentWakeupRequests, nativeRunFinalizations, mcpOauthGrants, mcpEventSubscriptions, dotAgentBindings as bindings, dotRunnerAssignments as assignments, dotRunnerOperations as operations, dotMailboxItems as mailbox, type Db } from "@paperclipai/db"; @@ -30,7 +33,7 @@ function createBroker(db: Db) { const experimental = await settings.getExperimental(); return experimental.enableOpenAiDot && experimental.enablePublicMcp; } - const ports = new Map Promise; revoke?: () => Promise }>(); + const ports = new Map Promise; revoke?: () => Promise }>(); async function principalBinding(principal: McpPrincipal, requireReady = true, allowPaused = false) { if (principal.grant.purpose !== "agent" || !principal.grant.scopes.includes("paperclip:agent")) throw fail("Use the dedicated Dot agent connection."); const [binding] = await db.select().from(bindings).where(and(eq(bindings.grantId, principal.grant.id), @@ -85,6 +88,9 @@ function createBroker(db: Db) { const [a] = await db.select().from(assignments).where(eq(assignments.id, row.assignmentId)); const port = a && ports.get(a.runId); if (!port || !["reserved", "admitted"].includes(row.status)) return; + const [owner] = await db.select().from(nativeRunFinalizations).where(eq(nativeRunFinalizations.runId, a.runId)); + if (!owner || owner.controllerGeneration !== port.controllerGeneration || a.controllerGeneration !== port.controllerGeneration + || !owner.leaseExpiresAt || owner.leaseExpiresAt <= new Date()) return; // Sending the same stable command is safe after a lost ACK. The Runner's // command/semantic receipts decide whether it was already admitted. if (!a || a.status === "fenced" || a.expiresAt <= new Date()) return; @@ -103,22 +109,31 @@ function createBroker(db: Db) { return { enabled, - async createPairing(input: { companyId: string; agentId: string; operatorId: string; dotUrl?: string }) { + async createPairing(input: { companyId: string; agentId: string; operatorId: string; dotUrl?: string; replaceBindingId?: string }) { if (!await enabled()) throw fail("Enable OpenAI Dot and Assistant connections (MCP) in experimental settings."); if (input.dotUrl && !/^https:\/\/chatgpt\.com\/dots\/[A-Za-z0-9-]+$/.test(input.dotUrl)) throw fail("Use the Dot's ChatGPT URL."); const code = randomBytes(24).toString("base64url"); const binding = await db.transaction(async tx => { const [agent] = await tx.select().from(agents).where(and(eq(agents.id, input.agentId), eq(agents.companyId, input.companyId))).for("update"); - if (!agent || agent.adapterType !== "paperclip_runner" || agent.status === "pending_approval" || agent.status === "terminated") throw fail("Choose an approved Paperclip Runner agent."); + if (!agent || agent.adapterType !== "paperclip_runner" || agent.adapterConfig.provider !== "openai_dot" || ["pending_approval", "terminated", "paused"].includes(agent.status)) throw fail("Choose an approved Paperclip Runner agent."); const [existing] = await tx.select().from(bindings).where(and(eq(bindings.companyId, input.companyId), eq(bindings.agentId, input.agentId), isNull(bindings.revokedAt))); - if (existing) throw fail("Revoke the existing connection before creating another pairing code."); - const [created] = await tx.insert(bindings).values({ ...input, pairingCodeHash: hash(code), pairingExpiresAt: new Date(Date.now() + 15 * 60_000) }).returning(); + if (existing) { + if (existing.id !== input.replaceBindingId || existing.status !== "pairing" || existing.operatorId !== input.operatorId) { + throw fail("This invitation changed. Refresh before creating a new prompt."); + } + // Consume only the pending binding named by the caller. An OAuth race + // cannot revoke a connection that has already been established. + const [replaced] = await tx.update(bindings).set({ revokedAt: new Date(), status: "revoked", pairingCodeHash: null, updatedAt: new Date() }) + .where(and(eq(bindings.id, existing.id), eq(bindings.status, "pairing"), isNull(bindings.revokedAt))).returning(); + if (!replaced) throw fail("Dot connected while this prompt was being replaced. Refresh the connection."); + } else if (input.replaceBindingId) throw fail("This invitation changed. Refresh before creating a new prompt."); + const [created] = await tx.insert(bindings).values({ companyId: input.companyId, agentId: input.agentId, operatorId: input.operatorId, dotUrl: input.dotUrl, pairingCodeHash: hash(code), pairingExpiresAt: new Date(Date.now() + 15 * 60_000) }).returning(); await logActivity(tx as unknown as Db, { companyId: input.companyId, actorType: "user", actorId: input.operatorId, action: "dot.pairing_created", entityType: "agent", entityId: input.agentId, details: { bindingId: created!.id } }); return created!; }); return { bindingId: binding.id, pairingCode: code, expiresAt: binding.pairingExpiresAt, - instructions: "Connect the private Paperclip Dot plugin at /mcp/runner, approve agent access, then call paperclip_dot_pair with this code. Subscribe to paperclip.dot.mailbox_updated for the returned binding. Run the event test before assigning work." }; + instructions: "Connect the private Paperclip Dot plugin at /mcp/runner, approve agent access, then call paperclip_dot_pair with this code. Subscribe to paperclip.dot.mailbox_updated for the returned binding. Paperclip sends the event test automatically before work can be assigned." }; }, async pair(principal: McpPrincipal, code: string) { if (!await enabled() || principal.grant.purpose !== "agent" || !principal.grant.scopes.includes("paperclip:agent")) throw fail("A dedicated Dot agent grant is required."); @@ -149,7 +164,7 @@ function createBroker(db: Db) { const [active] = await db.select({ id: assignments.id, runId: assignments.runId, status: assignments.status, lastActivityAt: assignments.lastActivityAt }).from(assignments) .where(and(eq(assignments.bindingId, b.id), inArray(assignments.status, ["offered", "accepted"]))); return { id: b.id, companyId: b.companyId, agentId: b.agentId, generation: b.generation, status: b.status, dotUrl: b.dotUrl, - readyAt: b.readyAt, connected: !!b.grantId, subscriptionVerified: activeSubscriptions.length > 0, + readyAt: b.readyAt, pairingExpiresAt: b.pairingExpiresAt, challengeExpiresAt: b.challengeExpiresAt, connected: !!b.grantId, subscriptionVerified: activeSubscriptions.length > 0, hasPendingChallenge: !!b.challengeHash && !!b.challengeExpiresAt && b.challengeExpiresAt > new Date(), assignment: active ? { ...active, attentionRequired: active.status === "accepted" && active.lastActivityAt.getTime() < Date.now() - 15 * 60_000 } : null }; }, @@ -228,6 +243,12 @@ function createBroker(db: Db) { return db.select({ id: issues.id, identifier: issues.identifier, title: issues.title, status: issues.status }).from(issues) .where(and(eq(issues.companyId, b.companyId), eq(issues.assigneeAgentId, b.agentId), inArray(issues.status, ["todo", "in_progress", "blocked"]), after ? gt(issues.id, after) : undefined)).orderBy(asc(issues.id)).limit(50); }, + async setAvatar(principal: McpPrincipal, input: SetAgentAvatarInput) { + if (!await enabled()) throw fail("Dot is disabled in experimental settings."); + const b = await principalBinding(principal, false); + return setAgentProfileAvatar(db, getStorageService(), b.companyId, b.agentId, input, + { actorType: "agent", actorId: b.agentId, agentId: b.agentId }); + }, async capabilities(principal: McpPrincipal) { const b = await principalBinding(principal, false); const [agent] = await db.select().from(agents).where(eq(agents.id, b.agentId)); @@ -238,6 +259,7 @@ function createBroker(db: Db) { permissions: agent!.permissions, ready: state?.status === "ready" && state.subscriptionVerified, assignment: state?.assignment ?? null, idle: { read: ["paperclip_dot_capabilities", "paperclip_dot_tasks", "paperclip_dot_inbox"], + profile: "paperclip_dot_set_avatar", start: "paperclip_dot_request_turn", instruction: "You can start work without an existing task. Call paperclip_dot_request_turn with the user's request and a stable UUID. Drain the inbox, read and accept the assignment, then use its full catalog through paperclip_dot_tool. Task tools run as this agent under normal permissions, never as the owner." }, runtime: { skills: "pinned_read", mcp: "assigned_gateway", taskAttachments: agent!.adapterConfig?.dotAttachmentAccess === true ? "assigned_task_read" : "disabled", attachmentPrerequisite: "Enable task attachment reading on this Dot agent to send verified contents of its current assigned task files to OpenAI. This does not enable workspace commands.", workspace: agent!.adapterConfig?.dotWorkspaceAccess === true ? "sandboxed_tool_bridge" : "disabled", @@ -355,19 +377,35 @@ function createBroker(db: Db) { return outcome; }); }, - async challenge(companyId: string, agentId: string) { + async challenge(companyId: string, agentId: string, options: { automatic?: boolean; bindingId?: string } = {}) { const state = await this.bindingForAgent(companyId, agentId); - if (!await enabled() || !state || !state.subscriptionVerified) throw fail("Connect and subscribe the Dot first."); + if (!await enabled() || !state || !state.subscriptionVerified || (options.bindingId && options.bindingId !== state.id)) { + if (options.automatic) return { status: "unavailable" }; + throw fail("Connect and subscribe the Dot first."); + } const nonce = randomBytes(24).toString("base64url"); - await db.transaction(async tx => { + const available = await db.transaction(async tx => { const [b] = await tx.select().from(bindings).where(eq(bindings.id, state.id)).for("update"); - if (!b || b.revokedAt || b.challengeHash && b.challengeExpiresAt && b.challengeExpiresAt > new Date()) throw fail("An event test is already pending."); + if (!b || b.revokedAt || b.generation !== state.generation) { + if (options.automatic) return false; + throw fail("Binding authority changed."); + } + if (options.automatic && (b.challengeHash || b.readyAt)) return; + if (b.challengeHash && b.challengeExpiresAt && b.challengeExpiresAt > new Date()) return; + const [subscription] = await tx.select({ id: mcpEventSubscriptions.id }).from(mcpEventSubscriptions).where(and( + eq(mcpEventSubscriptions.bindingId, b.id), eq(mcpEventSubscriptions.grantId, b.grantId!), + isNull(mcpEventSubscriptions.stoppedAt), gt(mcpEventSubscriptions.expiresAt, new Date()))); + if (!subscription) { + if (options.automatic) return false; + throw fail("The event subscription is no longer verified."); + } await tx.update(bindings).set({ challengeHash: hash(nonce), challengeExpiresAt: new Date(Date.now() + 10 * 60_000), updatedAt: new Date() }).where(eq(bindings.id, b.id)); await tx.insert(mailbox).values({ companyId, bindingId: b.id, bindingGeneration: b.generation, kind: "readiness_challenge", sourceEventId: "challenge_" + randomUUID(), references: { challenge: nonce } }); await logActivity(tx as unknown as Db, { companyId, actorType: "user", actorId: b.operatorId, action: "dot.event_test_requested", entityType: "agent", entityId: agentId, details: { bindingId: b.id } }); }); + if (available === false) return { status: "unavailable" }; return { status: "pending", message: "Waiting for the Dot to receive the event, read its mailbox and complete the harmless challenge." }; }, async confirmChallenge(principal: McpPrincipal, nonce: string) { @@ -375,7 +413,7 @@ function createBroker(db: Db) { const connection = await this.bindingForAgent(b.companyId, b.agentId); if (!connection?.subscriptionVerified) throw fail("The event subscription is no longer verified."); const [updated] = await db.update(bindings).set({ status: "ready", readyAt: new Date(), challengeHash: null, challengeExpiresAt: null, updatedAt: new Date() }) - .where(and(eq(bindings.id, b.id), eq(bindings.generation, b.generation), eq(bindings.challengeHash, hash(nonce)), gt(bindings.challengeExpiresAt, new Date()))).returning(); + .where(and(eq(bindings.id, b.id), eq(bindings.generation, b.generation), isNull(bindings.revokedAt), eq(bindings.grantId, principal.grant.id), eq(bindings.challengeHash, hash(nonce)), gt(bindings.challengeExpiresAt, new Date()))).returning(); if (!updated) throw fail("Event test expired or does not match."); await logActivity(db, { companyId: b.companyId, actorType: "agent", actorId: b.agentId, action: "dot.event_test_completed", entityType: "agent", entityId: b.agentId, details: { bindingId: b.id } }); @@ -422,14 +460,34 @@ function createBroker(db: Db) { if (existing && hasProviderCheckpoint !== true) throw fail("Dot bridge checkpoint missing; reconcile external work before continuing."); const token = Symbol(runId); if (ports.has(runId)) throw fail("A Dot run controller is already attached."); - ports.set(runId, { token, send, revoke }); const [coordinator] = await db.select().from(nativeRunFinalizations).where(eq(nativeRunFinalizations.runId, runId)); - if (!coordinator) { ports.delete(runId); throw fail("Run controller ownership is unavailable."); } - await db.update(assignments).set({ controllerGeneration: coordinator.controllerGeneration }).where(and(eq(assignments.runId, runId), eq(assignments.bindingGeneration, execution.provider.binding.bindingGeneration))); - const rows = await db.select({ operation: operations }).from(operations).innerJoin(assignments, eq(assignments.id, operations.assignmentId)) - .where(and(eq(assignments.runId, runId), inArray(operations.status, ["reserved", "admitted"]))).orderBy(asc(operations.createdAt)); - for (const { operation } of rows) void forward(operation).catch(() => {}); - return async () => { if (ports.get(runId)?.token === token) ports.delete(runId); }; + if (!coordinator?.leaseExpiresAt || coordinator.leaseExpiresAt <= new Date()) throw fail("Run controller ownership is unavailable."); + // Reserve synchronously after the ownership read; another attachment + // may have completed while that read was in flight. + if (ports.has(runId)) throw fail("A Dot run controller is already attached."); + ports.set(runId, { token, send, revoke, controllerGeneration: coordinator.controllerGeneration }); + try { + await db.update(assignments).set({ controllerGeneration: coordinator.controllerGeneration }).where(and(eq(assignments.runId, runId), + eq(assignments.bindingGeneration, execution.provider.binding.bindingGeneration), sql`${assignments.controllerGeneration} <= ${coordinator.controllerGeneration}`)); + } catch (error) { if (ports.get(runId)?.token === token) ports.delete(runId); throw error; } + // Any HTTP replica can reserve an operation. Only this run's current + // controller drains it. No Runner/sandbox is needed for an idle binding. + let timer: NodeJS.Timeout | undefined; + const drain = async () => { + try { + if (ports.get(runId)?.token !== token) return; + const rows = await db.select({ operation: operations }).from(operations).innerJoin(assignments, eq(assignments.id, operations.assignmentId)) + .where(and(eq(assignments.runId, runId), inArray(operations.status, ["reserved", "admitted"]))).orderBy(asc(operations.createdAt)).limit(32); + for (const { operation } of rows) { + if (ports.get(runId)?.token !== token) break; + await forward(operation).catch(() => {}); // durable rows remain retryable + } + } finally { + if (ports.get(runId)?.token === token) { timer = setTimeout(() => { void drain().catch(() => {}); }, 2000); timer.unref(); } + } + }; + void drain().catch(() => {}); + return async () => { if (timer) clearTimeout(timer); if (ports.get(runId)?.token === token) ports.delete(runId); }; }, dispatch: async event => { const p = event.payload; @@ -499,6 +557,7 @@ export function createDotRunnerMcpTools(db: Db): PublicMcpToolExtension { const broker = dotRunnerBroker(db); const request = { assignmentId: z.uuid(), requestId: z.uuid() }; const definitions = [ + { name: "paperclip_dot_set_avatar", description: "Update only your bound Paperclip agent's avatar, including while idle after pairing. If you can obtain your own avatar, send its PNG/JPEG/WebP bytes as raw base64 (max 512 KiB, static image). Do not send a URL or invent an image. Use imageBase64: null to restore the Paperclip character. Repeating the same image is safe. No active assignment is needed.", schema: setAgentAvatarSchema }, { name: "paperclip_dot_capabilities", description: "Discover your agent identity, responsible person, configured permissions, enforcement limits, idle entry point, runtime capabilities, and prerequisites. Use this before concluding you cannot act.", schema: z.object({}).strict() }, { name: "paperclip_dot_request_turn", description: "Start a governed Runner turn for a request from your Dot conversation, even when no task is assigned. Creates one auditable intake task using normal permissions and admission. Retry the exact prompt with the same UUID.", schema: z.object({ prompt: z.string().trim().min(1).max(20_000), requestId: z.uuid() }).strict() }, { name: "paperclip_dot_renew", description: "Renew an accepted assignment before expiry. Choose an expiry no more than two hours ahead or 24 hours after admission. Cannot revive expired, stopped, or revoked work.", schema: z.object({ ...request, expiresAtUnixMs: z.number().int().positive() }).strict() }, @@ -523,7 +582,8 @@ export function createDotRunnerMcpTools(db: Db): PublicMcpToolExtension { const definition = definitions.find(d => d.name === name); if (!definition) throw fail("Unknown Dot tool."); const input = definition.schema.parse(raw) as Record; let result: unknown; - if (name === "paperclip_dot_capabilities") result = await broker.capabilities(principal); + if (name === "paperclip_dot_set_avatar") result = await broker.setAvatar(principal, setAgentAvatarSchema.parse(input)); + else if (name === "paperclip_dot_capabilities") result = await broker.capabilities(principal); else if (name === "paperclip_dot_request_turn") result = await broker.requestTurn(principal, String(input.prompt), String(input.requestId)); else if (name === "paperclip_dot_tasks") result = await broker.tasks(principal, input.after ? String(input.after) : null); else if (name === "paperclip_dot_request_work") result = await broker.requestWork(principal, String(input.issueId), String(input.requestId)); diff --git a/server/src/services/heartbeat.ts b/server/src/services/heartbeat.ts index f83e5881f7e..9406f4a5cc3 100644 --- a/server/src/services/heartbeat.ts +++ b/server/src/services/heartbeat.ts @@ -1,3 +1,10 @@ +import { + HEARTBEAT_RUN_TERMINAL_STATUSES, + DETACHED_PROCESS_ERROR_CODE, + isProcessAlive, + CANCELLABLE_HEARTBEAT_RUN_STATUSES, + createHeartbeatRecovery, +} from "./heartbeat/recovery.js"; import { BOUNDED_TRANSIENT_HEARTBEAT_RETRY_MAX_ATTEMPTS, normalizeAgentNameKey, @@ -238,7 +245,7 @@ import { NativeWorkspaceFinalizationOwnershipLostError, type NativeWorkspaceFinalizationOwnership, } from "./native-runtime/native-workspace-finalization-ownership.js"; -import { hasStopOnlyCleanup, settleStopOnlyCleanup } from "./sandbox-stop-and-retain.js"; + import { reserveRunBudget } from "./budget-reservations.js"; import { accountRunCost, createCostAccountingReconciler } from "./run-cost-accounting.js"; import { createRunUsageRecorder } from "./usage-receipts.js"; @@ -257,9 +264,18 @@ import { withAdapterExecutionPhase } from "@paperclipai/adapter-utils/execution- import { getConversationConfirmationContext } from "./conversation-confirmation-context.js"; import { PROCESS_IDENTITY_RECORDED, recordNativeLocalProcessStop } from "./native-local-process-stop.js"; import { hasAcknowledgedNativeReassignmentStopIntent, hasAcknowledgedNativeStopIntent, isAcknowledgedNativeStop, acknowledgedNativeStopExecutionHasStopped } from "./acknowledged-native-stop.js"; -import { legacyControllerBootId, legacyControllerClaim, renewLegacyControllerLease, hasLiveLegacyController, revokeExpiredLegacyController, watchLegacyControllerLease } from "./legacy-controller-lease.js"; +import { + legacyControllerBootId, + legacyControllerClaim, + renewLegacyControllerLease, + watchLegacyControllerLease, +} from "./legacy-controller-lease.js"; import { completeTerminatedRemoteNativeSessionCleanup } from "../vendor/paperclip-runner/index.js"; -import { hasRemoteTerminationReceipt, remoteExecutionHasStopped, remoteTerminationReceipt, stoppedRemoteCleanupScopes } from "./remote-execution-termination.js"; +import { + hasRemoteTerminationReceipt, + remoteExecutionHasStopped, + stoppedRemoteCleanupScopes, +} from "./remote-execution-termination.js"; import { applyConnectorSkills, prepareConnectorSkillDelivery, resolveConnectorAssignments } from "./connector-runtime.js"; import { admitExplicitNativeContinuation, @@ -436,15 +452,11 @@ import { buildNativeExecutionWithCheckpoint, buildNativeRuntimeContext, cancelNativeSession, - claimNativeRestartRecoveries, claimWarmNativeInstructionCopy, nativeSessionWorkspaceScope, closeWarmNativeSessionsForEnvironment, - closeIdleWarmNativeSessionsForRestart, reserveWarmNativeInstructionDirectory, - currentNativeControllerIdentity, dispatchNativeSessionResumptions, - detachNativeSessionsForRestart, ensureNativeCompletionContract, executePaperclipNativeSession, finalizeNativeRun, @@ -463,13 +475,9 @@ import { nativeToolContractFingerprintForTarget, prepareNativeSessionBootstrapPersistence, prepareNativeWorkspaceSync, - readNativeWorkspaceSyncReference, recordNativeFinalizationFailure, type NativeRestartRecoveryClaim, rebindNativeSessionCheckpoint, - reconcileNativeFinalizations, - reconcileRetainedNativeSessionCleanup, - reconcileRetainedNativeSessionCleanups, resolveHeartbeatNativeRuntimeMode, } from "./native-runtime/index.js"; import { @@ -486,7 +494,6 @@ import { type NativeRunHistoricalSpan, } from "./native-runtime/native-run-trace.js"; import { - drainRetainedRunnerdMaintenanceOperations, describeRunnerdNativeSessionBackend, parseNativeExecutionInput, type NativeExecutionInput, @@ -541,8 +548,7 @@ import { } from "./agent-task-run-telemetry.js"; import { readAiConnectionConfigurationFailure } from "./ai-connection-configuration-failure.js"; import { reportRunFailure } from "./run-failure-report.js"; -import { performance } from "node:perf_hooks"; -import { buildProcessLossDiagnostic } from "./process-loss-diagnostics.js"; + import { collectRunFailureSecretValues, type RunFailureReportOptions } from "./run-failure-diagnostics.js"; import { companySkillService } from "./company-skills.js"; import { budgetService, withCurrentBudgetEnforcement, type BudgetEnforcementScope } from "./budgets.js"; @@ -810,15 +816,7 @@ import { touchHeartbeatRunRuntimeStatus, } from "./heartbeat-run-runtime-status.js"; import { - findMissingHotRestartSnapshotRunIds, - readHotRestartIntent, readProcessStartedAt, - removeHotRestartIntent, - shouldHonorHotRestartIntentForProcess, - writeHotRestartReport, - writeHotRestartShutdownSnapshot, - type HotRestartIntentRun, - type HotRestartReportRun, } from "./hot-restart.js"; import { assertLowTrustRuntimeServicesAllowed, @@ -827,7 +825,7 @@ import { import { resolveAndRetainRunTrustPreset } from "./run-trust-preset.js"; import type { PluginWorkerManager } from "./plugin-worker-manager.js"; -import { serverVersion } from "../version.js"; + import { computeTaskDrain, applyTaskDrain, startTaskDrain, stopTaskDrain, readTaskDrain } from "./task-admission.js"; const MAX_LIVE_LOG_CHUNK_BYTES = 8 * 1024; @@ -863,123 +861,16 @@ const LIVENESS_BOOKKEEPING_ACTIVITY_ACTIONS = [ ]; const DEFERRED_WAKE_CONTEXT_KEY = "_paperclipWakeContext"; - const ACCEPTED_PLAN_CONVERSION_SKILL_KEY = "paperclipai/paperclip/paperclip-converting-plans-to-tasks"; - - -const DETACHED_PROCESS_ERROR_CODE = "process_detached"; -const NATIVE_OWNERSHIP_UNVERIFIED_MESSAGE = - "Native execution ownership could not be verified; automatic recovery is blocked"; -// The reaper sweeps at most this many pending_cleanup leases per tick. -const PENDING_CLEANUP_SWEEP_PAGE_SIZE = 20; -const pendingCleanupAttemptsInFlight = new Set(); -// Escalate and slow cleanup after this many attempts; never abandon a live lease. -const PENDING_CLEANUP_SWEEP_ATTEMPT_CAP = 5; -// The reaper stores its retry state under these keys in the lease metadata. -const PENDING_CLEANUP_ATTEMPTS_METADATA_KEY = "pendingCleanupRetryAttempts"; -const PENDING_CLEANUP_CAP_WARNED_METADATA_KEY = "pendingCleanupRetryCapWarned"; -// The reaper sweeps at most this many orphaned active leases per tick. -const ORPHANED_ACTIVE_LEASE_SWEEP_PAGE_SIZE = 20; - -// A provider or plugin destroy rejection can carry a bearer credential, a -// signed URL, or provider response detail in its name, code, message, cause, or -// stack. The exception fields cross the server boundary, so they are not a -// trusted enum. The pending_cleanup sweep logs never read the exception. Each -// catch site logs a constant, locally generated `errorKind` instead. -const PENDING_CLEANUP_RETRY_ERROR_KIND = "destroy_failed"; -const PENDING_CLEANUP_SWEEP_ERROR_KIND = "sweep_failed"; -const ORPHANED_ACTIVE_LEASE_SWEEP_ERROR_KIND = "orphaned_active_lease_sweep_failed"; - -// Read the stored retry attempt count as a safe value, directly in SQL. A -// provider can write a malformed value under the attempts key. The type guard -// makes any non-number value read as zero. The reader computes as numeric and -// never casts to int, so a finite number outside the 32-bit range (for example -// 1e300) never throws. The reader clamps a negative value to zero and a positive -// value to the attempt cap. One malformed lease therefore never aborts the page -// sweep. This matches the TypeScript reader `readPendingCleanupRetryAttempts`, -// which clamps to the same range. The claim predicate compares the two readers, -// so both must yield the same value for every input. -function pendingCleanupAttemptsSql() { - return sql` - case - when jsonb_typeof(${environmentLeases.metadata} -> ${PENDING_CLEANUP_ATTEMPTS_METADATA_KEY}) = 'number' - then least( - greatest( - floor((${environmentLeases.metadata} ->> ${PENDING_CLEANUP_ATTEMPTS_METADATA_KEY})::numeric), - 0 - ), - ${PENDING_CLEANUP_SWEEP_ATTEMPT_CAP} - ) - else 0 - end`; -} - -function pendingCleanupRetryDueSql(explicitRetry = false) { - // Ownership renewal and retry cooldown are separate clocks. A late renewal - // cannot change when a completed attempt may retry. Older claims used the - // retry field for both clocks, so retain that fallback until they settle. - const deadline = sql`case - when ${environmentLeases.metadata}->>'pendingCleanupInFlight' = 'true' - and ${environmentLeases.metadata} ? 'pendingCleanupLeaseExpiresAtMs' - then ${environmentLeases.metadata}->'pendingCleanupLeaseExpiresAtMs' - else ${environmentLeases.metadata}->'pendingCleanupRetryAfterMs' end`; - return sql`case - when ${explicitRetry} and coalesce(${environmentLeases.metadata}->>'pendingCleanupInFlight', 'false') != 'true' then true - when jsonb_typeof(${deadline}) = 'number' - then (${deadline})::numeric <= ${Date.now()} - or (${deadline})::numeric > ${Date.now() + 30 * 60_000 + 1_000} - else true end`; -} - -// Choose the `jsonb_set` target root. A provider can write a scalar or array -// metadata root. `jsonb_set` fails on a non-object root, so the reader uses the -// stored metadata only when its root is an object. A NULL, scalar, or array root -// reads as an empty object. `jsonb_typeof(NULL)` is NULL, so the else branch also -// covers a NULL root. -function pendingCleanupMetadataObjectSql() { - return sql`case when jsonb_typeof(${environmentLeases.metadata}) = 'object' then ${environmentLeases.metadata} else '{}'::jsonb end`; -} - -// Read the stored cap-warned flag as a safe boolean, directly in SQL. A -// malformed value reads as false, so the boolean cast never throws. -function pendingCleanupCapWarnedSql() { - return sql`coalesce( - case - when jsonb_typeof(${environmentLeases.metadata} -> ${PENDING_CLEANUP_CAP_WARNED_METADATA_KEY}) = 'boolean' - then (${environmentLeases.metadata} ->> ${PENDING_CLEANUP_CAP_WARNED_METADATA_KEY})::boolean - else false - end, - false - )`; -} - - - - - - - const execFile = promisify(execFileCallback); const EXECUTION_PATH_HEARTBEAT_RUN_STATUSES = [ "queued", "running", "scheduled_retry", ] as const; -const CANCELLABLE_HEARTBEAT_RUN_STATUSES = [ - "queued", - "running", - "scheduled_retry", -] as const; -const NATIVE_QUESTION_CANCELLATION_CONTEXT_KEY = "nativeQuestionCancellation"; -const HEARTBEAT_RUN_TERMINAL_STATUSES = [ - "succeeded", - "interrupted", - "failed", - "cancelled", - "timed_out", -] as const; + const UNSUCCESSFUL_HEARTBEAT_RUN_TERMINAL_STATUSES = [ "failed", "cancelled", @@ -1188,16 +1079,6 @@ const RUNNING_ISSUE_WAKE_REASONS_REQUIRING_FOLLOWUP = new Set([ "issue_recovery_action_restored", ]); -const SESSIONED_LOCAL_ADAPTERS = new Set([ - "claude_local", - "codex_local", - "cursor", - "gemini_local", - "hermes_local", - "kimi_local", - "opencode_local", - "pi_local", -]); // Routes and the scheduler construct separate heartbeatService instances, but // they must agree on in-process adapter executions when reaping stale runs. const activeRunExecutions = new Set(); @@ -1635,10 +1516,6 @@ function isSameTaskScope(left: string | null, right: string | null) { return (left ?? null) === (right ?? null); } -function isTrackedLocalChildProcessAdapter(adapterType: string) { - return SESSIONED_LOCAL_ADAPTERS.has(adapterType); -} - function isHeartbeatRunTerminalStatus( status: string | null | undefined, ): status is (typeof HEARTBEAT_RUN_TERMINAL_STATUSES)[number] { @@ -1916,23 +1793,6 @@ function buildRunEventRuntimeProgress(input: { }; } -// A positive liveness check means some process currently owns the PID. -// On Linux, PIDs can be recycled, so this is a best-effort signal rather -// than proof that the original child is still alive. -function isProcessAlive(pid: number | null | undefined) { - if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) - return false; - try { - process.kill(pid, 0); - return true; - } catch (error) { - const code = (error as NodeJS.ErrnoException | undefined)?.code; - if (code === "EPERM") return true; - if (code === "ESRCH") return false; - return false; - } -} - export async function persistHeartbeatRunProcessMetadata( db: Db, runId: string, @@ -1992,65 +1852,6 @@ async function terminateHeartbeatRunProcess(input: { ); } -function buildProcessLossMessage( - run: { - processPid: number | null; - processGroupId: number | null; - }, - options?: { descendantOnly?: boolean }, -) { - if (options?.descendantOnly && run.processGroupId) { - return `Process lost -- parent pid ${run.processPid ?? "unknown"} exited, but descendant process group ${run.processGroupId} was still alive and was terminated`; - } - if (run.processPid) { - return `Process lost -- child pid ${run.processPid} is no longer running`; - } - if (run.processGroupId) { - return `Process lost -- process group ${run.processGroupId} is no longer running`; - } - return "Process lost -- server may have restarted"; -} - -function readHotRestartAdoptionMetadata( - resultJson: Record | null | undefined, -) { - const result = parseObject(resultJson); - const hotRestart = parseObject(result.hotRestart); - if (hotRestart.adopted !== true || typeof hotRestart.adoptedAt !== "string") - return null; - return hotRestart; -} - -function mergeHotRestartAdoptionResultJson( - resultJson: Record | null | undefined, - input: { - adoptedAt: Date; - previousServerPid: number; - newServerPid: number; - previousServerVersion: string | null; - newServerVersion: string; - processPid: number | null; - processGroupId: number | null; - }, -) { - const result = parseObject(resultJson); - const existing = parseObject(result.hotRestart); - return { - ...result, - hotRestart: { - ...existing, - adopted: true, - adoptedAt: input.adoptedAt.toISOString(), - previousServerPid: input.previousServerPid, - newServerPid: input.newServerPid, - previousServerVersion: input.previousServerVersion, - newServerVersion: input.newServerVersion, - processPid: input.processPid, - processGroupId: input.processGroupId, - }, - }; -} - type SkillTestHeartbeatCompletion = { outcome: "failed" | "cancelled"; error: string | null; @@ -2458,6 +2259,49 @@ export function heartbeatService( applyRunDispatchPostCommitEffects, }); + const { + sweepPendingCleanupLeases, + markNativeOwnershipUnverified, + prepareHotRestartShutdown, + reconcileHotRestartAdoption, + recoverNativeRunsAfterRestart, + reapOrphanedRuns, + sweepOrphanedActiveLeases, + drainRunningRunsForShutdown, + } = createHeartbeatRecovery(db, { + enterShutdown: () => { shutdownInProgress = true; }, + scheduleBoundedRetryForRun, + appendRunEvent, + environmentRuntime, + scheduleNativeSessionResumeDispatch, + getRun, + executeRun, + activeRunExecutionPromises, + cancelHeartbeatNativeRun, + terminateHeartbeatRunProcess, + setRunStatusIfRunning, + mergeRunStopMetadataForAgent, + setWakeupStatus, + classifyAndPersistRunLiveness, + releaseEnvironmentLeasesForRun, + releaseIssueExecutionAndPromote, + finalizeAgentStatus, + timerClaimWasFirstHeartbeat, + environmentsSvc, + acknowledgeRemoteStop, + resumeRemoteStopComments, + setRunStatusFromLive, + instructionCopies, + dispatchPendingNativeStatusWakeups, + runtimeEnv, + cancelRunInternal, + activeRunExecutions, + setRunStatus, + getAgent, + scheduleInteractionContinuationInfrastructureRetryIfEligible, + startNextQueuedRunForAgent, + }); + // Applies the post-commit effects a run-dispatch operation returns, on a // best-effort basis, exactly as this service publishes them for every // other run write. A publish failure never rolls back the write that @@ -6027,885 +5871,6 @@ export function heartbeatService( return { outcome: "retry_exhausted" as const, queuedRun: null }; } - async function enqueueProcessLossRetry( - run: typeof heartbeatRuns.$inferSelect, - agent: typeof agents.$inferSelect, - now: Date, - ) { - // Completion deliveries own their durable bounded retry and reply identity. - // A second process-loss retry would compete for the same outbox input. - if (run.contextSnapshot?.wakeReason === CHAT_COMPLETION_WAKE_REASON && - Array.isArray(run.contextSnapshot?.chatCompletionDeliveryIds)) return null; - // Native sessions have their own fenced same-run controller. Legacy - // bootstrap recovery shares the durable delay and incident counter with - // transient retries; process loss must not open a second retry budget. - if (run.runtimeMode === "native" || await legacyExecutionNeedsReconciliationWithEvidence(db, run)) - return null; - const scheduled = await scheduleBoundedRetryForRun(run, agent, { now }); - return scheduled.outcome === "scheduled" ? scheduled.run : null; - } - - function toHotRestartIntentRun(input: { - run: typeof heartbeatRuns.$inferSelect; - adapterType: string; - }): HotRestartIntentRun { - const context = parseObject(input.run.contextSnapshot); - return { - runId: input.run.id, - companyId: input.run.companyId, - agentId: input.run.agentId, - adapterType: input.adapterType, - status: input.run.status, - processPid: input.run.processPid ?? null, - processGroupId: input.run.processGroupId ?? null, - issueId: readNonEmptyString(context.issueId), - runtimeMode: input.run.runtimeMode, - nativeSessionId: input.run.nativeSessionId, - runnerInstanceId: input.run.runnerInstanceId, - processStartedAt: input.run.processStartedAt?.toISOString() ?? null, - }; - } - - function isServerStdioBoundHotRestartRun(input: { - run: typeof heartbeatRuns.$inferSelect; - adapterType: string; - adapterConfig: unknown; - }) { - const context = parseObject(input.run.contextSnapshot); - if ( - context.processTopology === "server_stdio" || - context.executionEngine === "acp" - ) { - return true; - } - if ( - context.processTopology === "detached" || - context.executionEngine === "cli" - ) { - return false; - } - if ( - !["claude_local", "codex_local", "gemini_local"].includes( - input.adapterType, - ) - ) { - return false; - } - return ( - readNonEmptyString(parseObject(input.adapterConfig).engine) !== "cli" - ); - } - - async function prepareHotRestartShutdown( - signal: "SIGINT" | "SIGTERM", - now = new Date(), - ) { - shutdownInProgress = true; - const idleSessions = await closeIdleWarmNativeSessionsForRestart(); - if (idleSessions.failed > 0) { - logger.warn({ idleSessions }, "idle native sessions could not checkpoint before controller shutdown"); - } - let intent: Awaited>; - try { - intent = await readHotRestartIntent(); - } catch (err) { - logger.warn( - { err }, - "failed to read hot-restart intent; falling back to normal shutdown drain", - ); - return { - mode: "read_error" as const, - skipDrain: false as const, - activeRunIds: [] as string[], - }; - } - - if (!intent) - return { - mode: "not_requested" as const, - skipDrain: false as const, - activeRunIds: [] as string[], - }; - if (intent.drainRequired) - return { - mode: "drain_required" as const, - skipDrain: false as const, - activeRunIds: [] as string[], - }; - if (!shouldHonorHotRestartIntentForProcess(intent)) { - logger.warn( - { expectedPid: intent.previousServerPid, currentPid: process.pid }, - "hot-restart intent targets a different server pid; falling back to normal shutdown drain", - ); - return { - mode: "pid_mismatch" as const, - skipDrain: false as const, - activeRunIds: [] as string[], - }; - } - - const activeRuns = await db - .select({ - run: heartbeatRuns, - adapterType: agents.adapterType, - adapterConfig: agents.adapterConfig, - }) - .from(heartbeatRuns) - .innerJoin(agents, eq(heartbeatRuns.agentId, agents.id)) - .where(eq(heartbeatRuns.status, "running")); - const snapshotRuns = activeRuns.map(toHotRestartIntentRun); - const intentWithVersion = { - ...intent, - previousServerVersion: intent.previousServerVersion ?? serverVersion, - }; - - const serverStdioRuns = activeRuns.filter(isServerStdioBoundHotRestartRun); - if (serverStdioRuns.length > 0) { - const activeServerStdioRunIds = serverStdioRuns.map(({ run }) => run.id); - await writeHotRestartShutdownSnapshot({ - intent: intentWithVersion, - signal, - activeRuns: snapshotRuns, - drainReason: "active_acp_run", - drainRunIds: activeServerStdioRunIds, - capturedAt: now, - }); - - logger.warn( - { - signal, - previousServerPid: intent.previousServerPid, - activeRunIds: snapshotRuns.map((run) => run.runId), - activeServerStdioRunIds, - drainReason: "active_acp_run", - }, - "server-stdio agent run prevents hot-restart adoption; using graceful drain and retry", - ); - - return { - mode: "acp_drain_required" as const, - skipDrain: false as const, - activeRunIds: snapshotRuns.map((run) => run.runId), - activeAcpRunIds: activeServerStdioRunIds, - drainRunIds: activeServerStdioRunIds, - drainReason: "active_acp_run" as const, - }; - } - - await writeHotRestartShutdownSnapshot({ - intent: intentWithVersion, - signal, - activeRuns: snapshotRuns, - capturedAt: now, - }); - - for (const { run } of activeRuns) { - await appendRunEvent(run, { - eventType: "lifecycle", - stream: "system", - level: "info", - message: - "Hot restart requested; leaving child process alive for startup adoption", - payload: { - signal, - previousServerPid: intent.previousServerPid, - previousServerVersion: intentWithVersion.previousServerVersion, - processPid: run.processPid ?? null, - processGroupId: run.processGroupId ?? null, - }, - }); - } - - const nativeRunIds = activeRuns - .filter( - ({ run, adapterType }) => - adapterType === "paperclip_runner" && - isNativeSessionId(run.nativeSessionId), - ) - .map(({ run }) => run.id); - const detachedNativeSessions = - await detachNativeSessionsForRestart(nativeRunIds); - - logger.info( - { - signal, - previousServerPid: intent.previousServerPid, - activeRunIds: snapshotRuns.map((run) => run.runId), - detachedNativeSessions, - }, - "hot-restart shutdown snapshot captured; skipping graceful run drain", - ); - - return { - mode: "hot_restart" as const, - skipDrain: true as const, - activeRunIds: snapshotRuns.map((run) => run.runId), - }; - } - - async function reconcileHotRestartAdoption(now = new Date()) { - let intent: Awaited>; - try { - intent = await readHotRestartIntent(); - } catch (err) { - logger.warn( - { err }, - "failed to read hot-restart intent on startup; skipping adoption", - ); - return { - mode: "read_error" as const, - adoptedRunIds: [] as string[], - finalizedWhileDownRunIds: [] as string[], - lostRunIds: [] as string[], - skippedRunIds: [] as string[], - }; - } - if (!intent) { - return { - mode: "not_requested" as const, - adoptedRunIds: [] as string[], - finalizedWhileDownRunIds: [] as string[], - lostRunIds: [] as string[], - skippedRunIds: [] as string[], - }; - } - - if (!intent.shutdownSnapshot) { - const log = intent.drainRequired - ? logger.info.bind(logger) - : logger.warn.bind(logger); - log( - { - previousServerPid: intent.previousServerPid, - preflightActiveRunIds: intent.preflightActiveRunIds, - drainReason: intent.drainReason ?? null, - }, - intent.drainRequired - ? "drain-required restart intent has no adoption snapshot" - : "hot-restart intent present but shutdown snapshot is missing; no runs can be adopted", - ); - } - const candidates = intent.shutdownSnapshot?.activeRuns ?? []; - const missingSnapshotRunIds = findMissingHotRestartSnapshotRunIds(intent); - const reconciliationRunIds = [ - ...new Set([ - ...candidates.map((run) => run.runId), - ...missingSnapshotRunIds, - ]), - ]; - const currentRows = - reconciliationRunIds.length > 0 - ? await db - .select({ - run: heartbeatRuns, - adapterType: agents.adapterType, - }) - .from(heartbeatRuns) - .innerJoin(agents, eq(heartbeatRuns.agentId, agents.id)) - .where(inArray(heartbeatRuns.id, reconciliationRunIds)) - : []; - const currentByRunId = new Map(currentRows.map((row) => [row.run.id, row])); - - const reportRuns: HotRestartReportRun[] = []; - const adoptedRunIds: string[] = []; - const finalizedWhileDownRunIds: string[] = []; - const lostRunIds: string[] = []; - const skippedRunIds: string[] = []; - - const classify = ( - candidate: HotRestartIntentRun, - classification: HotRestartReportRun["classification"], - reason: string, - patch?: Partial, - ) => { - const run = { - ...candidate, - ...patch, - classification, - reason, - } satisfies HotRestartReportRun; - reportRuns.push(run); - if (classification === "adopted") adoptedRunIds.push(candidate.runId); - else if (classification === "finalized_while_down") - finalizedWhileDownRunIds.push(candidate.runId); - else if (classification === "lost") lostRunIds.push(candidate.runId); - else skippedRunIds.push(candidate.runId); - }; - - for (const runId of missingSnapshotRunIds) { - const current = currentByRunId.get(runId); - if (!current) { - finalizedWhileDownRunIds.push(runId); - continue; - } - - const candidate = toHotRestartIntentRun(current); - if (current.run.status !== "running") { - classify( - candidate, - "finalized_while_down", - `run_status_${current.run.status}`, - ); - } else { - classify(candidate, "lost", "missing_shutdown_snapshot"); - } - } - - if (lostRunIds.length > 0) { - logger.error( - { previousServerPid: intent.previousServerPid, lostRunIds }, - "hot-restart shutdown snapshot omitted live preflight runs; reporting them as lost", - ); - } - - for (const candidate of candidates) { - const current = currentByRunId.get(candidate.runId); - if (!current) { - classify(candidate, "finalized_while_down", "run_row_missing"); - continue; - } - - const { run, adapterType } = current; - const patch = { - adapterType, - status: run.status, - processPid: run.processPid ?? candidate.processPid, - processGroupId: run.processGroupId ?? candidate.processGroupId, - }; - - if (run.status !== "running") { - classify( - candidate, - "finalized_while_down", - `run_status_${run.status}`, - patch, - ); - continue; - } - - const hasSelectiveAcpDrain = - intent.drainReason === "active_acp_run" && - (intent.drainRunIds?.length ?? 0) > 0; - if ( - hasSelectiveAcpDrain && - intent.drainRunIds?.includes(candidate.runId) - ) { - // A selective ACP drain is expected to persist a terminal row before - // the new server starts. If the process was terminated but that write - // failed, surface the run as lost instead of hiding it as an expected - // drain skip. - classify(candidate, "lost", "selective_drain_not_finalized", patch); - continue; - } - if (intent.drainRequired && !hasSelectiveAcpDrain) { - classify(candidate, "skipped", "drain_required", patch); - continue; - } - - if (run.runtimeMode === "native" && adapterType === "paperclip_runner") { - classify(candidate, "skipped", "native_restart_recovery_owned", patch); - continue; - } - - if (!isTrackedLocalChildProcessAdapter(adapterType)) { - classify( - candidate, - "skipped", - "adapter_not_local_child_process", - patch, - ); - continue; - } - - const processPid = run.processPid ?? candidate.processPid; - const processGroupId = run.processGroupId ?? candidate.processGroupId; - const processPidAlive = isProcessAlive(processPid); - const processGroupAlive = isProcessGroupAlive(processGroupId); - if (!processPid && !processGroupId) { - classify(candidate, "lost", "missing_process_metadata", patch); - continue; - } - if (!processPidAlive && !processGroupAlive) { - classify(candidate, "lost", "process_not_alive", patch); - continue; - } - - const resultJson = mergeHotRestartAdoptionResultJson( - parseObject(run.resultJson), - { - adoptedAt: now, - previousServerPid: intent.previousServerPid, - newServerPid: process.pid, - previousServerVersion: intent.previousServerVersion, - newServerVersion: serverVersion, - processPid, - processGroupId, - }, - ); - const updated = await db - .update(heartbeatRuns) - .set({ - resultJson: preserveWorkspaceRestoreRecoveryMetadataSql(resultJson, true), - error: - run.errorCode === DETACHED_PROCESS_ERROR_CODE ? null : run.error, - errorCode: - run.errorCode === DETACHED_PROCESS_ERROR_CODE - ? null - : run.errorCode, - updatedAt: now, - }) - .where( - and( - eq(heartbeatRuns.id, run.id), - eq(heartbeatRuns.status, "running"), - ), - ) - .returning() - .then((rows) => rows[0] ?? null); - - if (!updated) { - const latest = await db - .select({ status: heartbeatRuns.status }) - .from(heartbeatRuns) - .where(eq(heartbeatRuns.id, run.id)) - .then((rows) => rows[0] ?? null); - if (latest && latest.status !== "running") { - classify( - candidate, - "finalized_while_down", - `run_status_${latest.status}`, - patch, - ); - } else { - classify(candidate, "lost", "adoption_update_not_applied", patch); - } - continue; - } - - await appendRunEvent(updated, { - eventType: "lifecycle", - stream: "system", - level: "info", - message: "Adopted live child process after hot restart", - payload: { - previousServerPid: intent.previousServerPid, - newServerPid: process.pid, - previousServerVersion: intent.previousServerVersion, - newServerVersion: serverVersion, - processPid, - processGroupId, - }, - }); - classify( - candidate, - "adopted", - processPidAlive ? "process_pid_alive" : "process_group_alive", - patch, - ); - } - - const report = await writeHotRestartReport({ - version: 1, - requestedAt: intent.requestedAt, - completedAt: now.toISOString(), - drainRequired: intent.drainRequired, - drainReason: - intent.drainReason ?? (intent.drainRequired ? "requested" : null), - previousServerPid: intent.previousServerPid, - newServerPid: process.pid, - previousServerVersion: intent.previousServerVersion, - newServerVersion: serverVersion, - adoptedRunIds, - finalizedWhileDownRunIds, - lostRunIds, - skippedRunIds, - runs: reportRuns, - }); - await removeHotRestartIntent(undefined, intent); - - logger.info( - { - previousServerPid: report.previousServerPid, - newServerPid: report.newServerPid, - adoptedRunIds, - finalizedWhileDownRunIds, - lostRunIds, - missingSnapshotRunIds, - skippedRunIds, - }, - "hot-restart adoption report written", - ); - - return { - mode: "reported" as const, - adoptedRunIds, - finalizedWhileDownRunIds, - lostRunIds, - skippedRunIds, - }; - } - - async function recoverNativeRunsAfterRestart(now = new Date()) { - // A result committed before the old controller stopped outranks process - // recovery. Finish its durable workspace/status suffix before deciding - // whether any provider authority needs to be reopened. - await reconcileNativeFinalizations(db, undefined, { - environmentRuntime, - onWorkspaceSettled: settleRecoveredNativeWorkspace, - }); - scheduleRetainedNativeSessionCleanup(); - const intent = await readHotRestartIntent().catch((error) => { - logger.warn( - { err: error }, - "failed to read hot-restart intent before native startup recovery", - ); - return null; - }); - const restartKind = intent ? ("hot" as const) : ("hard" as const); - const previousStartedAt = intent?.previousServerStartedAt - ? new Date(intent.previousServerStartedAt) - : null; - const scheduledNativeRetries = await db - .select({ - runId: nativeRunFinalizations.runId, - nextAttemptAt: nativeRunFinalizations.nextAttemptAt, - }) - .from(nativeRunFinalizations) - .innerJoin( - heartbeatRuns, - eq(heartbeatRuns.id, nativeRunFinalizations.runId), - ) - .where( - and( - eq(heartbeatRuns.runtimeMode, "native"), - inArray(heartbeatRuns.status, ["running", "failed"]), - isNull(nativeRunFinalizations.resultId), - eq(nativeRunFinalizations.phase, "retryable_failure"), - gt(nativeRunFinalizations.nextAttemptAt, now), - ), - ); - for (const scheduled of scheduledNativeRetries) { - if (scheduled.nextAttemptAt) { - scheduleNativeSessionResumeDispatch( - scheduled.runId, - scheduled.nextAttemptAt, - ); - } - } - const dispositions = await claimNativeRestartRecoveries({ - db, - restartKind, - recoveryRequestId: intent?.recoveryRequestId ?? null, - coordinatedPreviousController: intent - ? { - pid: intent.previousServerPid, - processStartedAt: - previousStartedAt && !Number.isNaN(previousStartedAt.getTime()) - ? previousStartedAt - : null, - } - : null, - now, - }); - - const claims = dispositions.filter( - (disposition): disposition is NativeRestartRecoveryClaim => - disposition.kind === "reattach_existing_runner" || - disposition.kind === "reattach_remote_runner" || - disposition.kind === "resume_dead_runner" || - disposition.kind === "bootstrap_incomplete", - ); - for (const disposition of dispositions) { - const run = await getRun(disposition.runId); - if (run) { - const isClaim = - disposition.kind === "reattach_existing_runner" || - disposition.kind === "reattach_remote_runner" || - disposition.kind === "resume_dead_runner" || - disposition.kind === "bootstrap_incomplete"; - await appendRunEvent(run, { - eventType: "native.recovery.transition", - stream: "system", - level: disposition.kind === "blocked" ? "warn" : "info", - message: - disposition.kind === "reattach_existing_runner" || - disposition.kind === "reattach_remote_runner" - ? "Recovering the existing native runner process after server restart" - : disposition.kind === "resume_dead_runner" - ? "Resuming the durable native provider session after runner process loss" - : disposition.kind === "bootstrap_incomplete" - ? "Restarting an incomplete native runner bootstrap on the same heartbeat run" - : disposition.kind === "awaiting_evidence" - ? "Native restart recovery is waiting for safe ownership evidence" - : disposition.kind === "already_finalized" - ? "Native restart recovery found an already-finalized result" - : "Native restart recovery blocked ambiguous or conflicting ownership", - payload: { - restartKind: isClaim ? disposition.restartKind : restartKind, - recoveryRequestId: isClaim - ? disposition.recoveryRequestId - : (intent?.recoveryRequestId ?? null), - runnerDisposition: disposition.kind, - ...(isClaim - ? { - controllerGeneration: disposition.controllerGeneration, - providerAttempt: disposition.providerAttempt, - } - : { reason: disposition.reason }), - ...(disposition.kind === "reattach_existing_runner" - ? { - processPid: disposition.process.pid, - processGroupId: disposition.process.processGroupId, - processStartedAt: disposition.process.startedAt, - } - : {}), - }, - }); - } - } - for (const claim of claims) { - const execution = executeRun(claim.runId, { - nativeLeaseOwner: claim.leaseOwner, - nativeRestartRecovery: claim, - }).catch((error) => { - logger.error( - { err: error, runId: claim.runId, disposition: claim.kind }, - "native restart recovery execution failed", - ); - }); - activeRunExecutionPromises.add(execution); - void execution.finally(() => - activeRunExecutionPromises.delete(execution), - ); - } - - return { - restartKind, - claims, - dispositions, - scheduledRetryRunIds: scheduledNativeRetries.map((entry) => entry.runId), - awaitingEvidenceRunIds: dispositions - .filter((entry) => entry.kind === "awaiting_evidence") - .map((entry) => entry.runId), - blockedRunIds: dispositions - .filter((entry) => entry.kind === "blocked") - .map((entry) => entry.runId), - }; - } - - async function drainRunningRunsForShutdown( - signal: "SIGINT" | "SIGTERM", - now = new Date(), - runIds: readonly string[] | null = null, - ) { - const selectedRunIds = runIds ? [...new Set(runIds)] : null; - if (selectedRunIds?.length === 0) { - return { - interrupted: 0, - interruptedRunIds: [], - retryRunIds: [], - restartSuspendedRunIds: [], - }; - } - const activeRuns = await db - .select({ - run: heartbeatRuns, - agent: agents, - }) - .from(heartbeatRuns) - .innerJoin(agents, eq(heartbeatRuns.agentId, agents.id)) - .where( - selectedRunIds - ? and( - eq(heartbeatRuns.status, "running"), - inArray(heartbeatRuns.id, selectedRunIds), - ) - : eq(heartbeatRuns.status, "running"), - ); - - const interruptedRunIds: string[] = []; - const retryRunIds: string[] = []; - const restartSuspendedRunIds: string[] = []; - - for (const { run, agent } of activeRuns) { - // Shutdown owns only this boot's legacy executions. Expired foreign - // owners belong to the reaper, not another container's drain. - if (run.runtimeMode === "legacy" && run.controllerBootId && - run.controllerBootId !== legacyControllerBootId) continue; - if (isNativeRunnerOwnershipHeld(run)) continue; - if ( - run.runtimeMode === "native" && - agent.adapterType === "paperclip_runner" - ) { - // A graceful shutdown relinquishes controller authority just like a - // hot restart. Leaving the old event consumer attached lets its - // finalizer interrupt/suspend Claude while the next server is adopting - // the same turn. - await detachNativeSessionsForRestart([run.id]); - const recoveryHistoryEntry = JSON.stringify({ - at: now.toISOString(), - restartKind: "graceful", - disposition: "restart_suspended", - reason: signal, - processPid: run.processPid, - processStartedAt: run.processStartedAt?.toISOString() ?? null, - }); - await db - .update(nativeRunFinalizations) - .set({ - recoveryState: "awaiting_runner_reattach", - recoveryHistory: sql`( - select coalesce(jsonb_agg(item order by ordinal), '[]'::jsonb) - from jsonb_array_elements( - coalesce(${nativeRunFinalizations.recoveryHistory}, '[]'::jsonb) - || jsonb_build_array(${recoveryHistoryEntry}::jsonb) - ) with ordinality as history(item, ordinal) - where ordinal > greatest( - jsonb_array_length( - coalesce(${nativeRunFinalizations.recoveryHistory}, '[]'::jsonb) - || jsonb_build_array(${recoveryHistoryEntry}::jsonb) - ) - 20, - 0 - ) - )`, - updatedAt: now, - }) - .where( - and( - eq(nativeRunFinalizations.runId, run.id), - isNull(nativeRunFinalizations.resultId), - ), - ); - await appendRunEvent(run, { - eventType: "native.recovery.transition", - stream: "system", - level: "info", - message: - "Server shutdown suspended native controller ownership without cancelling provider work", - payload: { - restartKind: "graceful", - signal, - runnerDisposition: "awaiting_runner_reattach", - processPid: run.processPid, - processGroupId: run.processGroupId, - processStartedAt: run.processStartedAt?.toISOString() ?? null, - retryRunCreated: false, - }, - }); - restartSuspendedRunIds.push(run.id); - continue; - } - const message = `Interrupted by graceful server shutdown (${signal})`; - const running = runningProcesses.get(run.id); - try { - if (run.runtimeMode === "native") { - await cancelHeartbeatNativeRun({ - db, - runId: run.id, - reason: message, - runtimeMode: run.runtimeMode, - }); - } - if (running) { - await terminateHeartbeatRunProcess({ - pid: running.child.pid, - processGroupId: running.processGroupId, - graceMs: Math.max(1, running.graceSec) * 1000, - }); - } - } finally { - runningProcesses.delete(run.id); - } - - const persistedCancellationResult = - run.runtimeMode === "native" - ? await getRun(run.id).then((current) => - parseObject(current?.resultJson), - ) - : parseObject(run.resultJson); - - const interruptedStatus = await setRunStatusIfRunning( - run.id, - "interrupted", - { - finishedAt: now, - error: message, - errorCode: "server_shutdown_interrupted", - signal, - resultJson: mergeRunStopMetadataForAgent(agent, "interrupted", { - conversationContinuationEligible: await runUsedConversationAdapter(db, run), - resultJson: persistedCancellationResult, - errorCode: "server_shutdown_interrupted", - errorMessage: message, - }), - }, - ); - if (!interruptedStatus.updated || !interruptedStatus.run) continue; - let interrupted = interruptedStatus.run; - await setWakeupStatus(run.wakeupRequestId, "cancelled", { - finishedAt: now, - error: null, - }); - interrupted = - (await classifyAndPersistRunLiveness( - interrupted, - parseObject(interrupted.resultJson), - )) ?? interrupted; - - await releaseEnvironmentLeasesForRun({ - runId: interrupted.id, - companyId: interrupted.companyId, - agentId: interrupted.agentId, - status: interrupted.status, - failureReason: interrupted.error ?? undefined, - }); - - const retry = await enqueueProcessLossRetry(interrupted, agent, now); - if (!retry) { - await releaseIssueExecutionAndPromote(interrupted); - } else { - retryRunIds.push(retry.id); - } - - await appendRunEvent(interrupted, { - eventType: "lifecycle", - stream: "system", - level: "warn", - message, - payload: { - signal, - ...(run.processPid ? { processPid: run.processPid } : {}), - ...(run.processGroupId ? { processGroupId: run.processGroupId } : {}), - ...(retry ? { retryRunId: retry.id } : {}), - }, - }); - - await finalizeAgentStatus(run.agentId, "interrupted", message, { - wasFirstHeartbeat: timerClaimWasFirstHeartbeat(run), - }); - interruptedRunIds.push(interrupted.id); - } - - if (interruptedRunIds.length > 0) { - logger.warn( - { - signal, - interrupted: interruptedRunIds.length, - interruptedRunIds, - retryRunIds, - }, - "interrupted running heartbeat runs for graceful shutdown", - ); - } - - return { - interrupted: interruptedRunIds.length, - interruptedRunIds, - retryRunIds, - restartSuspendedRunIds, - }; - } - function parseHeartbeatPolicy(agent: typeof agents.$inferSelect) { const runtimeConfig = parseObject(agent.runtimeConfig); const heartbeat = parseObject(runtimeConfig.heartbeat); @@ -8604,1152 +7569,6 @@ export function heartbeatService( .then((rows) => rows[0] ?? null); } - // Clamp the stored attempt count to the range [0, cap]. The SQL reader - // `pendingCleanupAttemptsSql` clamps to the same range, so both readers yield - // the same value for every input. The claim predicate compares the two values, - // so this alignment lets the claim match for a malformed lease. - function readPendingCleanupRetryAttempts( - metadata: Record, - ): number { - const value = metadata[PENDING_CLEANUP_ATTEMPTS_METADATA_KEY]; - if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) - return 0; - return Math.min(Math.floor(value), PENDING_CLEANUP_SWEEP_ATTEMPT_CAP); - } - - // Atomically claim one retry attempt on a pending_cleanup lease. The update - // only matches when the lease is still pending_cleanup and its stored attempt - // count still equals `expectedAttempts`. Two concurrent sweeps read the same - // count, but Postgres serializes the two updates on the row and only the first - // matches the guard. The loser gets zero rows and skips the lease. The persisted in-flight deadline also prevents a later tick - // from starting another attempt while this one is still running. - // Returns the attempt identity only for the sweep that won the claim. - // - // The update patches cleanup ownership fields without writing a copied - // metadata object, so a concurrent write to an unrelated metadata key - // survives. The guard reads the stored count through the safe SQL reader, so a - // malformed value never throws. - async function claimPendingCleanupRetryAttempt( - leaseId: string, - expectedAttempts: number, - manualAttempt?: { previousId: unknown }, - ): Promise { - const now = new Date(); - const attemptId = randomUUID(); - const claimed = await db - .update(environmentLeases) - .set({ - metadata: sql`jsonb_set(${pendingCleanupMetadataObjectSql()}, array[${PENDING_CLEANUP_ATTEMPTS_METADATA_KEY}], to_jsonb(${expectedAttempts + 1}::int), true) - || ${JSON.stringify({ ...(manualAttempt ? { pendingCleanupManualAttemptId: randomUUID() } : {}), - pendingCleanupAttemptId: attemptId, pendingCleanupInFlight: true, - pendingCleanupLeaseExpiresAtMs: Date.now() + 15 * 60_000, - })}::jsonb`, - lastUsedAt: now, - updatedAt: now, - }) - .where( - and( - eq(environmentLeases.id, leaseId), - eq(environmentLeases.status, "pending_cleanup"), - sql`${pendingCleanupAttemptsSql()} = ${expectedAttempts}`, - manualAttempt ? sql`coalesce(${environmentLeases.metadata}->'pendingCleanupManualAttemptId', 'null'::jsonb) is not distinct from ${JSON.stringify(manualAttempt.previousId ?? null)}::jsonb` : undefined, - pendingCleanupRetryDueSql(Boolean(manualAttempt)), - ), - ) - .returning({ id: environmentLeases.id }); - return claimed.length > 0 ? attemptId : null; - } - - // Atomically claim the one-time cap warning for a lease. The update only - // matches when the lease is still pending_cleanup, its stored attempt count is - // at or above the cap, and it has not yet carried the warned flag. Two - // concurrent sweeps that both reach the cap race here, but only one update - // sets the flag and returns a row. The loser skips the warning. This keeps the - // warning to one log line per lease. - // - // The status and cap predicates are the last line of defense. They stop a warn - // flag write to a lease that left pending_cleanup or dropped below the cap - // between the read and this claim. The update writes only the warned key with - // `jsonb_set`, so a concurrent write to an unrelated metadata key survives. - async function claimPendingCleanupCapWarning( - leaseId: string, - ): Promise { - const now = new Date(); - const claimed = await db - .update(environmentLeases) - .set({ - metadata: sql`jsonb_set(${pendingCleanupMetadataObjectSql()}, array[${PENDING_CLEANUP_CAP_WARNED_METADATA_KEY}], to_jsonb(true), true)`, - updatedAt: now, - }) - .where( - and( - eq(environmentLeases.id, leaseId), - eq(environmentLeases.status, "pending_cleanup"), - sql`${pendingCleanupAttemptsSql()} >= ${PENDING_CLEANUP_SWEEP_ATTEMPT_CAP}`, - sql`${pendingCleanupCapWarnedSql()} = false`, - ), - ) - .returning({ id: environmentLeases.id }); - return claimed.length > 0; - } - - // Defer a pending_cleanup lease whose provider plugin is not ready this tick. - // The sweep reads one page of the oldest rows, ordered by `updatedAt`. A lease - // that the sweep only skips keeps its old `updatedAt`, so it stays the oldest - // and refills the page on every tick. That starves a newer lease whose - // provider is ready. The defer bumps `updatedAt` to now, so the unavailable - // lease moves to the back of the queue and a ready lease takes its page slot. - // The defer never writes the attempt count, so a long provider outage never - // consumes a finite retry. The status guard keeps the write on a lease that is - // still pending_cleanup. - async function deferPendingCleanupLease(leaseId: string): Promise { - const now = new Date(); - await db - .update(environmentLeases) - .set({ updatedAt: now }) - .where( - and( - eq(environmentLeases.id, leaseId), - eq(environmentLeases.status, "pending_cleanup"), - ), - ); - } - - // Move a guarded orphan candidate to the back of the sweep order. The - // shared-resource guard below can skip a row on every tick as long as the - // other owner stays live, retained, or pending cleanup. The select orders - // by `updatedAt` ascending and takes only the oldest page, so an untouched - // skipped row keeps refilling that same page and blocks every row behind - // it. The bump pushes the row past the fixed-size page, so the next tick - // reaches the rows behind it. It costs the row one extra backoff wait, - // which is safe because the guard means a physical sandbox still exists. - async function deferOrphanedActiveLease(leaseId: string): Promise { - const now = new Date(); - await db - .update(environmentLeases) - .set({ updatedAt: now }) - .where( - and( - eq(environmentLeases.id, leaseId), - eq(environmentLeases.status, "active"), - ), - ); - } - - // An active lease is reachable only while its heartbeat run keeps the - // running status. The reaper writes the run status and the lease release as - // two separate statements, so a restart between them can leave a terminal - // run and an active lease. `releaseRunLeases` also skips a lease whose - // environment row is gone, so that lease stays active too. No later query - // finds either lease, because every production query selects an active - // lease by its environment or by its heartbeat run id, never by age. This - // sweep finds both stranded classes and moves each lease to pending_cleanup, - // so the existing pending_cleanup sweep tears the sandbox down from the - // data already on the lease row. - async function sweepOrphanedActiveLeases(opts: { - backoffMs: number; - }): Promise<{ recovered: number }> { - const cutoff = new Date(Date.now() - opts.backoffMs); - - const rows = await db - .select({ lease: environmentLeases }) - .from(environmentLeases) - .leftJoin( - heartbeatRuns, - eq(environmentLeases.heartbeatRunId, heartbeatRuns.id), - ) - .where( - and( - eq(environmentLeases.status, "active"), - or( - isNull(environmentLeases.heartbeatRunId), - inArray(heartbeatRuns.status, [ - ...HEARTBEAT_RUN_TERMINAL_STATUSES, - ]), - ), - lte(environmentLeases.updatedAt, cutoff), - ), - ) - .orderBy(asc(environmentLeases.updatedAt)) - .limit(ORPHANED_ACTIVE_LEASE_SWEEP_PAGE_SIZE); - - let recovered = 0; - for (const { lease } of rows) { - // A provider resource id names one physical sandbox. A different lease - // row can still hold that same resource in a live status, so this sweep - // must not tear down a sandbox that a different lease still owns. - if (lease.provider && lease.providerLeaseId) { - const [otherOwner] = await db - .select({ id: environmentLeases.id }) - .from(environmentLeases) - .where( - and( - ne(environmentLeases.id, lease.id), - eq(environmentLeases.provider, lease.provider), - eq(environmentLeases.providerLeaseId, lease.providerLeaseId), - inArray(environmentLeases.status, [ - "active", - "retained", - "pending_cleanup", - ]), - ), - ) - .limit(1); - if (otherOwner) { - // Defer this row so the fixed-size page reaches the rows behind - // it next tick, instead of re-selecting the same guarded rows - // forever. - await deferOrphanedActiveLease(lease.id); - continue; - } - } - - // Keep the row's existing updatedAt value. The select above already - // proved the row is older than the backoff cutoff, so the - // pending_cleanup sweep can accept the same row in this same tick. A - // fresh timestamp here would push the row inside that sweep's own - // backoff window and delay the teardown by one full tick. - const flipped = await db - .update(environmentLeases) - .set({ - status: "pending_cleanup", - failureReason: "orphaned_active_lease_recovered", - }) - .where( - and( - eq(environmentLeases.id, lease.id), - eq(environmentLeases.status, "active"), - ), - ) - .returning({ id: environmentLeases.id }); - if (flipped.length > 0) recovered += 1; - } - - return { recovered }; - } - - // Retry the leases stranded in "pending_cleanup". A failed destroy leaves a - // lease in that state forever without this sweep. The reaper tick runs the - // sweep. The backoff equals the reaper staleness threshold, so a lease waits - // for that period between attempts. The sweep reads and writes the attempt - // count in the lease metadata. It warns once when a lease reaches the attempt - // threshold, then continues with slower retries. Live attempts renew their - // cleanup claim; after controller loss, exact-resource destruction may repeat. - async function sweepPendingCleanupLeases(opts?: { - backoffMs?: number; - /** One cleanup attempt per explicit user Retry, for this failed run only. - * A later user Retry may bypass the cooldown after a provider failure, - * but cannot take over an in-flight cleanup attempt. - */ - explicitRetry?: { companyId: string; runId: string; actorId: string; reason?: "retry_failed_run" | "queued_comment_interrupt" }; - }): Promise<{ - swept: number; - destroyed: number; - capped: number; - }> { - const backoffMs = opts?.backoffMs ?? 0; - const now = new Date(); - const cutoff = new Date(now.getTime() - backoffMs); - - // Flush the in-process orphan-cleanup buffer first. A failed acquire buffers - // an orphan there when every synchronous pending-cleanup write failed after a - // failed teardown. The flush re-inserts each buffered record, so a durable - // `pending_cleanup` row lands once the database recovers. The flush runs - // before the read below, so this same tick tears down a freshly-landed row. - try { - const flushed = opts?.explicitRetry ? null : await environmentRuntime.flushDeferredOrphanCleanups?.(); - if (flushed && (flushed.recovered > 0 || flushed.pending > 0)) { - logger.info( - { recovered: flushed.recovered, pending: flushed.pending }, - "flushed the in-process orphan sandbox cleanup buffer to the database", - ); - } - } catch { - // A flush failure never stops the sweep. The buffer keeps the orphan for a - // later tick, and the database rows below still need this sweep. The caught - // exception never enters the log, because a write error can carry a - // credential in its message, code, cause, or stack. - logger.warn( - "orphan sandbox cleanup buffer flush failed; the sweep continues", - ); - } - - const rows = await db - .select() - .from(environmentLeases) - .where( - and( - eq(environmentLeases.status, "pending_cleanup"), - opts?.explicitRetry ? eq(environmentLeases.companyId, opts.explicitRetry.companyId) : undefined, - opts?.explicitRetry ? eq(environmentLeases.heartbeatRunId, opts.explicitRetry.runId) : undefined, - pendingCleanupRetryDueSql(Boolean(opts?.explicitRetry)), - backoffMs > 0 ? lte(environmentLeases.updatedAt, cutoff) : undefined, - ), - ) - .orderBy(asc(environmentLeases.updatedAt)) - .limit(PENDING_CLEANUP_SWEEP_PAGE_SIZE); - - let destroyed = 0; - let capped = 0; - for (const row of rows) { - if (pendingCleanupAttemptsInFlight.has(row.id)) continue; - const metadata = { ...(row.metadata ?? {}) } as Record; - const attempts = readPendingCleanupRetryAttempts(metadata); - - const environment = row.environmentId - ? await environmentsSvc.getById(row.environmentId) - : null; - const lease = await environmentsSvc.getLeaseById(row.id); - if (!lease) continue; - - // An orphan ephemeral lease keeps its provider, its provider lease id, and - // its sandbox config in the lease row. A failed acquire records it, and its - // environment row may be gone or foreign-bound. A reuse_by_environment lease - // whose environment a delete removed keeps the same recorded data, because - // the schema sets the environment reference to null on delete and preserves - // the row. Both leases tear down from the recorded lease data through - // `retryPendingSandboxTeardown`, which never reads the environment row. So - // the sweep uses that path whenever the lease is an orphan ephemeral lease - // or its environment row is gone. A reuse_by_environment lease whose - // environment still exists tears down through `destroyRunLease`. That - // path uses the provider and configuration recorded on the lease first; - // the environment is lifecycle context and only a legacy fallback. - const isOrphanEphemeralLease = lease.leasePolicy === "ephemeral"; - const useRecordedTeardown = isOrphanEphemeralLease || !environment || hasStopOnlyCleanup(lease); - - // Do not consume a finite cleanup attempt while the provider plugin is - // briefly unavailable. A plugin worker restart, a plugin reload, or a - // plugin reinstall makes the provider unavailable for a short window. The - // plugin can be missing or not ready in that window. A teardown then throws, - // and the atomic claim below would count that throw against the cap, so a - // long restart or reload could exhaust the retries and strand a live - // sandbox. So probe the provider first, and defer the lease this tick when - // the provider is not ready. The sweep preserves the pending_cleanup row, - // and a later sweep retries after the provider recovers. The probe reports - // ready only for a permanent condition (a missing provider string, a - // built-in provider, or no worker manager), so a genuine teardown failure - // still runs, throws, and counts toward the cap. A runtime with no probe - // method treats the lease as ready, so the sweep keeps its earlier - // behavior. - const workerReady = environmentRuntime.isPendingCleanupWorkerReady - ? await environmentRuntime.isPendingCleanupWorkerReady({ - environment, - lease, - }) - : true; - if (!workerReady) { - // Move the unavailable lease to the back of the sweep queue. Otherwise - // the oldest unavailable rows refill the page on every tick and starve a - // newer lease that has a ready provider. The defer bumps `updatedAt` - // only, so it consumes no finite retry attempt. - await deferPendingCleanupLease(row.id); - continue; - } - - // Atomically claim the attempt before the retry. Only the winning sweep - // increments the count and tears the sandbox down, so an overlapping sweep - // cannot start another attempt while this one holds the cleanup lease. - // The deadline survives a server restart; the counter saturates at the - // escalation threshold while attempt identities remain unique. - const claimed = await claimPendingCleanupRetryAttempt(row.id, attempts, - opts?.explicitRetry ? { previousId: metadata.pendingCleanupManualAttemptId } : undefined); - if (!claimed) continue; - pendingCleanupAttemptsInFlight.add(row.id); - lease.metadata = { ...lease.metadata, pendingCleanupAttemptId: claimed }; - let activeRenewal: Promise | null = null; - const renewal = setInterval(() => { - if (activeRenewal) return; - activeRenewal = db.update(environmentLeases).set({ - metadata: sql`jsonb_set(${pendingCleanupMetadataObjectSql()}, '{pendingCleanupLeaseExpiresAtMs}', to_jsonb(${Date.now() + 15 * 60_000}::bigint))`, - }).where(and(eq(environmentLeases.id, row.id), eq(environmentLeases.status, "pending_cleanup"), - sql`${environmentLeases.metadata}->>'pendingCleanupAttemptId' = ${claimed}`, - sql`${environmentLeases.metadata}->>'pendingCleanupInFlight' = 'true'`)) - .then(() => {}) - .catch(() => logger.warn({ leaseId: row.id }, "cleanup ownership renewal failed")) - .finally(() => { activeRenewal = null; }); - }, 30_000); - renewal.unref(); - - try { - if (opts?.explicitRetry) await logActivity(db, { - companyId: row.companyId, actorType: "user", actorId: opts.explicitRetry.actorId, - action: "environment_lease.cleanup_retried", entityType: "environment_lease", entityId: row.id, - runId: opts.explicitRetry.runId, details: { attempt: attempts + 1, reason: opts.explicitRetry.reason ?? "retry_failed_run" }, - }); - if (useRecordedTeardown) { - // Tear the sandbox down from the recorded provider config and the - // cleanup-authorized secret versions. Preserve any provider receipt; - // a completed retry must grant the same evidence as initial cleanup. - const receipt = await environmentRuntime.retryPendingSandboxTeardown({ - environment, - lease, - }); - const released = hasStopOnlyCleanup(lease) - ? await settleStopOnlyCleanup(db, lease, { attemptId: claimed, receipt }) - : await environmentsSvc.releaseLease(lease.id, "expired", { - expectedPendingCleanupAttemptId: claimed, - cleanupStatus: "success", - failureReason: "pending_cleanup_retry", - remoteExecutionTermination: remoteTerminationReceipt(lease, receipt), - }); - if (released) destroyed += 1; - } else if (environment) { - const result = await environmentRuntime.destroyRunLease({ - environment, - lease, - failureReason: "pending_cleanup_retry", - }); - if (result && result.status !== "pending_cleanup") { - destroyed += 1; - } - } - } catch { - // The recorded-data teardown throws on failure, so revert the lease to - // pending_cleanup for a later sweep. The claimed attempt still counts - // for backoff, so requests stay bounded. The `destroyRunLease` - // path reverts the lease itself, so this revert only runs for the - // recorded-data teardown path. - if (useRecordedTeardown) { - await environmentsSvc.releaseLease(lease.id, "pending_cleanup", { - expectedPendingCleanupAttemptId: claimed, - cleanupStatus: "failed", - failureReason: "pending_cleanup_retry", - }); - } - // Log a constant errorKind only. The exception can carry a credential in - // its name, code, message, cause, or stack, so the sweep never reads it. - logger.warn( - { - errorKind: PENDING_CLEANUP_RETRY_ERROR_KIND, - leaseId: row.id, - environmentId: row.environmentId, - attempts: attempts + 1, - }, - "pending_cleanup lease retry failed", - ); - } finally { - clearInterval(renewal); - // A hung renewal must not retain process-local cleanup ownership. - // Late renewals are attempt-fenced and never write the retry cooldown. - pendingCleanupAttemptsInFlight.delete(row.id); - } - if (attempts + 1 >= PENDING_CLEANUP_SWEEP_ATTEMPT_CAP) { - capped += 1; - // Warn once, then continue automatic cleanup with backoff. The atomic claim - // keeps the warning to one log line even when two sweeps overlap. - if (metadata[PENDING_CLEANUP_CAP_WARNED_METADATA_KEY] !== true) { - const warned = await claimPendingCleanupCapWarning(row.id); - if (warned) { - logger.warn( - { leaseId: row.id, environmentId: row.environmentId, attempts }, - "environment lease needs operator attention; automatic cleanup continues with backoff", - ); - } - } - } - // Persist the cooldown independently of process memory. A crash before - // this write leaves the bounded in-flight lease for a later sweep. - await db.update(environmentLeases).set({ - metadata: sql`${pendingCleanupMetadataObjectSql()} || ${JSON.stringify({ - pendingCleanupInFlight: false, - pendingCleanupRetryAfterMs: Date.now() + (attempts + 1 >= PENDING_CLEANUP_SWEEP_ATTEMPT_CAP - ? 30 * 60_000 : Math.min(30 * 60_000, Math.max(30_000, backoffMs))), - })}::jsonb`, - }).where(and(eq(environmentLeases.id, lease.id), - sql`${environmentLeases.metadata}->>'pendingCleanupAttemptId' = ${claimed}`)); - if (lease.heartbeatRunId) { - // Delivery failure must not revert successful provider cleanup. A new - // message can still use the persisted receipt on its next admission. - await (async () => { - await acknowledgeRemoteStop(lease.heartbeatRunId!, lease.companyId); - const run = await getRun(lease.heartbeatRunId!); - if (run) await resumeRemoteStopComments(run); - })().catch(() => logger.warn({ leaseId: lease.id }, "could not reconsider messages after cleanup retry")); - } - } - - return { swept: rows.length, destroyed, capped }; - } - - async function markNativeOwnershipUnverified( - run: typeof heartbeatRuns.$inferSelect, - evidence: { - reason: - | "live_process_identifier" - | "observed_owner_unverified" - | "adopted_runner_authentication_timeout" - | "native_chat_workspace_scope_mismatch"; - processPidAlive?: boolean; - processGroupAlive?: boolean; - }, - ) { - const durableOwnershipHold = - evidence.reason === "adopted_runner_authentication_timeout" || - evidence.reason === "native_chat_workspace_scope_mismatch"; - if ( - run.errorCode === NATIVE_OWNERSHIP_UNVERIFIED_ERROR_CODE && - run.error === NATIVE_OWNERSHIP_UNVERIFIED_MESSAGE && - (!durableOwnershipHold || isNativeRunnerOwnershipHeld(run)) - ) - return run; - const blockedStatus = run.status === "failed" ? "failed" : "running"; - const blockedWrite = await setRunStatusFromLive( - run.id, - blockedStatus, - [blockedStatus], - { - error: NATIVE_OWNERSHIP_UNVERIFIED_MESSAGE, - errorCode: NATIVE_OWNERSHIP_UNVERIFIED_ERROR_CODE, - ...(durableOwnershipHold - ? { - nativePhase: "terminal_failure", - nativePhaseUpdatedAt: new Date(), - } - : {}), - }, - ); - if (!blockedWrite.updated || !blockedWrite.run) { - return blockedWrite.run ?? run; - } - const blocked = blockedWrite.run; - await appendRunEvent(blocked, { - eventType: "lifecycle", - stream: "system", - level: "warn", - message: NATIVE_OWNERSHIP_UNVERIFIED_MESSAGE, - payload: { - reason: evidence.reason, - ...(evidence.processPidAlive === true ? { processPidAlive: true } : {}), - ...(evidence.processGroupAlive === true - ? { processGroupAlive: true } - : {}), - }, - }); - return blocked; - } - - async function settleRecoveredNativeWorkspace(input: { - runId: string; - companyId: string; - agentId: string; - succeeded: boolean; - }) { - const settledRun = await getRun(input.runId); - const workspaceSyncReference = readNativeWorkspaceSyncReference( - parseObject(settledRun?.runnerProfileJson).nativeWorkspaceSync, - ); - await releaseEnvironmentLeasesForRun({ - runId: input.runId, - companyId: input.companyId, - agentId: input.agentId, - status: settledRun?.status, - failureReason: settledRun?.error ?? undefined, - providerResourceDisposition: input.succeeded && (!parseObject(settledRun?.resultJson).workspaceExportRetry || workspaceSyncReference?.resourceDisposition === "destroy") - ? (workspaceSyncReference?.resourceDisposition ?? "stop_and_retain") - : "stop_and_retain", - }); - await releaseRuntimeServicesForRun(input.runId).catch(() => undefined); - await finalizeAgentStatus( - input.agentId, - input.succeeded ? "succeeded" : "failed", - input.succeeded - ? null - : (settledRun?.error ?? "native_workspace_sync_out_failed"), - { - wasFirstHeartbeat: settledRun - ? timerClaimWasFirstHeartbeat(settledRun) - : undefined, - }, - ).catch(() => undefined); - } - - function scheduleRetainedNativeSessionCleanup() { - // The per-database sweep joins startup and periodic callers. One bounded - // control-only repair must not hold up unrelated provider ingress or the - // entire orphan reaper, but shutdown must still await its physical owner. - const cleanup = reconcileRetainedNativeSessionCleanups(db, { - cleanup: (input) => reconcileRetainedNativeSessionCleanup(db, input), - onError: (error, runId) => { - logger.warn( - { err: error, runId }, - "retained native session cleanup failed", - ); - }, - }) - .then(() => undefined) - .catch((error) => { - logger.warn({ err: error }, "retained native cleanup discovery failed"); - }) - // The bounded maintenance attempt may fail before an already-started - // database callback settles. Keep shutdown ownership until the original - // operations finish; their timeout cannot authorize closing the database. - .finally(() => drainRetainedRunnerdMaintenanceOperations()); - activeRunExecutionPromises.add(cleanup); - void cleanup.finally(() => activeRunExecutionPromises.delete(cleanup)); - } - - async function reapOrphanedRuns(opts?: { staleThresholdMs?: number }) { - const staleThresholdMs = opts?.staleThresholdMs ?? 0; - const now = new Date(); - // Recovery never launches a provider or infers stopped ownership from - // terminal status. Uncaptured local copies require durable stop evidence. - await instructionCopies.recoverStopped().catch(error => { - logger.warn({ err: error }, "failed to recover stopped instruction copies"); - }); - await instructionCopies.recoverCaptured().catch(error => { - logger.warn({ err: error }, "failed to retry captured instruction revisions"); - }); - - // Complete persisted native results before generic orphan recovery. The - // reconciler reads the durable workspace barrier and persisted runtime - // mode, never the current feature flag. - await reconcileNativeFinalizations(db, undefined, { - environmentRuntime, - onWorkspaceSettled: settleRecoveredNativeWorkspace, - }).catch((error) => { - logger.warn( - { err: error }, - "failed to reconcile persisted native finalizations before orphan reaping", - ); - }); - scheduleRetainedNativeSessionCleanup(); - await dispatchPendingNativeStatusWakeups().catch((error) => { - logger.warn( - { err: error }, - "failed to dispatch persisted native status wake intents before orphan reaping", - ); - }); - - // A retryable native run can retain process identifiers from the failed - // attempt. Inspect them before the recovery claim: a live identifier is - // unowned and blocks recovery, while identifiers that are all dead can be - // cleared with a compare-and-set so the explicit retryable failure becomes - // claimable in this same sweep. - const retryableNativeProcesses = await db - .select({ run: heartbeatRuns }) - .from(heartbeatRuns) - .innerJoin( - nativeRunFinalizations, - eq(nativeRunFinalizations.runId, heartbeatRuns.id), - ) - .where( - and( - inArray(heartbeatRuns.status, ["running", "failed"]), - eq(heartbeatRuns.runtimeMode, "native"), - eq(nativeRunFinalizations.phase, "retryable_failure"), - isNull(nativeRunFinalizations.resultId), - ), - ); - const claimableNativeRunIds = new Set(); - for (const { run } of retryableNativeProcesses) { - if (isNativeRunnerOwnershipHeld(run)) continue; - if (!run.processPid && !run.processGroupId) { - claimableNativeRunIds.add(run.id); - continue; - } - const processPidAlive = - !!run.processPid && isProcessAlive(run.processPid); - const processGroupAlive = - !!run.processGroupId && isProcessGroupAlive(run.processGroupId); - if (processPidAlive || processGroupAlive) { - await markNativeOwnershipUnverified(run, { - reason: "live_process_identifier", - processPidAlive, - processGroupAlive, - }); - continue; - } - const cleared = await db.transaction(async tx => { - const cleared = await tx - .update(heartbeatRuns) - .set({ - processPid: null, - processGroupId: null, - processStartedAt: null, - updatedAt: now, - }) - .where( - and( - eq(heartbeatRuns.id, run.id), - eq(heartbeatRuns.runtimeMode, "native"), - run.processPid === null - ? isNull(heartbeatRuns.processPid) - : eq(heartbeatRuns.processPid, run.processPid), - run.processGroupId === null - ? isNull(heartbeatRuns.processGroupId) - : eq(heartbeatRuns.processGroupId, run.processGroupId), - run.processStartedAt === null - ? isNull(heartbeatRuns.processStartedAt) - : eq(heartbeatRuns.processStartedAt, run.processStartedAt), - ), - ) - .returning({ id: heartbeatRuns.id }) - .then((rows) => rows[0] ?? null); - if (cleared) await recordNativeLocalProcessStop(tx as unknown as Db, run); - return cleared; - }); - if (cleared) claimableNativeRunIds.add(cleared.id); - } - - // An explicit result-less retryable failure resumes on the original run. - // The database lease is claimed before dispatch so concurrent service - // instances cannot open competing recoveries; executeRun receives the exact - // claimed owner. Expired `observed` ownership never enters this set. - const nativeResumeClaims = - claimableNativeRunIds.size === 0 - ? [] - : await dispatchNativeSessionResumptions({ - db, - runnerInstanceId: - runtimeEnv.PAPERCLIP_INSTANCE_ID?.trim() || "paperclip-heartbeat", - now, - runIds: [...claimableNativeRunIds], - dispatch: (claim) => { - const execution = executeRun(claim.runId, { - nativeLeaseOwner: claim.leaseOwner, - }).catch((error) => { - logger.error( - { err: error, runId: claim.runId }, - "persisted native session resume failed", - ); - }); - activeRunExecutionPromises.add(execution); - void execution.finally(() => - activeRunExecutionPromises.delete(execution), - ); - }, - }).catch((error) => { - logger.warn( - { err: error }, - "failed to claim persisted native session resumptions", - ); - return []; - }); - const resumedRunIds = new Set( - nativeResumeClaims.map((claim) => claim.runId), - ); - - // A terminal issue transition writes this intent in the same transaction - // that closes the question's task, even when its card is retained. Consume - // it before generic orphan recovery so a restart preserves cancellation. - const cancellationRequests = await db - .select({ - id: heartbeatRuns.id, - contextSnapshot: heartbeatRuns.contextSnapshot, - }) - .from(heartbeatRuns) - .where( - and( - inArray(heartbeatRuns.status, [ - ...CANCELLABLE_HEARTBEAT_RUN_STATUSES, - ]), - sql`${heartbeatRuns.contextSnapshot} -> ${NATIVE_QUESTION_CANCELLATION_CONTEXT_KEY} is not null`, - ), - ); - for (const request of cancellationRequests) { - const marker = parseObject( - parseObject(request.contextSnapshot)[ - NATIVE_QUESTION_CANCELLATION_CONTEXT_KEY - ], - ); - const issueId = readNonEmptyString(marker.issueId); - const issueStatus = readNonEmptyString(marker.issueStatus); - const interactionId = readNonEmptyString(marker.interactionId); - const kind = readNonEmptyString(marker.kind); - const reason = - kind === "interaction_withdrawn" - ? "Question withdrawn while waiting for operator input" - : kind === "interaction_cancelled" - ? "Cancelled while waiting for operator input" - : "Task closed while waiting for operator input"; - try { - await cancelRunInternal(request.id, reason, { - resultJson: { - ...(kind === "interaction_withdrawn" && interactionId - ? { withdrawnInteractionId: interactionId } - : {}), - ...(kind === "interaction_cancelled" && interactionId - ? { cancelledInteractionId: interactionId } - : {}), - ...((!kind || kind === "issue_terminal") && issueStatus - ? { cancelledByIssueStatus: issueStatus } - : {}), - ...(issueId ? { cancelledIssueId: issueId } : {}), - }, - }); - } catch (err) { - // Keep the marker intact for the next startup/periodic sweep. - logger.warn( - { err, runId: request.id }, - "native question cancellation recovery attempt failed", - ); - } - } - - // Find all runs stuck in "running" state (queued runs are legitimately waiting; resumeQueuedRuns handles them) - const activeRuns = await db - .select({ - run: heartbeatRuns, - adapterType: agents.adapterType, - adapterConfig: agents.adapterConfig, - nativeCoordinatorPhase: nativeRunFinalizations.phase, - nativeRecoveryState: nativeRunFinalizations.recoveryState, - nativeControllerBootId: nativeRunFinalizations.controllerBootId, - nativeControllerPid: nativeRunFinalizations.controllerPid, - nativeControllerProcessStartedAt: - nativeRunFinalizations.controllerProcessStartedAt, - nativeControllerLeaseExpiresAt: nativeRunFinalizations.leaseExpiresAt, - }) - .from(heartbeatRuns) - .innerJoin(agents, eq(heartbeatRuns.agentId, agents.id)) - .leftJoin( - nativeRunFinalizations, - eq(nativeRunFinalizations.runId, heartbeatRuns.id), - ) - .where(eq(heartbeatRuns.status, "running")); - - const monitorIssueIds = [ - ...new Set( - activeRuns.flatMap(({ run }) => { - const runContext = parseObject(run.contextSnapshot); - if (readNonEmptyString(runContext.wakeReason) !== "issue_monitor_due") - return []; - const issueId = readNonEmptyString(runContext.issueId); - return issueId ? [issueId] : []; - }), - ), - ]; - const monitorIssues = - monitorIssueIds.length > 0 - ? await db - .select({ - id: issues.id, - companyId: issues.companyId, - monitorNextCheckAt: issues.monitorNextCheckAt, - }) - .from(issues) - .where(inArray(issues.id, monitorIssueIds)) - : []; - const monitorNextCheckAtByIssue = new Map( - monitorIssues.map((issue) => [ - `${issue.companyId}:${issue.id}`, - issue.monitorNextCheckAt, - ]), - ); - - const reaped: string[] = []; - const currentNativeController = await currentNativeControllerIdentity(); - - for (const { - run, - adapterType, - adapterConfig, - nativeCoordinatorPhase, - nativeRecoveryState, - nativeControllerBootId, - nativeControllerPid, - nativeControllerProcessStartedAt, - nativeControllerLeaseExpiresAt, - } of activeRuns) { - // Authentication timeout requires an explicit ownership resolution, not - // repeated reattachment or a process-gone guess on subsequent sweeps. - if (isNativeRunnerOwnershipHeld(run)) continue; - const nativeRun = run.runtimeMode === "native"; - const nativeProcessPidAlive = - nativeRun && !!run.processPid && isProcessAlive(run.processPid); - const nativeProcessGroupAlive = - nativeRun && - !!run.processGroupId && - isProcessGroupAlive(run.processGroupId); - const coordinatorOwnedByCurrentController = - nativeRun && - nativeControllerBootId === currentNativeController.bootId && - nativeControllerPid === currentNativeController.pid && - nativeControllerProcessStartedAt?.getTime() === - currentNativeController.processStartedAt.getTime() && - !!nativeControllerLeaseExpiresAt && - nativeControllerLeaseExpiresAt.getTime() > now.getTime(); - const locallyTracked = - runningProcesses.has(run.id) || - activeRunExecutions.has(run.id) || - coordinatorOwnedByCurrentController; - if ( - nativeRun && - ([ - "awaiting_evidence", - "awaiting_runner_reattach", - "resuming_session", - "bootstrap_incomplete", - ].includes(nativeRecoveryState ?? "") || - nativeCoordinatorPhase === "retryable_failure") - ) { - continue; - } - const observedOwnerUnverified = - nativeRun && - (nativeCoordinatorPhase === "observed" || - (nativeCoordinatorPhase === null && - run.nativePhase === "observed")) && - !resumedRunIds.has(run.id) && - !locallyTracked; - // Persisted numeric process identifiers prove only that some process is - // alive, not that Paperclip still owns it. Likewise an observed native - // coordinator without a live in-process execution has no durable proof - // that its prior provider owner stopped. Keep both cases running but - // blocked: never signal, finalize, or retry them automatically. This gate - // intentionally precedes resumedRunIds so a claim cannot bypass the - // ownership check. - if ( - !locallyTracked && - (nativeProcessPidAlive || - nativeProcessGroupAlive || - observedOwnerUnverified) - ) { - await markNativeOwnershipUnverified(run, { - reason: - nativeProcessPidAlive || nativeProcessGroupAlive - ? "live_process_identifier" - : "observed_owner_unverified", - processPidAlive: nativeProcessPidAlive, - processGroupAlive: nativeProcessGroupAlive, - }); - continue; - } - if (resumedRunIds.has(run.id)) continue; - if (locallyTracked) continue; - if (await hasLiveLegacyController(db, run)) continue; - - // Apply staleness threshold to avoid false positives - if (staleThresholdMs > 0) { - const refTime = run.updatedAt ? new Date(run.updatedAt).getTime() : 0; - if (now.getTime() - refTime < staleThresholdMs) continue; - } - - const currentAdapterTracksLocalChild = - isTrackedLocalChildProcessAdapter(adapterType); - const tracksLegacyLocalChild = - run.runtimeMode !== "native" && currentAdapterTracksLocalChild; - // Native runner processes also persist child metadata, but they must not - // inherit legacy retry or termination authority. Use their PID/group only - // for a read-only liveness check so a lost in-memory handle cannot cause - // overlapping provider/tool execution while that child is still alive. - const checksPersistedChildLiveness = - currentAdapterTracksLocalChild || run.runtimeMode === "native"; - const processPidAlive = - checksPersistedChildLiveness && - run.processPid && - isProcessAlive(run.processPid); - const processGroupAlive = - checksPersistedChildLiveness && - run.processGroupId && - isProcessGroupAlive(run.processGroupId); - if ( - (processPidAlive || processGroupAlive) && - readHotRestartAdoptionMetadata(parseObject(run.resultJson)) - ) { - continue; - } - if (processPidAlive || processGroupAlive) { - if (run.errorCode !== DETACHED_PROCESS_ERROR_CODE) { - const detachedMessage = processPidAlive - ? `Lost in-memory process handle, but child pid ${run.processPid} is still alive` - : `Lost in-memory process handle, but persisted process group ${run.processGroupId} is still alive`; - const detachedRun = await setRunStatus(run.id, "running", { - error: detachedMessage, - errorCode: DETACHED_PROCESS_ERROR_CODE, - }); - if (detachedRun) { - await appendRunEvent(detachedRun, { - eventType: "lifecycle", - stream: "system", - level: "warn", - message: detachedMessage, - payload: { - processPid: run.processPid ?? null, - processGroupId: run.processGroupId ?? null, - ownedProcessHandle: false, - }, - }); - } - } - continue; - } - - const runContext = parseObject(run.contextSnapshot); - const monitorIssueId = readNonEmptyString(runContext.issueId); - const monitorNextCheckAt = monitorIssueId - ? monitorNextCheckAtByIssue.get(`${run.companyId}:${monitorIssueId}`) - : undefined; - const monitorDispatchLostWithoutFutureWake = - readNonEmptyString(runContext.wakeReason) === "issue_monitor_due" && - monitorNextCheckAt !== undefined && - (!monitorNextCheckAt || monitorNextCheckAt.getTime() <= now.getTime()); - const shouldRetry = - (run.processLossRetryCount ?? 0) < 1 && - ((tracksLegacyLocalChild && - (!!run.processPid || !!run.processGroupId)) || - monitorDispatchLostWithoutFutureWake); - if (!(await revokeExpiredLegacyController(db, run))) continue; - const baseMessage = buildProcessLossMessage(run); - const processLossDiagnostic = buildProcessLossDiagnostic({ - run, - nowMs: Date.now(), - observerStartedAtMs: performance.timeOrigin, - checksPersistedChildLiveness, - retryEligible: shouldRetry, - }); - const conversationContinuationEligible = await runUsedConversationAdapter(db, run); - - const failureWrite = await setRunStatusFromLive( - run.id, - "failed", - ["running"], - { - error: shouldRetry ? `${baseMessage}; retrying once` : baseMessage, - errorCode: "process_lost", - finishedAt: now, - resultJson: (() => { - const result = mergeRunStopMetadataForAgent( - { adapterType, adapterConfig }, - "failed", - { - conversationContinuationEligible, - resultJson: { ...parseObject(run.resultJson), processLossDiagnostic }, - errorCode: "process_lost", - errorMessage: shouldRetry - ? `${baseMessage}; retrying once` - : baseMessage, - }, - ); - return result; - })(), - }, - ); - if (!failureWrite.updated || !failureWrite.run) continue; - let finalizedRun: typeof heartbeatRuns.$inferSelect | null = - failureWrite.run; - await setWakeupStatus(run.wakeupRequestId, "failed", { - finishedAt: now, - error: shouldRetry ? `${baseMessage}; retrying once` : baseMessage, - }); - if (!finalizedRun) finalizedRun = await getRun(run.id); - if (!finalizedRun) continue; - finalizedRun = - (await classifyAndPersistRunLiveness( - finalizedRun, - parseObject(finalizedRun.resultJson), - )) ?? finalizedRun; - await releaseEnvironmentLeasesForRun({ - runId: finalizedRun.id, - companyId: finalizedRun.companyId, - agentId: finalizedRun.agentId, - status: finalizedRun.status, - failureReason: finalizedRun.error ?? undefined, - }); - - let retriedRun: typeof heartbeatRuns.$inferSelect | null = null; - const retryAgent = await getAgent(run.agentId); - if (shouldRetry) { - if (retryAgent) { - retriedRun = await enqueueProcessLossRetry( - finalizedRun, - retryAgent, - now, - ); - } - } else if (retryAgent) { - const scheduled = - await scheduleInteractionContinuationInfrastructureRetryIfEligible( - finalizedRun, - retryAgent, - ); - retriedRun = scheduled?.outcome === "scheduled" ? scheduled.run : null; - } - - if (!retriedRun) { - await releaseIssueExecutionAndPromote(finalizedRun); - } - - await appendRunEvent(finalizedRun, { - eventType: "lifecycle", - stream: "system", - level: "error", - message: shouldRetry - ? `${baseMessage}; queued retry ${retriedRun?.id ?? ""}`.trim() - : baseMessage, - payload: { - ...(run.processPid ? { processPid: run.processPid } : {}), - ...(run.processGroupId ? { processGroupId: run.processGroupId } : {}), - ...(retriedRun ? { retryRunId: retriedRun.id } : {}), - }, - }); - - await finalizeAgentStatus(run.agentId, "failed", baseMessage, { - wasFirstHeartbeat: timerClaimWasFirstHeartbeat(run), - }); - await startNextQueuedRunForAgent(run.agentId); - runningProcesses.delete(run.id); - reaped.push(run.id); - } - - if (reaped.length > 0) { - logger.warn( - { reapedCount: reaped.length, runIds: reaped }, - "reaped orphaned heartbeat runs", - ); - } - - // Recover an active lease whose run already ended before the same-tick - // pending_cleanup sweep, so this tick can stop the recovered sandbox. - // Isolate the sweep so its failure never hides the reaper result. - try { - const orphanedActiveLeaseSweep = await sweepOrphanedActiveLeases({ - backoffMs: staleThresholdMs, - }); - if (orphanedActiveLeaseSweep.recovered > 0) { - logger.warn( - { recovered: orphanedActiveLeaseSweep.recovered }, - "recovered orphaned active environment leases", - ); - } - } catch { - // Log a constant errorKind only. The exception can carry a credential in - // its name, code, message, cause, or stack, so the sweep never reads it. - logger.error( - { errorKind: ORPHANED_ACTIVE_LEASE_SWEEP_ERROR_KIND }, - "orphaned active environment lease sweep failed", - ); - } - - // Retry stranded pending_cleanup leases on the same tick. Isolate the sweep - // so its failure never hides the reaper result. The backoff equals the - // reaper staleness threshold. - try { - const sweep = await sweepPendingCleanupLeases({ - backoffMs: staleThresholdMs, - }); - if (sweep.destroyed > 0 || sweep.capped > 0) { - logger.warn( - { - destroyed: sweep.destroyed, - capped: sweep.capped, - swept: sweep.swept, - }, - "swept pending_cleanup environment leases", - ); - } - } catch { - // Log a constant errorKind only. The exception can carry a credential in - // its name, code, message, cause, or stack, so the sweep never reads it. - logger.error( - { errorKind: PENDING_CLEANUP_SWEEP_ERROR_KIND }, - "pending_cleanup lease sweep failed", - ); - } - - return { reaped: reaped.length, runIds: reaped }; - } - async function resumeQueuedRuns() { if ((await getSchedulingSuppression()).suppressed) return; await resumeExecutionWaitComments(); diff --git a/server/src/services/heartbeat/recovery.test.ts b/server/src/services/heartbeat/recovery.test.ts new file mode 100644 index 00000000000..a925edfaa79 --- /dev/null +++ b/server/src/services/heartbeat/recovery.test.ts @@ -0,0 +1,268 @@ +import { randomUUID } from "node:crypto"; +import type { Db } from "@paperclipai/db"; +import { agents, companies, createDb, EMBEDDED_POSTGRES_TEST_TIMEOUT_MS, heartbeatRuns, issues, nativeRunFinalizations } from "@paperclipai/db"; +import { eq } from "drizzle-orm"; +import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "../../__tests__/helpers/embedded-postgres.js"; +import { environmentRuntimeService } from "../environment-runtime.js"; +import { environmentService } from "../environments.js"; +import { createHeartbeatRecovery, type HeartbeatRecoveryDependencies } from "./recovery.js"; +import type { HotRestartIntent } from "../hot-restart.js"; +import type { NativeRestartRecoveryClaim, NativeRestartRecoveryDisposition } from "../native-runtime/index.js"; +import { NATIVE_OWNERSHIP_UNVERIFIED_ERROR_CODE } from "../native-runtime/native-runner-ownership.js"; + +type Run = typeof heartbeatRuns.$inferSelect; + +const native = vi.hoisted(() => ({ + closeIdle: vi.fn(async () => ({ closed: 0, failed: 0 })), + detach: vi.fn(async () => 0), + finalizations: vi.fn(async (_db: Db, _ids?: string[], _options?: unknown) => undefined), + cleanups: vi.fn(async () => undefined), + drainMaintenance: vi.fn<() => Promise>(async () => undefined), + claims: vi.fn<() => Promise>(async () => []), +})); +const hotRestart = vi.hoisted(() => ({ + read: vi.fn<() => Promise>(async () => null), +})); +vi.mock("../hot-restart.js", async (importOriginal) => ({ + ...await importOriginal(), + readHotRestartIntent: hotRestart.read, +})); +vi.mock("../native-runtime/index.js", async (importOriginal) => ({ + ...await importOriginal(), + closeIdleWarmNativeSessionsForRestart: native.closeIdle, + detachNativeSessionsForRestart: native.detach, + reconcileNativeFinalizations: native.finalizations, + reconcileRetainedNativeSessionCleanups: native.cleanups, + claimNativeRestartRecoveries: native.claims, +})); +vi.mock("../../vendor/paperclip-runner/index.js", async (importOriginal) => ({ + ...await importOriginal(), + drainRetainedRunnerdMaintenanceOperations: native.drainMaintenance, +})); + +function callbacks(db: Db) { + return { + enterShutdown: vi.fn(), + getRun: vi.fn(async () => null), + getAgent: vi.fn(async () => null), + appendRunEvent: vi.fn(async () => undefined), + setRunStatusIfRunning: vi.fn(async () => ({ updated: false, run: null })), + setRunStatusFromLive: vi.fn(async () => ({ updated: false, run: null })), + setRunStatus: vi.fn(async () => null), + setWakeupStatus: vi.fn(async () => undefined), + releaseIssueExecutionAndPromote: vi.fn(async () => undefined), + finalizeAgentStatus: vi.fn(async () => undefined), + environmentRuntime: environmentRuntimeService(db), + environmentsSvc: environmentService(db), + instructionCopies: { + recoverStopped: vi.fn(async () => 0), + recoverCaptured: vi.fn(async () => 0), + }, + runtimeEnv: {}, + activeRunExecutions: new Set(), + activeRunExecutionPromises: new Set>(), + scheduleBoundedRetryForRun: vi.fn(async () => ({ outcome: "retry_exhausted", retryReason: "transient_failure", attempt: 1, maxAttempts: 0 })), + scheduleInteractionContinuationInfrastructureRetryIfEligible: vi.fn(async () => null), + timerClaimWasFirstHeartbeat: vi.fn(() => undefined), + executeRun: vi.fn(async () => undefined), + scheduleNativeSessionResumeDispatch: vi.fn(), + cancelHeartbeatNativeRun: vi.fn(async () => undefined), + terminateHeartbeatRunProcess: vi.fn(async () => undefined), + mergeRunStopMetadataForAgent: vi.fn((_agent, _outcome, options) => options?.resultJson ?? null), + classifyAndPersistRunLiveness: vi.fn(async run => run), + releaseEnvironmentLeasesForRun: vi.fn(async () => undefined), + acknowledgeRemoteStop: vi.fn(async () => undefined), + resumeRemoteStopComments: vi.fn(async () => undefined), + dispatchPendingNativeStatusWakeups: vi.fn(async () => undefined), + cancelRunInternal: vi.fn(async () => undefined), + startNextQueuedRunForAgent: vi.fn(async () => undefined), + } satisfies HeartbeatRecoveryDependencies; +} + +function guardedDatabase() { + const access = vi.fn(() => { throw new Error("Unexpected recovery database access"); }); + return { db: new Proxy({}, { get: access }) as Db, access }; +} + +beforeEach(() => { + vi.clearAllMocks(); + hotRestart.read.mockResolvedValue(null); + native.closeIdle.mockResolvedValue({ closed: 0, failed: 0 }); + native.finalizations.mockResolvedValue(undefined); + native.cleanups.mockResolvedValue(undefined); + native.drainMaintenance.mockResolvedValue(undefined); + native.claims.mockResolvedValue([]); +}); + +describe("heartbeat recovery module callbacks", () => { + it("constructs without database access, shutdown, or background work", () => { + const database = guardedDatabase(); + const deps = callbacks(database.db); + createHeartbeatRecovery(database.db, deps); + expect(database.access).not.toHaveBeenCalled(); + for (const callback of Object.values(deps)) if (typeof callback === "function") expect(callback).not.toHaveBeenCalled(); + for (const callback of Object.values(native)) expect(callback).not.toHaveBeenCalled(); + }); + + it.each(["not_requested", "read_error"] as const)("enters shutdown before checkpointing for %s", async (mode) => { + const database = guardedDatabase(); + const deps = callbacks(database.db); + if (mode === "read_error") hotRestart.read.mockRejectedValueOnce(new Error("unreadable intent")); + const recovery = createHeartbeatRecovery(database.db, deps); + expect(await recovery.prepareHotRestartShutdown("SIGTERM")).toEqual({ mode, skipDrain: false, activeRunIds: [] }); + expect(native.closeIdle).toHaveBeenCalledAfter(deps.enterShutdown); + expect(hotRestart.read).toHaveBeenCalledAfter(native.closeIdle); + expect(database.access).not.toHaveBeenCalled(); + }); + + it("does not adopt or query runs without a restart intent", async () => { + const database = guardedDatabase(); + expect(await createHeartbeatRecovery(database.db, callbacks(database.db)).reconcileHotRestartAdoption()).toEqual({ + mode: "not_requested", adoptedRunIds: [], finalizedWhileDownRunIds: [], lostRunIds: [], skippedRunIds: [], + }); + expect(database.access).not.toHaveBeenCalled(); + }); + + it("does not broaden an empty selective shutdown drain to every run", async () => { + const database = guardedDatabase(); + const deps = callbacks(database.db); + expect(await createHeartbeatRecovery(database.db, deps).drainRunningRunsForShutdown("SIGINT", new Date(), [])).toEqual({ + interrupted: 0, interruptedRunIds: [], retryRunIds: [], restartSuspendedRunIds: [], + }); + expect(database.access).not.toHaveBeenCalled(); + expect(deps.cancelHeartbeatNativeRun).not.toHaveBeenCalled(); + expect(deps.terminateHeartbeatRunProcess).not.toHaveBeenCalled(); + }); + + it.each(["running", "failed"] as const)("keeps a %s ownership hold when a status race wins", async (status) => { + const database = guardedDatabase(); + const deps = callbacks(database.db); + const run = { id: "run", runtimeMode: "native", status } as Run; + const winner = { ...run, status: "cancelled" }; + deps.setRunStatusFromLive.mockResolvedValue({ updated: false, run: winner }); + expect(await createHeartbeatRecovery(database.db, deps).markNativeOwnershipUnverified(run, { reason: "live_process_identifier" })).toBe(winner); + expect(deps.setRunStatusFromLive).toHaveBeenCalledWith("run", status, [status], expect.objectContaining({ errorCode: NATIVE_OWNERSHIP_UNVERIFIED_ERROR_CODE })); + expect(deps.appendRunEvent).not.toHaveBeenCalled(); + expect(database.access).not.toHaveBeenCalled(); + }); + + it("persists an authentication ownership hold before its event without terminating or retrying", async () => { + const database = guardedDatabase(); + const deps = callbacks(database.db); + const run = { id: "run", runtimeMode: "native", status: "running" } as Run; + const blocked = { ...run, nativePhase: "terminal_failure", errorCode: NATIVE_OWNERSHIP_UNVERIFIED_ERROR_CODE }; + deps.setRunStatusFromLive.mockResolvedValue({ updated: true, run: blocked }); + expect(await createHeartbeatRecovery(database.db, deps).markNativeOwnershipUnverified(run, { reason: "adopted_runner_authentication_timeout" })).toBe(blocked); + expect(deps.setRunStatusFromLive).toHaveBeenCalledWith("run", "running", ["running"], expect.objectContaining({ nativePhase: "terminal_failure" })); + expect(deps.appendRunEvent).toHaveBeenCalledAfter(deps.setRunStatusFromLive); + expect(deps.cancelHeartbeatNativeRun).not.toHaveBeenCalled(); + expect(deps.terminateHeartbeatRunProcess).not.toHaveBeenCalled(); + expect(deps.scheduleBoundedRetryForRun).not.toHaveBeenCalled(); + expect(database.access).not.toHaveBeenCalled(); + }); +}); + +const support = await getEmbeddedPostgresTestSupport(); +const describePostgres = support.supported ? describe : describe.skip; +if (!support.supported) console.warn(`Skipping recovery module database tests: ${support.reason}`); + +describePostgres("heartbeat recovery module ownership", () => { + let db: Db; + let database: Awaited>; + beforeAll(async () => { + database = await startEmbeddedPostgresTestDatabase("paperclip-heartbeat-recovery-module-"); + db = createDb(database.connectionString); + }, EMBEDDED_POSTGRES_TEST_TIMEOUT_MS); + afterAll(async () => { await database?.cleanup(); }); + + async function seedRun() { + const companyId = randomUUID(), agentId = randomUUID(), runId = randomUUID(), issueId = randomUUID(); + await db.insert(companies).values({ id: companyId, name: "Recovery", issuePrefix: `T${companyId.slice(0, 6)}` }); + await db.insert(agents).values({ id: agentId, companyId, name: "Recovery", role: "engineer", adapterType: "process" }); + await db.insert(issues).values({ id: issueId, companyId, title: "Recover this run", status: "in_progress", assigneeAgentId: agentId }); + return (await db.insert(heartbeatRuns).values({ id: runId, companyId, agentId, issueId, invocationSource: "automation", status: "running", runtimeMode: "legacy" }).returning())[0]; + } + + it("uses the shared live-execution set after construction across two factories", async () => { + const run = await seedRun(); + const deps = callbacks(db); + const first = createHeartbeatRecovery(db, deps); + const second = createHeartbeatRecovery(db, deps); + deps.activeRunExecutions.add(run.id); + expect(await first.reapOrphanedRuns()).toEqual({ reaped: 0, runIds: [] }); + expect(await second.reapOrphanedRuns()).toEqual({ reaped: 0, runIds: [] }); + expect(deps.setRunStatusFromLive).not.toHaveBeenCalled(); + expect((await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, run.id)))[0].status).toBe("running"); + await Promise.all([...deps.activeRunExecutionPromises]); + await db.delete(heartbeatRuns).where(eq(heartbeatRuns.id, run.id)); + }); + + it("settles persisted native results before claiming restart authority and tracks the exact execution", async () => { + const deps = callbacks(db); + const claim: NativeRestartRecoveryClaim = { kind: "bootstrap_incomplete", runId: randomUUID(), leaseOwner: "claimed-owner", controllerGeneration: 3, providerAttempt: 2, restartKind: "hard", recoveryRequestId: null }; + native.claims.mockResolvedValue([claim]); + let finish!: () => void; + const execution = new Promise(resolve => { finish = resolve; }); + deps.executeRun.mockReturnValue(execution); + const result = await createHeartbeatRecovery(db, deps).recoverNativeRunsAfterRestart(); + expect(result.claims).toEqual([claim]); + expect(native.claims).toHaveBeenCalledAfter(native.finalizations); + expect(deps.executeRun).toHaveBeenCalledWith(claim.runId, { nativeLeaseOwner: claim.leaseOwner, nativeRestartRecovery: claim }); + expect(deps.activeRunExecutionPromises.size).toBeGreaterThan(0); + finish(); + await Promise.all([...deps.activeRunExecutionPromises]); + await vi.waitFor(() => expect(deps.activeRunExecutionPromises.size).toBe(0)); + }); + + it("does not claim or execute recovery when persisted finalization fails", async () => { + const deps = callbacks(db); + native.finalizations.mockRejectedValueOnce(new Error("result settlement failed")); + await expect(createHeartbeatRecovery(db, deps).recoverNativeRunsAfterRestart()).rejects.toThrow("result settlement failed"); + expect(native.claims).not.toHaveBeenCalled(); + expect(deps.executeRun).not.toHaveBeenCalled(); + expect(native.cleanups).not.toHaveBeenCalled(); + }); + + it("keeps blocked and ambiguous ownership out of execution", async () => { + const deps = callbacks(db); + const dispositions: NativeRestartRecoveryDisposition[] = [ + { kind: "blocked", runId: randomUUID(), reason: "conflicting_owner" }, + { kind: "awaiting_evidence", runId: randomUUID(), reason: "missing_stop_evidence" }, + ]; + native.claims.mockResolvedValue(dispositions); + const result = await createHeartbeatRecovery(db, deps).recoverNativeRunsAfterRestart(); + expect(result.blockedRunIds).toEqual([dispositions[0].runId]); + expect(result.awaitingEvidenceRunIds).toEqual([dispositions[1].runId]); + expect(result.claims).toEqual([]); + expect(deps.executeRun).not.toHaveBeenCalled(); + await Promise.all([...deps.activeRunExecutionPromises]); + }); + + it("rearms the persisted native retry deadline through the service callback", async () => { + const run = await seedRun(); + const nextAttemptAt = new Date(Date.now() + 60_000); + await db.update(heartbeatRuns).set({ runtimeMode: "native", nativeIssueId: run.issueId, status: "failed" }).where(eq(heartbeatRuns.id, run.id)); + await db.insert(nativeRunFinalizations).values({ runId: run.id, companyId: run.companyId, issueId: run.issueId!, phase: "retryable_failure", nextAttemptAt }); + const deps = callbacks(db); + const result = await createHeartbeatRecovery(db, deps).recoverNativeRunsAfterRestart(); + expect(result.scheduledRetryRunIds).toEqual([run.id]); + expect(deps.scheduleNativeSessionResumeDispatch).toHaveBeenCalledWith(run.id, nextAttemptAt); + expect(deps.executeRun).not.toHaveBeenCalled(); + await Promise.all([...deps.activeRunExecutionPromises]); + await db.delete(nativeRunFinalizations).where(eq(nativeRunFinalizations.runId, run.id)); + await db.delete(heartbeatRuns).where(eq(heartbeatRuns.id, run.id)); + }); + + it("retains shutdown ownership until background native cleanup physically settles", async () => { + const deps = callbacks(db); + let settle!: () => void; + native.drainMaintenance.mockReturnValueOnce(new Promise(resolve => { settle = resolve; })); + await createHeartbeatRecovery(db, deps).recoverNativeRunsAfterRestart(); + await vi.waitFor(() => expect(native.drainMaintenance).toHaveBeenCalled()); + expect(deps.activeRunExecutionPromises.size).toBe(1); + settle(); + await Promise.all([...deps.activeRunExecutionPromises]); + await vi.waitFor(() => expect(deps.activeRunExecutionPromises.size).toBe(0)); + }); +}); diff --git a/server/src/services/heartbeat/recovery.ts b/server/src/services/heartbeat/recovery.ts new file mode 100644 index 00000000000..4798251a1fd --- /dev/null +++ b/server/src/services/heartbeat/recovery.ts @@ -0,0 +1,2423 @@ +import { preserveWorkspaceRestoreRecoveryMetadataSql } from "../legacy-workspace-restore-recovery.js"; +import { CHAT_COMPLETION_WAKE_REASON } from "../chat-completion-delivery.js"; +import { + hasStopOnlyCleanup, + settleStopOnlyCleanup, +} from "../sandbox-stop-and-retain.js"; +import { recordNativeLocalProcessStop } from "../native-local-process-stop.js"; +import { + legacyControllerBootId, + hasLiveLegacyController, + revokeExpiredLegacyController, +} from "../legacy-controller-lease.js"; +import { remoteTerminationReceipt } from "../remote-execution-termination.js"; +import { runUsedConversationAdapter } from "../conversation-continuation.js"; +import { legacyExecutionNeedsReconciliationWithEvidence } from "../legacy-execution-recovery.js"; +import { randomUUID } from "node:crypto"; +import { + and, + asc, + eq, + gt, + inArray, + isNull, + lte, + ne, + or, + sql, +} from "drizzle-orm"; +import type { Db } from "@paperclipai/db"; +import { + agents, + environmentLeases, + heartbeatRuns, + issues, + nativeRunFinalizations, +} from "@paperclipai/db"; +import { logger } from "../../middleware/logger.js"; +import { + claimNativeRestartRecoveries, + closeIdleWarmNativeSessionsForRestart, + currentNativeControllerIdentity, + dispatchNativeSessionResumptions, + detachNativeSessionsForRestart, + isNativeSessionId, + readNativeWorkspaceSyncReference, + type NativeRestartRecoveryClaim, + reconcileNativeFinalizations, + reconcileRetainedNativeSessionCleanup, + reconcileRetainedNativeSessionCleanups, +} from "../native-runtime/index.js"; +import { drainRetainedRunnerdMaintenanceOperations } from "../../vendor/paperclip-runner/index.js"; +import { runningProcesses } from "../../adapters/index.js"; +import { parseObject } from "../../adapters/utils.js"; +import { + isNativeRunnerOwnershipHeld, + NATIVE_OWNERSHIP_UNVERIFIED_ERROR_CODE, +} from "../native-runtime/native-runner-ownership.js"; +import { performance } from "node:perf_hooks"; +import { buildProcessLossDiagnostic } from "../process-loss-diagnostics.js"; +import { logActivity } from "../activity-log.js"; +import { releaseRuntimeServicesForRun } from "../workspace-runtime.js"; +import { isProcessGroupAlive } from "../local-service-supervisor.js"; +import { + findMissingHotRestartSnapshotRunIds, + readHotRestartIntent, + removeHotRestartIntent, + shouldHonorHotRestartIntentForProcess, + writeHotRestartReport, + writeHotRestartShutdownSnapshot, + type HotRestartIntentRun, + type HotRestartReportRun, +} from "../hot-restart.js"; +import { serverVersion } from "../../version.js"; + +import type { environmentService } from "../environments.js"; +import type { environmentRuntimeService, ProviderResourceDisposition } from "../environment-runtime.js"; +import type { agentInstructionWorkingCopyService } from "../agent-instruction-working-copies.js"; +import type { createHeartbeatRunState } from "./run-state.js"; +import type { HeartbeatRetryDependencies, createHeartbeatRetries } from "./retries.js"; + +type HeartbeatRun = typeof heartbeatRuns.$inferSelect; +type HeartbeatRetries = ReturnType; + +/** Recovery owns reconciliation; the service retains execution and lifecycle effects. */ +export interface HeartbeatRecoveryDependencies extends Pick { + enterShutdown: () => void; + getRun: (runId: string, options?: Parameters["getRun"]>[1]) => Promise< + Awaited["getRun"]>> | null + >; + environmentRuntime: ReturnType; + environmentsSvc: Pick, "getById" | "getLeaseById" | "releaseLease">; + instructionCopies: Pick, "recoverStopped" | "recoverCaptured">; + runtimeEnv: Record; + // Preserve the module-wide sets shared by scheduler and route service instances. + activeRunExecutions: Set; + activeRunExecutionPromises: Set>; + scheduleBoundedRetryForRun: HeartbeatRetries["scheduleBoundedRetryForRun"]; + scheduleInteractionContinuationInfrastructureRetryIfEligible: HeartbeatRetries["scheduleInteractionContinuationInfrastructureRetryIfEligible"]; + timerClaimWasFirstHeartbeat: HeartbeatRetries["timerClaimWasFirstHeartbeat"]; + executeRun: (runId: string, options?: { + nativeLeaseOwner?: string; + nativeRestartRecovery?: NativeRestartRecoveryClaim; + }) => Promise; + scheduleNativeSessionResumeDispatch: (runId: string, nextAttemptAt: Date) => void; + cancelHeartbeatNativeRun: (input: { + db: Db; runId: string; reason: string; runtimeMode: string | null; + }) => Promise; + terminateHeartbeatRunProcess: (input: { + pid: number | null | undefined; + processGroupId: number | null | undefined; + graceMs?: number; + }) => Promise; + setRunStatus: (runId: string, status: string, patch?: Partial) => Promise; + setRunStatusFromLive: (runId: string, status: string, fromStatuses: string[], patch?: Partial) => Promise<{ + updated: boolean; + run: HeartbeatRun | null; + }>; + mergeRunStopMetadataForAgent: ( + agent: Pick, + outcome: "succeeded" | "interrupted" | "failed" | "cancelled" | "timed_out", + options?: { + resultJson?: Record | null; + conversationContinuationEligible?: boolean; + errorCode?: string | null; + errorMessage?: string | null; + }, + ) => Record | null; + classifyAndPersistRunLiveness: (run: HeartbeatRun, resultJson?: Record | null) => Promise; + releaseEnvironmentLeasesForRun: (input: { + runId: string; + companyId: string; + agentId: string; + status: string | null | undefined; + failureReason?: string | null; + providerResourceDisposition?: ProviderResourceDisposition; + }) => Promise; + acknowledgeRemoteStop: (runId: string, companyId: string) => Promise; + resumeRemoteStopComments: (run: HeartbeatRun) => Promise; + dispatchPendingNativeStatusWakeups: () => Promise; + cancelRunInternal: (runId: string, reason?: string, options?: { resultJson?: Record }) => Promise; + startNextQueuedRunForAgent: (agentId: string) => Promise; +} + +export const DETACHED_PROCESS_ERROR_CODE = "process_detached"; + +const NATIVE_OWNERSHIP_UNVERIFIED_MESSAGE = + "Native execution ownership could not be verified; automatic recovery is blocked"; + +// The reaper sweeps at most this many pending_cleanup leases per tick. +const PENDING_CLEANUP_SWEEP_PAGE_SIZE = 20; + +const pendingCleanupAttemptsInFlight = new Set(); + +// Escalate and slow cleanup after this many attempts; never abandon a live lease. +const PENDING_CLEANUP_SWEEP_ATTEMPT_CAP = 5; + +// The reaper stores its retry state under these keys in the lease metadata. +const PENDING_CLEANUP_ATTEMPTS_METADATA_KEY = "pendingCleanupRetryAttempts"; + +const PENDING_CLEANUP_CAP_WARNED_METADATA_KEY = "pendingCleanupRetryCapWarned"; + +// The reaper sweeps at most this many orphaned active leases per tick. +const ORPHANED_ACTIVE_LEASE_SWEEP_PAGE_SIZE = 20; + +// A provider or plugin destroy rejection can carry a bearer credential, a +// signed URL, or provider response detail in its name, code, message, cause, or +// stack. The exception fields cross the server boundary, so they are not a +// trusted enum. The pending_cleanup sweep logs never read the exception. Each +// catch site logs a constant, locally generated `errorKind` instead. +const PENDING_CLEANUP_RETRY_ERROR_KIND = "destroy_failed"; + +const PENDING_CLEANUP_SWEEP_ERROR_KIND = "sweep_failed"; + +const ORPHANED_ACTIVE_LEASE_SWEEP_ERROR_KIND = "orphaned_active_lease_sweep_failed"; + +// Read the stored retry attempt count as a safe value, directly in SQL. A +// provider can write a malformed value under the attempts key. The type guard +// makes any non-number value read as zero. The reader computes as numeric and +// never casts to int, so a finite number outside the 32-bit range (for example +// 1e300) never throws. The reader clamps a negative value to zero and a positive +// value to the attempt cap. One malformed lease therefore never aborts the page +// sweep. This matches the TypeScript reader `readPendingCleanupRetryAttempts`, +// which clamps to the same range. The claim predicate compares the two readers, +// so both must yield the same value for every input. +function pendingCleanupAttemptsSql() { + return sql` + case + when jsonb_typeof(${environmentLeases.metadata} -> ${PENDING_CLEANUP_ATTEMPTS_METADATA_KEY}) = 'number' + then least( + greatest( + floor((${environmentLeases.metadata} ->> ${PENDING_CLEANUP_ATTEMPTS_METADATA_KEY})::numeric), + 0 + ), + ${PENDING_CLEANUP_SWEEP_ATTEMPT_CAP} + ) + else 0 + end`; +} + +function pendingCleanupRetryDueSql(explicitRetry = false) { + // Ownership renewal and retry cooldown are separate clocks. A late renewal + // cannot change when a completed attempt may retry. Older claims used the + // retry field for both clocks, so retain that fallback until they settle. + const deadline = sql`case + when ${environmentLeases.metadata}->>'pendingCleanupInFlight' = 'true' + and ${environmentLeases.metadata} ? 'pendingCleanupLeaseExpiresAtMs' + then ${environmentLeases.metadata}->'pendingCleanupLeaseExpiresAtMs' + else ${environmentLeases.metadata}->'pendingCleanupRetryAfterMs' end`; + return sql`case + when ${explicitRetry} and coalesce(${environmentLeases.metadata}->>'pendingCleanupInFlight', 'false') != 'true' then true + when jsonb_typeof(${deadline}) = 'number' + then (${deadline})::numeric <= ${Date.now()} + or (${deadline})::numeric > ${Date.now() + 30 * 60_000 + 1_000} + else true end`; +} + +// Choose the `jsonb_set` target root. A provider can write a scalar or array +// metadata root. `jsonb_set` fails on a non-object root, so the reader uses the +// stored metadata only when its root is an object. A NULL, scalar, or array root +// reads as an empty object. `jsonb_typeof(NULL)` is NULL, so the else branch also +// covers a NULL root. +function pendingCleanupMetadataObjectSql() { + return sql`case when jsonb_typeof(${environmentLeases.metadata}) = 'object' then ${environmentLeases.metadata} else '{}'::jsonb end`; +} + +// Read the stored cap-warned flag as a safe boolean, directly in SQL. A +// malformed value reads as false, so the boolean cast never throws. +function pendingCleanupCapWarnedSql() { + return sql`coalesce( + case + when jsonb_typeof(${environmentLeases.metadata} -> ${PENDING_CLEANUP_CAP_WARNED_METADATA_KEY}) = 'boolean' + then (${environmentLeases.metadata} ->> ${PENDING_CLEANUP_CAP_WARNED_METADATA_KEY})::boolean + else false + end, + false + )`; +} + +export const CANCELLABLE_HEARTBEAT_RUN_STATUSES = [ + "queued", + "running", + "scheduled_retry", +] as const; + +const NATIVE_QUESTION_CANCELLATION_CONTEXT_KEY = "nativeQuestionCancellation"; + +export const HEARTBEAT_RUN_TERMINAL_STATUSES = [ + "succeeded", + "interrupted", + "failed", + "cancelled", + "timed_out", +] as const; + +const SESSIONED_LOCAL_ADAPTERS = new Set([ + "claude_local", + "codex_local", + "cursor", + "gemini_local", + "hermes_local", + "kimi_local", + "opencode_local", + "pi_local", +]); + +function isTrackedLocalChildProcessAdapter(adapterType: string) { + return SESSIONED_LOCAL_ADAPTERS.has(adapterType); +} + +// A positive liveness check means some process currently owns the PID. +// On Linux, PIDs can be recycled, so this is a best-effort signal rather +// than proof that the original child is still alive. +export function isProcessAlive(pid: number | null | undefined) { + if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) + return false; + try { + process.kill(pid, 0); + return true; + } catch (error) { + const code = (error as NodeJS.ErrnoException | undefined)?.code; + if (code === "EPERM") return true; + if (code === "ESRCH") return false; + return false; + } +} + +function buildProcessLossMessage( + run: { + processPid: number | null; + processGroupId: number | null; + }, + options?: { descendantOnly?: boolean }, +) { + if (options?.descendantOnly && run.processGroupId) { + return `Process lost -- parent pid ${run.processPid ?? "unknown"} exited, but descendant process group ${run.processGroupId} was still alive and was terminated`; + } + if (run.processPid) { + return `Process lost -- child pid ${run.processPid} is no longer running`; + } + if (run.processGroupId) { + return `Process lost -- process group ${run.processGroupId} is no longer running`; + } + return "Process lost -- server may have restarted"; +} + +function readHotRestartAdoptionMetadata( + resultJson: Record | null | undefined, +) { + const result = parseObject(resultJson); + const hotRestart = parseObject(result.hotRestart); + if (hotRestart.adopted !== true || typeof hotRestart.adoptedAt !== "string") + return null; + return hotRestart; +} + +function mergeHotRestartAdoptionResultJson( + resultJson: Record | null | undefined, + input: { + adoptedAt: Date; + previousServerPid: number; + newServerPid: number; + previousServerVersion: string | null; + newServerVersion: string; + processPid: number | null; + processGroupId: number | null; + }, +) { + const result = parseObject(resultJson); + const existing = parseObject(result.hotRestart); + return { + ...result, + hotRestart: { + ...existing, + adopted: true, + adoptedAt: input.adoptedAt.toISOString(), + previousServerPid: input.previousServerPid, + newServerPid: input.newServerPid, + previousServerVersion: input.previousServerVersion, + newServerVersion: input.newServerVersion, + processPid: input.processPid, + processGroupId: input.processGroupId, + }, + }; +} + +function readNonEmptyString(value: unknown): string | null { + return typeof value === "string" && value.trim().length > 0 ? value : null; +} + +/** Restart recovery shares the service lifecycle callbacks and execution ownership. */ +export function createHeartbeatRecovery(db: Db, dependencies: HeartbeatRecoveryDependencies) { + const { + enterShutdown, + scheduleBoundedRetryForRun, + appendRunEvent, + environmentRuntime, + scheduleNativeSessionResumeDispatch, + getRun, + executeRun, + activeRunExecutionPromises, + cancelHeartbeatNativeRun, + terminateHeartbeatRunProcess, + setRunStatusIfRunning, + mergeRunStopMetadataForAgent, + setWakeupStatus, + classifyAndPersistRunLiveness, + releaseEnvironmentLeasesForRun, + releaseIssueExecutionAndPromote, + finalizeAgentStatus, + timerClaimWasFirstHeartbeat, + environmentsSvc, + acknowledgeRemoteStop, + resumeRemoteStopComments, + setRunStatusFromLive, + instructionCopies, + dispatchPendingNativeStatusWakeups, + runtimeEnv, + cancelRunInternal, + activeRunExecutions, + setRunStatus, + getAgent, + scheduleInteractionContinuationInfrastructureRetryIfEligible, + startNextQueuedRunForAgent, + } = dependencies; + + async function enqueueProcessLossRetry( + run: typeof heartbeatRuns.$inferSelect, + agent: typeof agents.$inferSelect, + now: Date, + ) { + // Completion deliveries own their durable bounded retry and reply identity. + // A second process-loss retry would compete for the same outbox input. + if (run.contextSnapshot?.wakeReason === CHAT_COMPLETION_WAKE_REASON && + Array.isArray(run.contextSnapshot?.chatCompletionDeliveryIds)) return null; + // Native sessions have their own fenced same-run controller. Legacy + // bootstrap recovery shares the durable delay and incident counter with + // transient retries; process loss must not open a second retry budget. + if (run.runtimeMode === "native" || await legacyExecutionNeedsReconciliationWithEvidence(db, run)) + return null; + const scheduled = await scheduleBoundedRetryForRun(run, agent, { now }); + return scheduled.outcome === "scheduled" ? scheduled.run : null; + } + + function toHotRestartIntentRun(input: { + run: typeof heartbeatRuns.$inferSelect; + adapterType: string; + }): HotRestartIntentRun { + const context = parseObject(input.run.contextSnapshot); + return { + runId: input.run.id, + companyId: input.run.companyId, + agentId: input.run.agentId, + adapterType: input.adapterType, + status: input.run.status, + processPid: input.run.processPid ?? null, + processGroupId: input.run.processGroupId ?? null, + issueId: readNonEmptyString(context.issueId), + runtimeMode: input.run.runtimeMode, + nativeSessionId: input.run.nativeSessionId, + runnerInstanceId: input.run.runnerInstanceId, + processStartedAt: input.run.processStartedAt?.toISOString() ?? null, + }; + } + + function isServerStdioBoundHotRestartRun(input: { + run: typeof heartbeatRuns.$inferSelect; + adapterType: string; + adapterConfig: unknown; + }) { + const context = parseObject(input.run.contextSnapshot); + if ( + context.processTopology === "server_stdio" || + context.executionEngine === "acp" + ) { + return true; + } + if ( + context.processTopology === "detached" || + context.executionEngine === "cli" + ) { + return false; + } + if ( + !["claude_local", "codex_local", "gemini_local"].includes( + input.adapterType, + ) + ) { + return false; + } + return ( + readNonEmptyString(parseObject(input.adapterConfig).engine) !== "cli" + ); + } + + async function prepareHotRestartShutdown( + signal: "SIGINT" | "SIGTERM", + now = new Date(), + ) { + enterShutdown(); + const idleSessions = await closeIdleWarmNativeSessionsForRestart(); + if (idleSessions.failed > 0) { + logger.warn({ idleSessions }, "idle native sessions could not checkpoint before controller shutdown"); + } + let intent: Awaited>; + try { + intent = await readHotRestartIntent(); + } catch (err) { + logger.warn( + { err }, + "failed to read hot-restart intent; falling back to normal shutdown drain", + ); + return { + mode: "read_error" as const, + skipDrain: false as const, + activeRunIds: [] as string[], + }; + } + + if (!intent) + return { + mode: "not_requested" as const, + skipDrain: false as const, + activeRunIds: [] as string[], + }; + if (intent.drainRequired) + return { + mode: "drain_required" as const, + skipDrain: false as const, + activeRunIds: [] as string[], + }; + if (!shouldHonorHotRestartIntentForProcess(intent)) { + logger.warn( + { expectedPid: intent.previousServerPid, currentPid: process.pid }, + "hot-restart intent targets a different server pid; falling back to normal shutdown drain", + ); + return { + mode: "pid_mismatch" as const, + skipDrain: false as const, + activeRunIds: [] as string[], + }; + } + + const activeRuns = await db + .select({ + run: heartbeatRuns, + adapterType: agents.adapterType, + adapterConfig: agents.adapterConfig, + }) + .from(heartbeatRuns) + .innerJoin(agents, eq(heartbeatRuns.agentId, agents.id)) + .where(eq(heartbeatRuns.status, "running")); + const snapshotRuns = activeRuns.map(toHotRestartIntentRun); + const intentWithVersion = { + ...intent, + previousServerVersion: intent.previousServerVersion ?? serverVersion, + }; + + const serverStdioRuns = activeRuns.filter(isServerStdioBoundHotRestartRun); + if (serverStdioRuns.length > 0) { + const activeServerStdioRunIds = serverStdioRuns.map(({ run }) => run.id); + await writeHotRestartShutdownSnapshot({ + intent: intentWithVersion, + signal, + activeRuns: snapshotRuns, + drainReason: "active_acp_run", + drainRunIds: activeServerStdioRunIds, + capturedAt: now, + }); + + logger.warn( + { + signal, + previousServerPid: intent.previousServerPid, + activeRunIds: snapshotRuns.map((run) => run.runId), + activeServerStdioRunIds, + drainReason: "active_acp_run", + }, + "server-stdio agent run prevents hot-restart adoption; using graceful drain and retry", + ); + + return { + mode: "acp_drain_required" as const, + skipDrain: false as const, + activeRunIds: snapshotRuns.map((run) => run.runId), + activeAcpRunIds: activeServerStdioRunIds, + drainRunIds: activeServerStdioRunIds, + drainReason: "active_acp_run" as const, + }; + } + + await writeHotRestartShutdownSnapshot({ + intent: intentWithVersion, + signal, + activeRuns: snapshotRuns, + capturedAt: now, + }); + + for (const { run } of activeRuns) { + await appendRunEvent(run, { + eventType: "lifecycle", + stream: "system", + level: "info", + message: + "Hot restart requested; leaving child process alive for startup adoption", + payload: { + signal, + previousServerPid: intent.previousServerPid, + previousServerVersion: intentWithVersion.previousServerVersion, + processPid: run.processPid ?? null, + processGroupId: run.processGroupId ?? null, + }, + }); + } + + const nativeRunIds = activeRuns + .filter( + ({ run, adapterType }) => + adapterType === "paperclip_runner" && + isNativeSessionId(run.nativeSessionId), + ) + .map(({ run }) => run.id); + const detachedNativeSessions = + await detachNativeSessionsForRestart(nativeRunIds); + + logger.info( + { + signal, + previousServerPid: intent.previousServerPid, + activeRunIds: snapshotRuns.map((run) => run.runId), + detachedNativeSessions, + }, + "hot-restart shutdown snapshot captured; skipping graceful run drain", + ); + + return { + mode: "hot_restart" as const, + skipDrain: true as const, + activeRunIds: snapshotRuns.map((run) => run.runId), + }; + } + + async function reconcileHotRestartAdoption(now = new Date()) { + let intent: Awaited>; + try { + intent = await readHotRestartIntent(); + } catch (err) { + logger.warn( + { err }, + "failed to read hot-restart intent on startup; skipping adoption", + ); + return { + mode: "read_error" as const, + adoptedRunIds: [] as string[], + finalizedWhileDownRunIds: [] as string[], + lostRunIds: [] as string[], + skippedRunIds: [] as string[], + }; + } + if (!intent) { + return { + mode: "not_requested" as const, + adoptedRunIds: [] as string[], + finalizedWhileDownRunIds: [] as string[], + lostRunIds: [] as string[], + skippedRunIds: [] as string[], + }; + } + + if (!intent.shutdownSnapshot) { + const log = intent.drainRequired + ? logger.info.bind(logger) + : logger.warn.bind(logger); + log( + { + previousServerPid: intent.previousServerPid, + preflightActiveRunIds: intent.preflightActiveRunIds, + drainReason: intent.drainReason ?? null, + }, + intent.drainRequired + ? "drain-required restart intent has no adoption snapshot" + : "hot-restart intent present but shutdown snapshot is missing; no runs can be adopted", + ); + } + const candidates = intent.shutdownSnapshot?.activeRuns ?? []; + const missingSnapshotRunIds = findMissingHotRestartSnapshotRunIds(intent); + const reconciliationRunIds = [ + ...new Set([ + ...candidates.map((run) => run.runId), + ...missingSnapshotRunIds, + ]), + ]; + const currentRows = + reconciliationRunIds.length > 0 + ? await db + .select({ + run: heartbeatRuns, + adapterType: agents.adapterType, + }) + .from(heartbeatRuns) + .innerJoin(agents, eq(heartbeatRuns.agentId, agents.id)) + .where(inArray(heartbeatRuns.id, reconciliationRunIds)) + : []; + const currentByRunId = new Map(currentRows.map((row) => [row.run.id, row])); + + const reportRuns: HotRestartReportRun[] = []; + const adoptedRunIds: string[] = []; + const finalizedWhileDownRunIds: string[] = []; + const lostRunIds: string[] = []; + const skippedRunIds: string[] = []; + + const classify = ( + candidate: HotRestartIntentRun, + classification: HotRestartReportRun["classification"], + reason: string, + patch?: Partial, + ) => { + const run = { + ...candidate, + ...patch, + classification, + reason, + } satisfies HotRestartReportRun; + reportRuns.push(run); + if (classification === "adopted") adoptedRunIds.push(candidate.runId); + else if (classification === "finalized_while_down") + finalizedWhileDownRunIds.push(candidate.runId); + else if (classification === "lost") lostRunIds.push(candidate.runId); + else skippedRunIds.push(candidate.runId); + }; + + for (const runId of missingSnapshotRunIds) { + const current = currentByRunId.get(runId); + if (!current) { + finalizedWhileDownRunIds.push(runId); + continue; + } + + const candidate = toHotRestartIntentRun(current); + if (current.run.status !== "running") { + classify( + candidate, + "finalized_while_down", + `run_status_${current.run.status}`, + ); + } else { + classify(candidate, "lost", "missing_shutdown_snapshot"); + } + } + + if (lostRunIds.length > 0) { + logger.error( + { previousServerPid: intent.previousServerPid, lostRunIds }, + "hot-restart shutdown snapshot omitted live preflight runs; reporting them as lost", + ); + } + + for (const candidate of candidates) { + const current = currentByRunId.get(candidate.runId); + if (!current) { + classify(candidate, "finalized_while_down", "run_row_missing"); + continue; + } + + const { run, adapterType } = current; + const patch = { + adapterType, + status: run.status, + processPid: run.processPid ?? candidate.processPid, + processGroupId: run.processGroupId ?? candidate.processGroupId, + }; + + if (run.status !== "running") { + classify( + candidate, + "finalized_while_down", + `run_status_${run.status}`, + patch, + ); + continue; + } + + const hasSelectiveAcpDrain = + intent.drainReason === "active_acp_run" && + (intent.drainRunIds?.length ?? 0) > 0; + if ( + hasSelectiveAcpDrain && + intent.drainRunIds?.includes(candidate.runId) + ) { + // A selective ACP drain is expected to persist a terminal row before + // the new server starts. If the process was terminated but that write + // failed, surface the run as lost instead of hiding it as an expected + // drain skip. + classify(candidate, "lost", "selective_drain_not_finalized", patch); + continue; + } + if (intent.drainRequired && !hasSelectiveAcpDrain) { + classify(candidate, "skipped", "drain_required", patch); + continue; + } + + if (run.runtimeMode === "native" && adapterType === "paperclip_runner") { + classify(candidate, "skipped", "native_restart_recovery_owned", patch); + continue; + } + + if (!isTrackedLocalChildProcessAdapter(adapterType)) { + classify( + candidate, + "skipped", + "adapter_not_local_child_process", + patch, + ); + continue; + } + + const processPid = run.processPid ?? candidate.processPid; + const processGroupId = run.processGroupId ?? candidate.processGroupId; + const processPidAlive = isProcessAlive(processPid); + const processGroupAlive = isProcessGroupAlive(processGroupId); + if (!processPid && !processGroupId) { + classify(candidate, "lost", "missing_process_metadata", patch); + continue; + } + if (!processPidAlive && !processGroupAlive) { + classify(candidate, "lost", "process_not_alive", patch); + continue; + } + + const resultJson = mergeHotRestartAdoptionResultJson( + parseObject(run.resultJson), + { + adoptedAt: now, + previousServerPid: intent.previousServerPid, + newServerPid: process.pid, + previousServerVersion: intent.previousServerVersion, + newServerVersion: serverVersion, + processPid, + processGroupId, + }, + ); + const updated = await db + .update(heartbeatRuns) + .set({ + resultJson: preserveWorkspaceRestoreRecoveryMetadataSql(resultJson, true), + error: + run.errorCode === DETACHED_PROCESS_ERROR_CODE ? null : run.error, + errorCode: + run.errorCode === DETACHED_PROCESS_ERROR_CODE + ? null + : run.errorCode, + updatedAt: now, + }) + .where( + and( + eq(heartbeatRuns.id, run.id), + eq(heartbeatRuns.status, "running"), + ), + ) + .returning() + .then((rows) => rows[0] ?? null); + + if (!updated) { + const latest = await db + .select({ status: heartbeatRuns.status }) + .from(heartbeatRuns) + .where(eq(heartbeatRuns.id, run.id)) + .then((rows) => rows[0] ?? null); + if (latest && latest.status !== "running") { + classify( + candidate, + "finalized_while_down", + `run_status_${latest.status}`, + patch, + ); + } else { + classify(candidate, "lost", "adoption_update_not_applied", patch); + } + continue; + } + + await appendRunEvent(updated, { + eventType: "lifecycle", + stream: "system", + level: "info", + message: "Adopted live child process after hot restart", + payload: { + previousServerPid: intent.previousServerPid, + newServerPid: process.pid, + previousServerVersion: intent.previousServerVersion, + newServerVersion: serverVersion, + processPid, + processGroupId, + }, + }); + classify( + candidate, + "adopted", + processPidAlive ? "process_pid_alive" : "process_group_alive", + patch, + ); + } + + const report = await writeHotRestartReport({ + version: 1, + requestedAt: intent.requestedAt, + completedAt: now.toISOString(), + drainRequired: intent.drainRequired, + drainReason: + intent.drainReason ?? (intent.drainRequired ? "requested" : null), + previousServerPid: intent.previousServerPid, + newServerPid: process.pid, + previousServerVersion: intent.previousServerVersion, + newServerVersion: serverVersion, + adoptedRunIds, + finalizedWhileDownRunIds, + lostRunIds, + skippedRunIds, + runs: reportRuns, + }); + await removeHotRestartIntent(undefined, intent); + + logger.info( + { + previousServerPid: report.previousServerPid, + newServerPid: report.newServerPid, + adoptedRunIds, + finalizedWhileDownRunIds, + lostRunIds, + missingSnapshotRunIds, + skippedRunIds, + }, + "hot-restart adoption report written", + ); + + return { + mode: "reported" as const, + adoptedRunIds, + finalizedWhileDownRunIds, + lostRunIds, + skippedRunIds, + }; + } + + async function recoverNativeRunsAfterRestart(now = new Date()) { + // A result committed before the old controller stopped outranks process + // recovery. Finish its durable workspace/status suffix before deciding + // whether any provider authority needs to be reopened. + await reconcileNativeFinalizations(db, undefined, { + environmentRuntime, + onWorkspaceSettled: settleRecoveredNativeWorkspace, + }); + scheduleRetainedNativeSessionCleanup(); + const intent = await readHotRestartIntent().catch((error) => { + logger.warn( + { err: error }, + "failed to read hot-restart intent before native startup recovery", + ); + return null; + }); + const restartKind = intent ? ("hot" as const) : ("hard" as const); + const previousStartedAt = intent?.previousServerStartedAt + ? new Date(intent.previousServerStartedAt) + : null; + const scheduledNativeRetries = await db + .select({ + runId: nativeRunFinalizations.runId, + nextAttemptAt: nativeRunFinalizations.nextAttemptAt, + }) + .from(nativeRunFinalizations) + .innerJoin( + heartbeatRuns, + eq(heartbeatRuns.id, nativeRunFinalizations.runId), + ) + .where( + and( + eq(heartbeatRuns.runtimeMode, "native"), + inArray(heartbeatRuns.status, ["running", "failed"]), + isNull(nativeRunFinalizations.resultId), + eq(nativeRunFinalizations.phase, "retryable_failure"), + gt(nativeRunFinalizations.nextAttemptAt, now), + ), + ); + for (const scheduled of scheduledNativeRetries) { + if (scheduled.nextAttemptAt) { + scheduleNativeSessionResumeDispatch( + scheduled.runId, + scheduled.nextAttemptAt, + ); + } + } + const dispositions = await claimNativeRestartRecoveries({ + db, + restartKind, + recoveryRequestId: intent?.recoveryRequestId ?? null, + coordinatedPreviousController: intent + ? { + pid: intent.previousServerPid, + processStartedAt: + previousStartedAt && !Number.isNaN(previousStartedAt.getTime()) + ? previousStartedAt + : null, + } + : null, + now, + }); + + const claims = dispositions.filter( + (disposition): disposition is NativeRestartRecoveryClaim => + disposition.kind === "reattach_existing_runner" || + disposition.kind === "reattach_remote_runner" || + disposition.kind === "resume_dead_runner" || + disposition.kind === "bootstrap_incomplete", + ); + for (const disposition of dispositions) { + const run = await getRun(disposition.runId); + if (run) { + const isClaim = + disposition.kind === "reattach_existing_runner" || + disposition.kind === "reattach_remote_runner" || + disposition.kind === "resume_dead_runner" || + disposition.kind === "bootstrap_incomplete"; + await appendRunEvent(run, { + eventType: "native.recovery.transition", + stream: "system", + level: disposition.kind === "blocked" ? "warn" : "info", + message: + disposition.kind === "reattach_existing_runner" || + disposition.kind === "reattach_remote_runner" + ? "Recovering the existing native runner process after server restart" + : disposition.kind === "resume_dead_runner" + ? "Resuming the durable native provider session after runner process loss" + : disposition.kind === "bootstrap_incomplete" + ? "Restarting an incomplete native runner bootstrap on the same heartbeat run" + : disposition.kind === "awaiting_evidence" + ? "Native restart recovery is waiting for safe ownership evidence" + : disposition.kind === "already_finalized" + ? "Native restart recovery found an already-finalized result" + : "Native restart recovery blocked ambiguous or conflicting ownership", + payload: { + restartKind: isClaim ? disposition.restartKind : restartKind, + recoveryRequestId: isClaim + ? disposition.recoveryRequestId + : (intent?.recoveryRequestId ?? null), + runnerDisposition: disposition.kind, + ...(isClaim + ? { + controllerGeneration: disposition.controllerGeneration, + providerAttempt: disposition.providerAttempt, + } + : { reason: disposition.reason }), + ...(disposition.kind === "reattach_existing_runner" + ? { + processPid: disposition.process.pid, + processGroupId: disposition.process.processGroupId, + processStartedAt: disposition.process.startedAt, + } + : {}), + }, + }); + } + } + for (const claim of claims) { + const execution = executeRun(claim.runId, { + nativeLeaseOwner: claim.leaseOwner, + nativeRestartRecovery: claim, + }).catch((error) => { + logger.error( + { err: error, runId: claim.runId, disposition: claim.kind }, + "native restart recovery execution failed", + ); + }); + activeRunExecutionPromises.add(execution); + void execution.finally(() => + activeRunExecutionPromises.delete(execution), + ); + } + + return { + restartKind, + claims, + dispositions, + scheduledRetryRunIds: scheduledNativeRetries.map((entry) => entry.runId), + awaitingEvidenceRunIds: dispositions + .filter((entry) => entry.kind === "awaiting_evidence") + .map((entry) => entry.runId), + blockedRunIds: dispositions + .filter((entry) => entry.kind === "blocked") + .map((entry) => entry.runId), + }; + } + + async function drainRunningRunsForShutdown( + signal: "SIGINT" | "SIGTERM", + now = new Date(), + runIds: readonly string[] | null = null, + ) { + const selectedRunIds = runIds ? [...new Set(runIds)] : null; + if (selectedRunIds?.length === 0) { + return { + interrupted: 0, + interruptedRunIds: [], + retryRunIds: [], + restartSuspendedRunIds: [], + }; + } + const activeRuns = await db + .select({ + run: heartbeatRuns, + agent: agents, + }) + .from(heartbeatRuns) + .innerJoin(agents, eq(heartbeatRuns.agentId, agents.id)) + .where( + selectedRunIds + ? and( + eq(heartbeatRuns.status, "running"), + inArray(heartbeatRuns.id, selectedRunIds), + ) + : eq(heartbeatRuns.status, "running"), + ); + + const interruptedRunIds: string[] = []; + const retryRunIds: string[] = []; + const restartSuspendedRunIds: string[] = []; + + for (const { run, agent } of activeRuns) { + // Shutdown owns only this boot's legacy executions. Expired foreign + // owners belong to the reaper, not another container's drain. + if (run.runtimeMode === "legacy" && run.controllerBootId && + run.controllerBootId !== legacyControllerBootId) continue; + if (isNativeRunnerOwnershipHeld(run)) continue; + if ( + run.runtimeMode === "native" && + agent.adapterType === "paperclip_runner" + ) { + // A graceful shutdown relinquishes controller authority just like a + // hot restart. Leaving the old event consumer attached lets its + // finalizer interrupt/suspend Claude while the next server is adopting + // the same turn. + await detachNativeSessionsForRestart([run.id]); + const recoveryHistoryEntry = JSON.stringify({ + at: now.toISOString(), + restartKind: "graceful", + disposition: "restart_suspended", + reason: signal, + processPid: run.processPid, + processStartedAt: run.processStartedAt?.toISOString() ?? null, + }); + await db + .update(nativeRunFinalizations) + .set({ + recoveryState: "awaiting_runner_reattach", + recoveryHistory: sql`( + select coalesce(jsonb_agg(item order by ordinal), '[]'::jsonb) + from jsonb_array_elements( + coalesce(${nativeRunFinalizations.recoveryHistory}, '[]'::jsonb) + || jsonb_build_array(${recoveryHistoryEntry}::jsonb) + ) with ordinality as history(item, ordinal) + where ordinal > greatest( + jsonb_array_length( + coalesce(${nativeRunFinalizations.recoveryHistory}, '[]'::jsonb) + || jsonb_build_array(${recoveryHistoryEntry}::jsonb) + ) - 20, + 0 + ) + )`, + updatedAt: now, + }) + .where( + and( + eq(nativeRunFinalizations.runId, run.id), + isNull(nativeRunFinalizations.resultId), + ), + ); + await appendRunEvent(run, { + eventType: "native.recovery.transition", + stream: "system", + level: "info", + message: + "Server shutdown suspended native controller ownership without cancelling provider work", + payload: { + restartKind: "graceful", + signal, + runnerDisposition: "awaiting_runner_reattach", + processPid: run.processPid, + processGroupId: run.processGroupId, + processStartedAt: run.processStartedAt?.toISOString() ?? null, + retryRunCreated: false, + }, + }); + restartSuspendedRunIds.push(run.id); + continue; + } + const message = `Interrupted by graceful server shutdown (${signal})`; + const running = runningProcesses.get(run.id); + try { + if (run.runtimeMode === "native") { + await cancelHeartbeatNativeRun({ + db, + runId: run.id, + reason: message, + runtimeMode: run.runtimeMode, + }); + } + if (running) { + await terminateHeartbeatRunProcess({ + pid: running.child.pid, + processGroupId: running.processGroupId, + graceMs: Math.max(1, running.graceSec) * 1000, + }); + } + } finally { + runningProcesses.delete(run.id); + } + + const persistedCancellationResult = + run.runtimeMode === "native" + ? await getRun(run.id).then((current) => + parseObject(current?.resultJson), + ) + : parseObject(run.resultJson); + + const interruptedStatus = await setRunStatusIfRunning( + run.id, + "interrupted", + { + finishedAt: now, + error: message, + errorCode: "server_shutdown_interrupted", + signal, + resultJson: mergeRunStopMetadataForAgent(agent, "interrupted", { + conversationContinuationEligible: await runUsedConversationAdapter(db, run), + resultJson: persistedCancellationResult, + errorCode: "server_shutdown_interrupted", + errorMessage: message, + }), + }, + ); + if (!interruptedStatus.updated || !interruptedStatus.run) continue; + let interrupted = interruptedStatus.run; + await setWakeupStatus(run.wakeupRequestId, "cancelled", { + finishedAt: now, + error: null, + }); + interrupted = + (await classifyAndPersistRunLiveness( + interrupted, + parseObject(interrupted.resultJson), + )) ?? interrupted; + + await releaseEnvironmentLeasesForRun({ + runId: interrupted.id, + companyId: interrupted.companyId, + agentId: interrupted.agentId, + status: interrupted.status, + failureReason: interrupted.error ?? undefined, + }); + + const retry = await enqueueProcessLossRetry(interrupted, agent, now); + if (!retry) { + await releaseIssueExecutionAndPromote(interrupted); + } else { + retryRunIds.push(retry.id); + } + + await appendRunEvent(interrupted, { + eventType: "lifecycle", + stream: "system", + level: "warn", + message, + payload: { + signal, + ...(run.processPid ? { processPid: run.processPid } : {}), + ...(run.processGroupId ? { processGroupId: run.processGroupId } : {}), + ...(retry ? { retryRunId: retry.id } : {}), + }, + }); + + await finalizeAgentStatus(run.agentId, "interrupted", message, { + wasFirstHeartbeat: timerClaimWasFirstHeartbeat(run), + }); + interruptedRunIds.push(interrupted.id); + } + + if (interruptedRunIds.length > 0) { + logger.warn( + { + signal, + interrupted: interruptedRunIds.length, + interruptedRunIds, + retryRunIds, + }, + "interrupted running heartbeat runs for graceful shutdown", + ); + } + + return { + interrupted: interruptedRunIds.length, + interruptedRunIds, + retryRunIds, + restartSuspendedRunIds, + }; + } + + // Clamp the stored attempt count to the range [0, cap]. The SQL reader + // `pendingCleanupAttemptsSql` clamps to the same range, so both readers yield + // the same value for every input. The claim predicate compares the two values, + // so this alignment lets the claim match for a malformed lease. + function readPendingCleanupRetryAttempts( + metadata: Record, + ): number { + const value = metadata[PENDING_CLEANUP_ATTEMPTS_METADATA_KEY]; + if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) + return 0; + return Math.min(Math.floor(value), PENDING_CLEANUP_SWEEP_ATTEMPT_CAP); + } + + // Atomically claim one retry attempt on a pending_cleanup lease. The update + // only matches when the lease is still pending_cleanup and its stored attempt + // count still equals `expectedAttempts`. Two concurrent sweeps read the same + // count, but Postgres serializes the two updates on the row and only the first + // matches the guard. The loser gets zero rows and skips the lease. The persisted in-flight deadline also prevents a later tick + // from starting another attempt while this one is still running. + // Returns the attempt identity only for the sweep that won the claim. + // + // The update patches cleanup ownership fields without writing a copied + // metadata object, so a concurrent write to an unrelated metadata key + // survives. The guard reads the stored count through the safe SQL reader, so a + // malformed value never throws. + async function claimPendingCleanupRetryAttempt( + leaseId: string, + expectedAttempts: number, + manualAttempt?: { previousId: unknown }, + ): Promise { + const now = new Date(); + const attemptId = randomUUID(); + const claimed = await db + .update(environmentLeases) + .set({ + metadata: sql`jsonb_set(${pendingCleanupMetadataObjectSql()}, array[${PENDING_CLEANUP_ATTEMPTS_METADATA_KEY}], to_jsonb(${expectedAttempts + 1}::int), true) + || ${JSON.stringify({ ...(manualAttempt ? { pendingCleanupManualAttemptId: randomUUID() } : {}), + pendingCleanupAttemptId: attemptId, pendingCleanupInFlight: true, + pendingCleanupLeaseExpiresAtMs: Date.now() + 15 * 60_000, + })}::jsonb`, + lastUsedAt: now, + updatedAt: now, + }) + .where( + and( + eq(environmentLeases.id, leaseId), + eq(environmentLeases.status, "pending_cleanup"), + sql`${pendingCleanupAttemptsSql()} = ${expectedAttempts}`, + manualAttempt ? sql`coalesce(${environmentLeases.metadata}->'pendingCleanupManualAttemptId', 'null'::jsonb) is not distinct from ${JSON.stringify(manualAttempt.previousId ?? null)}::jsonb` : undefined, + pendingCleanupRetryDueSql(Boolean(manualAttempt)), + ), + ) + .returning({ id: environmentLeases.id }); + return claimed.length > 0 ? attemptId : null; + } + + // Atomically claim the one-time cap warning for a lease. The update only + // matches when the lease is still pending_cleanup, its stored attempt count is + // at or above the cap, and it has not yet carried the warned flag. Two + // concurrent sweeps that both reach the cap race here, but only one update + // sets the flag and returns a row. The loser skips the warning. This keeps the + // warning to one log line per lease. + // + // The status and cap predicates are the last line of defense. They stop a warn + // flag write to a lease that left pending_cleanup or dropped below the cap + // between the read and this claim. The update writes only the warned key with + // `jsonb_set`, so a concurrent write to an unrelated metadata key survives. + async function claimPendingCleanupCapWarning( + leaseId: string, + ): Promise { + const now = new Date(); + const claimed = await db + .update(environmentLeases) + .set({ + metadata: sql`jsonb_set(${pendingCleanupMetadataObjectSql()}, array[${PENDING_CLEANUP_CAP_WARNED_METADATA_KEY}], to_jsonb(true), true)`, + updatedAt: now, + }) + .where( + and( + eq(environmentLeases.id, leaseId), + eq(environmentLeases.status, "pending_cleanup"), + sql`${pendingCleanupAttemptsSql()} >= ${PENDING_CLEANUP_SWEEP_ATTEMPT_CAP}`, + sql`${pendingCleanupCapWarnedSql()} = false`, + ), + ) + .returning({ id: environmentLeases.id }); + return claimed.length > 0; + } + + // Defer a pending_cleanup lease whose provider plugin is not ready this tick. + // The sweep reads one page of the oldest rows, ordered by `updatedAt`. A lease + // that the sweep only skips keeps its old `updatedAt`, so it stays the oldest + // and refills the page on every tick. That starves a newer lease whose + // provider is ready. The defer bumps `updatedAt` to now, so the unavailable + // lease moves to the back of the queue and a ready lease takes its page slot. + // The defer never writes the attempt count, so a long provider outage never + // consumes a finite retry. The status guard keeps the write on a lease that is + // still pending_cleanup. + async function deferPendingCleanupLease(leaseId: string): Promise { + const now = new Date(); + await db + .update(environmentLeases) + .set({ updatedAt: now }) + .where( + and( + eq(environmentLeases.id, leaseId), + eq(environmentLeases.status, "pending_cleanup"), + ), + ); + } + + // Move a guarded orphan candidate to the back of the sweep order. The + // shared-resource guard below can skip a row on every tick as long as the + // other owner stays live, retained, or pending cleanup. The select orders + // by `updatedAt` ascending and takes only the oldest page, so an untouched + // skipped row keeps refilling that same page and blocks every row behind + // it. The bump pushes the row past the fixed-size page, so the next tick + // reaches the rows behind it. It costs the row one extra backoff wait, + // which is safe because the guard means a physical sandbox still exists. + async function deferOrphanedActiveLease(leaseId: string): Promise { + const now = new Date(); + await db + .update(environmentLeases) + .set({ updatedAt: now }) + .where( + and( + eq(environmentLeases.id, leaseId), + eq(environmentLeases.status, "active"), + ), + ); + } + + // An active lease is reachable only while its heartbeat run keeps the + // running status. The reaper writes the run status and the lease release as + // two separate statements, so a restart between them can leave a terminal + // run and an active lease. `releaseRunLeases` also skips a lease whose + // environment row is gone, so that lease stays active too. No later query + // finds either lease, because every production query selects an active + // lease by its environment or by its heartbeat run id, never by age. This + // sweep finds both stranded classes and moves each lease to pending_cleanup, + // so the existing pending_cleanup sweep tears the sandbox down from the + // data already on the lease row. + async function sweepOrphanedActiveLeases(opts: { + backoffMs: number; + }): Promise<{ recovered: number }> { + const cutoff = new Date(Date.now() - opts.backoffMs); + + const rows = await db + .select({ lease: environmentLeases }) + .from(environmentLeases) + .leftJoin( + heartbeatRuns, + eq(environmentLeases.heartbeatRunId, heartbeatRuns.id), + ) + .where( + and( + eq(environmentLeases.status, "active"), + or( + isNull(environmentLeases.heartbeatRunId), + inArray(heartbeatRuns.status, [ + ...HEARTBEAT_RUN_TERMINAL_STATUSES, + ]), + ), + lte(environmentLeases.updatedAt, cutoff), + ), + ) + .orderBy(asc(environmentLeases.updatedAt)) + .limit(ORPHANED_ACTIVE_LEASE_SWEEP_PAGE_SIZE); + + let recovered = 0; + for (const { lease } of rows) { + // A provider resource id names one physical sandbox. A different lease + // row can still hold that same resource in a live status, so this sweep + // must not tear down a sandbox that a different lease still owns. + if (lease.provider && lease.providerLeaseId) { + const [otherOwner] = await db + .select({ id: environmentLeases.id }) + .from(environmentLeases) + .where( + and( + ne(environmentLeases.id, lease.id), + eq(environmentLeases.provider, lease.provider), + eq(environmentLeases.providerLeaseId, lease.providerLeaseId), + inArray(environmentLeases.status, [ + "active", + "retained", + "pending_cleanup", + ]), + ), + ) + .limit(1); + if (otherOwner) { + // Defer this row so the fixed-size page reaches the rows behind + // it next tick, instead of re-selecting the same guarded rows + // forever. + await deferOrphanedActiveLease(lease.id); + continue; + } + } + + // Keep the row's existing updatedAt value. The select above already + // proved the row is older than the backoff cutoff, so the + // pending_cleanup sweep can accept the same row in this same tick. A + // fresh timestamp here would push the row inside that sweep's own + // backoff window and delay the teardown by one full tick. + const flipped = await db + .update(environmentLeases) + .set({ + status: "pending_cleanup", + failureReason: "orphaned_active_lease_recovered", + }) + .where( + and( + eq(environmentLeases.id, lease.id), + eq(environmentLeases.status, "active"), + ), + ) + .returning({ id: environmentLeases.id }); + if (flipped.length > 0) recovered += 1; + } + + return { recovered }; + } + + // Retry the leases stranded in "pending_cleanup". A failed destroy leaves a + // lease in that state forever without this sweep. The reaper tick runs the + // sweep. The backoff equals the reaper staleness threshold, so a lease waits + // for that period between attempts. The sweep reads and writes the attempt + // count in the lease metadata. It warns once when a lease reaches the attempt + // threshold, then continues with slower retries. Live attempts renew their + // cleanup claim; after controller loss, exact-resource destruction may repeat. + async function sweepPendingCleanupLeases(opts?: { + backoffMs?: number; + /** One cleanup attempt per explicit user Retry, for this failed run only. + * A later user Retry may bypass the cooldown after a provider failure, + * but cannot take over an in-flight cleanup attempt. + */ + explicitRetry?: { companyId: string; runId: string; actorId: string; reason?: "retry_failed_run" | "queued_comment_interrupt" }; + }): Promise<{ + swept: number; + destroyed: number; + capped: number; + }> { + const backoffMs = opts?.backoffMs ?? 0; + const now = new Date(); + const cutoff = new Date(now.getTime() - backoffMs); + + // Flush the in-process orphan-cleanup buffer first. A failed acquire buffers + // an orphan there when every synchronous pending-cleanup write failed after a + // failed teardown. The flush re-inserts each buffered record, so a durable + // `pending_cleanup` row lands once the database recovers. The flush runs + // before the read below, so this same tick tears down a freshly-landed row. + try { + const flushed = opts?.explicitRetry ? null : await environmentRuntime.flushDeferredOrphanCleanups?.(); + if (flushed && (flushed.recovered > 0 || flushed.pending > 0)) { + logger.info( + { recovered: flushed.recovered, pending: flushed.pending }, + "flushed the in-process orphan sandbox cleanup buffer to the database", + ); + } + } catch { + // A flush failure never stops the sweep. The buffer keeps the orphan for a + // later tick, and the database rows below still need this sweep. The caught + // exception never enters the log, because a write error can carry a + // credential in its message, code, cause, or stack. + logger.warn( + "orphan sandbox cleanup buffer flush failed; the sweep continues", + ); + } + + const rows = await db + .select() + .from(environmentLeases) + .where( + and( + eq(environmentLeases.status, "pending_cleanup"), + opts?.explicitRetry ? eq(environmentLeases.companyId, opts.explicitRetry.companyId) : undefined, + opts?.explicitRetry ? eq(environmentLeases.heartbeatRunId, opts.explicitRetry.runId) : undefined, + pendingCleanupRetryDueSql(Boolean(opts?.explicitRetry)), + backoffMs > 0 ? lte(environmentLeases.updatedAt, cutoff) : undefined, + ), + ) + .orderBy(asc(environmentLeases.updatedAt)) + .limit(PENDING_CLEANUP_SWEEP_PAGE_SIZE); + + let destroyed = 0; + let capped = 0; + for (const row of rows) { + if (pendingCleanupAttemptsInFlight.has(row.id)) continue; + const metadata = { ...(row.metadata ?? {}) } as Record; + const attempts = readPendingCleanupRetryAttempts(metadata); + + const environment = row.environmentId + ? await environmentsSvc.getById(row.environmentId) + : null; + const lease = await environmentsSvc.getLeaseById(row.id); + if (!lease) continue; + + // An orphan ephemeral lease keeps its provider, its provider lease id, and + // its sandbox config in the lease row. A failed acquire records it, and its + // environment row may be gone or foreign-bound. A reuse_by_environment lease + // whose environment a delete removed keeps the same recorded data, because + // the schema sets the environment reference to null on delete and preserves + // the row. Both leases tear down from the recorded lease data through + // `retryPendingSandboxTeardown`, which never reads the environment row. So + // the sweep uses that path whenever the lease is an orphan ephemeral lease + // or its environment row is gone. A reuse_by_environment lease whose + // environment still exists tears down through `destroyRunLease`. That + // path uses the provider and configuration recorded on the lease first; + // the environment is lifecycle context and only a legacy fallback. + const isOrphanEphemeralLease = lease.leasePolicy === "ephemeral"; + const useRecordedTeardown = isOrphanEphemeralLease || !environment || hasStopOnlyCleanup(lease); + + // Do not consume a finite cleanup attempt while the provider plugin is + // briefly unavailable. A plugin worker restart, a plugin reload, or a + // plugin reinstall makes the provider unavailable for a short window. The + // plugin can be missing or not ready in that window. A teardown then throws, + // and the atomic claim below would count that throw against the cap, so a + // long restart or reload could exhaust the retries and strand a live + // sandbox. So probe the provider first, and defer the lease this tick when + // the provider is not ready. The sweep preserves the pending_cleanup row, + // and a later sweep retries after the provider recovers. The probe reports + // ready only for a permanent condition (a missing provider string, a + // built-in provider, or no worker manager), so a genuine teardown failure + // still runs, throws, and counts toward the cap. A runtime with no probe + // method treats the lease as ready, so the sweep keeps its earlier + // behavior. + const workerReady = environmentRuntime.isPendingCleanupWorkerReady + ? await environmentRuntime.isPendingCleanupWorkerReady({ + environment, + lease, + }) + : true; + if (!workerReady) { + // Move the unavailable lease to the back of the sweep queue. Otherwise + // the oldest unavailable rows refill the page on every tick and starve a + // newer lease that has a ready provider. The defer bumps `updatedAt` + // only, so it consumes no finite retry attempt. + await deferPendingCleanupLease(row.id); + continue; + } + + // Atomically claim the attempt before the retry. Only the winning sweep + // increments the count and tears the sandbox down, so an overlapping sweep + // cannot start another attempt while this one holds the cleanup lease. + // The deadline survives a server restart; the counter saturates at the + // escalation threshold while attempt identities remain unique. + const claimed = await claimPendingCleanupRetryAttempt(row.id, attempts, + opts?.explicitRetry ? { previousId: metadata.pendingCleanupManualAttemptId } : undefined); + if (!claimed) continue; + pendingCleanupAttemptsInFlight.add(row.id); + lease.metadata = { ...lease.metadata, pendingCleanupAttemptId: claimed }; + let activeRenewal: Promise | null = null; + const renewal = setInterval(() => { + if (activeRenewal) return; + activeRenewal = db.update(environmentLeases).set({ + metadata: sql`jsonb_set(${pendingCleanupMetadataObjectSql()}, '{pendingCleanupLeaseExpiresAtMs}', to_jsonb(${Date.now() + 15 * 60_000}::bigint))`, + }).where(and(eq(environmentLeases.id, row.id), eq(environmentLeases.status, "pending_cleanup"), + sql`${environmentLeases.metadata}->>'pendingCleanupAttemptId' = ${claimed}`, + sql`${environmentLeases.metadata}->>'pendingCleanupInFlight' = 'true'`)) + .then(() => {}) + .catch(() => logger.warn({ leaseId: row.id }, "cleanup ownership renewal failed")) + .finally(() => { activeRenewal = null; }); + }, 30_000); + renewal.unref(); + + try { + if (opts?.explicitRetry) await logActivity(db, { + companyId: row.companyId, actorType: "user", actorId: opts.explicitRetry.actorId, + action: "environment_lease.cleanup_retried", entityType: "environment_lease", entityId: row.id, + runId: opts.explicitRetry.runId, details: { attempt: attempts + 1, reason: opts.explicitRetry.reason ?? "retry_failed_run" }, + }); + if (useRecordedTeardown) { + // Tear the sandbox down from the recorded provider config and the + // cleanup-authorized secret versions. Preserve any provider receipt; + // a completed retry must grant the same evidence as initial cleanup. + const receipt = await environmentRuntime.retryPendingSandboxTeardown({ + environment, + lease, + }); + const released = hasStopOnlyCleanup(lease) + ? await settleStopOnlyCleanup(db, lease, { attemptId: claimed, receipt }) + : await environmentsSvc.releaseLease(lease.id, "expired", { + expectedPendingCleanupAttemptId: claimed, + cleanupStatus: "success", + failureReason: "pending_cleanup_retry", + remoteExecutionTermination: remoteTerminationReceipt(lease, receipt), + }); + if (released) destroyed += 1; + } else if (environment) { + const result = await environmentRuntime.destroyRunLease({ + environment, + lease, + failureReason: "pending_cleanup_retry", + }); + if (result && result.status !== "pending_cleanup") { + destroyed += 1; + } + } + } catch { + // The recorded-data teardown throws on failure, so revert the lease to + // pending_cleanup for a later sweep. The claimed attempt still counts + // for backoff, so requests stay bounded. The `destroyRunLease` + // path reverts the lease itself, so this revert only runs for the + // recorded-data teardown path. + if (useRecordedTeardown) { + await environmentsSvc.releaseLease(lease.id, "pending_cleanup", { + expectedPendingCleanupAttemptId: claimed, + cleanupStatus: "failed", + failureReason: "pending_cleanup_retry", + }); + } + // Log a constant errorKind only. The exception can carry a credential in + // its name, code, message, cause, or stack, so the sweep never reads it. + logger.warn( + { + errorKind: PENDING_CLEANUP_RETRY_ERROR_KIND, + leaseId: row.id, + environmentId: row.environmentId, + attempts: attempts + 1, + }, + "pending_cleanup lease retry failed", + ); + } finally { + clearInterval(renewal); + // A hung renewal must not retain process-local cleanup ownership. + // Late renewals are attempt-fenced and never write the retry cooldown. + pendingCleanupAttemptsInFlight.delete(row.id); + } + if (attempts + 1 >= PENDING_CLEANUP_SWEEP_ATTEMPT_CAP) { + capped += 1; + // Warn once, then continue automatic cleanup with backoff. The atomic claim + // keeps the warning to one log line even when two sweeps overlap. + if (metadata[PENDING_CLEANUP_CAP_WARNED_METADATA_KEY] !== true) { + const warned = await claimPendingCleanupCapWarning(row.id); + if (warned) { + logger.warn( + { leaseId: row.id, environmentId: row.environmentId, attempts }, + "environment lease needs operator attention; automatic cleanup continues with backoff", + ); + } + } + } + // Persist the cooldown independently of process memory. A crash before + // this write leaves the bounded in-flight lease for a later sweep. + await db.update(environmentLeases).set({ + metadata: sql`${pendingCleanupMetadataObjectSql()} || ${JSON.stringify({ + pendingCleanupInFlight: false, + pendingCleanupRetryAfterMs: Date.now() + (attempts + 1 >= PENDING_CLEANUP_SWEEP_ATTEMPT_CAP + ? 30 * 60_000 : Math.min(30 * 60_000, Math.max(30_000, backoffMs))), + })}::jsonb`, + }).where(and(eq(environmentLeases.id, lease.id), + sql`${environmentLeases.metadata}->>'pendingCleanupAttemptId' = ${claimed}`)); + if (lease.heartbeatRunId) { + // Delivery failure must not revert successful provider cleanup. A new + // message can still use the persisted receipt on its next admission. + await (async () => { + await acknowledgeRemoteStop(lease.heartbeatRunId!, lease.companyId); + const run = await getRun(lease.heartbeatRunId!); + if (run) await resumeRemoteStopComments(run); + })().catch(() => logger.warn({ leaseId: lease.id }, "could not reconsider messages after cleanup retry")); + } + } + + return { swept: rows.length, destroyed, capped }; + } + + async function markNativeOwnershipUnverified( + run: typeof heartbeatRuns.$inferSelect, + evidence: { + reason: + | "live_process_identifier" + | "observed_owner_unverified" + | "adopted_runner_authentication_timeout" + | "native_chat_workspace_scope_mismatch"; + processPidAlive?: boolean; + processGroupAlive?: boolean; + }, + ) { + const durableOwnershipHold = + evidence.reason === "adopted_runner_authentication_timeout" || + evidence.reason === "native_chat_workspace_scope_mismatch"; + if ( + run.errorCode === NATIVE_OWNERSHIP_UNVERIFIED_ERROR_CODE && + run.error === NATIVE_OWNERSHIP_UNVERIFIED_MESSAGE && + (!durableOwnershipHold || isNativeRunnerOwnershipHeld(run)) + ) + return run; + const blockedStatus = run.status === "failed" ? "failed" : "running"; + const blockedWrite = await setRunStatusFromLive( + run.id, + blockedStatus, + [blockedStatus], + { + error: NATIVE_OWNERSHIP_UNVERIFIED_MESSAGE, + errorCode: NATIVE_OWNERSHIP_UNVERIFIED_ERROR_CODE, + ...(durableOwnershipHold + ? { + nativePhase: "terminal_failure", + nativePhaseUpdatedAt: new Date(), + } + : {}), + }, + ); + if (!blockedWrite.updated || !blockedWrite.run) { + return blockedWrite.run ?? run; + } + const blocked = blockedWrite.run; + await appendRunEvent(blocked, { + eventType: "lifecycle", + stream: "system", + level: "warn", + message: NATIVE_OWNERSHIP_UNVERIFIED_MESSAGE, + payload: { + reason: evidence.reason, + ...(evidence.processPidAlive === true ? { processPidAlive: true } : {}), + ...(evidence.processGroupAlive === true + ? { processGroupAlive: true } + : {}), + }, + }); + return blocked; + } + + async function settleRecoveredNativeWorkspace(input: { + runId: string; + companyId: string; + agentId: string; + succeeded: boolean; + }) { + const settledRun = await getRun(input.runId); + const workspaceSyncReference = readNativeWorkspaceSyncReference( + parseObject(settledRun?.runnerProfileJson).nativeWorkspaceSync, + ); + await releaseEnvironmentLeasesForRun({ + runId: input.runId, + companyId: input.companyId, + agentId: input.agentId, + status: settledRun?.status, + failureReason: settledRun?.error ?? undefined, + providerResourceDisposition: input.succeeded && (!parseObject(settledRun?.resultJson).workspaceExportRetry || workspaceSyncReference?.resourceDisposition === "destroy") + ? (workspaceSyncReference?.resourceDisposition ?? "stop_and_retain") + : "stop_and_retain", + }); + await releaseRuntimeServicesForRun(input.runId).catch(() => undefined); + await finalizeAgentStatus( + input.agentId, + input.succeeded ? "succeeded" : "failed", + input.succeeded + ? null + : (settledRun?.error ?? "native_workspace_sync_out_failed"), + { + wasFirstHeartbeat: settledRun + ? timerClaimWasFirstHeartbeat(settledRun) + : undefined, + }, + ).catch(() => undefined); + } + + function scheduleRetainedNativeSessionCleanup() { + // The per-database sweep joins startup and periodic callers. One bounded + // control-only repair must not hold up unrelated provider ingress or the + // entire orphan reaper, but shutdown must still await its physical owner. + const cleanup = reconcileRetainedNativeSessionCleanups(db, { + cleanup: (input) => reconcileRetainedNativeSessionCleanup(db, input), + onError: (error, runId) => { + logger.warn( + { err: error, runId }, + "retained native session cleanup failed", + ); + }, + }) + .then(() => undefined) + .catch((error) => { + logger.warn({ err: error }, "retained native cleanup discovery failed"); + }) + // The bounded maintenance attempt may fail before an already-started + // database callback settles. Keep shutdown ownership until the original + // operations finish; their timeout cannot authorize closing the database. + .finally(() => drainRetainedRunnerdMaintenanceOperations()); + activeRunExecutionPromises.add(cleanup); + void cleanup.finally(() => activeRunExecutionPromises.delete(cleanup)); + } + + async function reapOrphanedRuns(opts?: { staleThresholdMs?: number }) { + const staleThresholdMs = opts?.staleThresholdMs ?? 0; + const now = new Date(); + // Recovery never launches a provider or infers stopped ownership from + // terminal status. Uncaptured local copies require durable stop evidence. + await instructionCopies.recoverStopped().catch(error => { + logger.warn({ err: error }, "failed to recover stopped instruction copies"); + }); + await instructionCopies.recoverCaptured().catch(error => { + logger.warn({ err: error }, "failed to retry captured instruction revisions"); + }); + + // Complete persisted native results before generic orphan recovery. The + // reconciler reads the durable workspace barrier and persisted runtime + // mode, never the current feature flag. + await reconcileNativeFinalizations(db, undefined, { + environmentRuntime, + onWorkspaceSettled: settleRecoveredNativeWorkspace, + }).catch((error) => { + logger.warn( + { err: error }, + "failed to reconcile persisted native finalizations before orphan reaping", + ); + }); + scheduleRetainedNativeSessionCleanup(); + await dispatchPendingNativeStatusWakeups().catch((error) => { + logger.warn( + { err: error }, + "failed to dispatch persisted native status wake intents before orphan reaping", + ); + }); + + // A retryable native run can retain process identifiers from the failed + // attempt. Inspect them before the recovery claim: a live identifier is + // unowned and blocks recovery, while identifiers that are all dead can be + // cleared with a compare-and-set so the explicit retryable failure becomes + // claimable in this same sweep. + const retryableNativeProcesses = await db + .select({ run: heartbeatRuns }) + .from(heartbeatRuns) + .innerJoin( + nativeRunFinalizations, + eq(nativeRunFinalizations.runId, heartbeatRuns.id), + ) + .where( + and( + inArray(heartbeatRuns.status, ["running", "failed"]), + eq(heartbeatRuns.runtimeMode, "native"), + eq(nativeRunFinalizations.phase, "retryable_failure"), + isNull(nativeRunFinalizations.resultId), + ), + ); + const claimableNativeRunIds = new Set(); + for (const { run } of retryableNativeProcesses) { + if (isNativeRunnerOwnershipHeld(run)) continue; + if (!run.processPid && !run.processGroupId) { + claimableNativeRunIds.add(run.id); + continue; + } + const processPidAlive = + !!run.processPid && isProcessAlive(run.processPid); + const processGroupAlive = + !!run.processGroupId && isProcessGroupAlive(run.processGroupId); + if (processPidAlive || processGroupAlive) { + await markNativeOwnershipUnverified(run, { + reason: "live_process_identifier", + processPidAlive, + processGroupAlive, + }); + continue; + } + const cleared = await db.transaction(async tx => { + const cleared = await tx + .update(heartbeatRuns) + .set({ + processPid: null, + processGroupId: null, + processStartedAt: null, + updatedAt: now, + }) + .where( + and( + eq(heartbeatRuns.id, run.id), + eq(heartbeatRuns.runtimeMode, "native"), + run.processPid === null + ? isNull(heartbeatRuns.processPid) + : eq(heartbeatRuns.processPid, run.processPid), + run.processGroupId === null + ? isNull(heartbeatRuns.processGroupId) + : eq(heartbeatRuns.processGroupId, run.processGroupId), + run.processStartedAt === null + ? isNull(heartbeatRuns.processStartedAt) + : eq(heartbeatRuns.processStartedAt, run.processStartedAt), + ), + ) + .returning({ id: heartbeatRuns.id }) + .then((rows) => rows[0] ?? null); + if (cleared) await recordNativeLocalProcessStop(tx as unknown as Db, run); + return cleared; + }); + if (cleared) claimableNativeRunIds.add(cleared.id); + } + + // An explicit result-less retryable failure resumes on the original run. + // The database lease is claimed before dispatch so concurrent service + // instances cannot open competing recoveries; executeRun receives the exact + // claimed owner. Expired `observed` ownership never enters this set. + const nativeResumeClaims = + claimableNativeRunIds.size === 0 + ? [] + : await dispatchNativeSessionResumptions({ + db, + runnerInstanceId: + runtimeEnv.PAPERCLIP_INSTANCE_ID?.trim() || "paperclip-heartbeat", + now, + runIds: [...claimableNativeRunIds], + dispatch: (claim) => { + const execution = executeRun(claim.runId, { + nativeLeaseOwner: claim.leaseOwner, + }).catch((error) => { + logger.error( + { err: error, runId: claim.runId }, + "persisted native session resume failed", + ); + }); + activeRunExecutionPromises.add(execution); + void execution.finally(() => + activeRunExecutionPromises.delete(execution), + ); + }, + }).catch((error) => { + logger.warn( + { err: error }, + "failed to claim persisted native session resumptions", + ); + return []; + }); + const resumedRunIds = new Set( + nativeResumeClaims.map((claim) => claim.runId), + ); + + // A terminal issue transition writes this intent in the same transaction + // that closes the question's task, even when its card is retained. Consume + // it before generic orphan recovery so a restart preserves cancellation. + const cancellationRequests = await db + .select({ + id: heartbeatRuns.id, + contextSnapshot: heartbeatRuns.contextSnapshot, + }) + .from(heartbeatRuns) + .where( + and( + inArray(heartbeatRuns.status, [ + ...CANCELLABLE_HEARTBEAT_RUN_STATUSES, + ]), + sql`${heartbeatRuns.contextSnapshot} -> ${NATIVE_QUESTION_CANCELLATION_CONTEXT_KEY} is not null`, + ), + ); + for (const request of cancellationRequests) { + const marker = parseObject( + parseObject(request.contextSnapshot)[ + NATIVE_QUESTION_CANCELLATION_CONTEXT_KEY + ], + ); + const issueId = readNonEmptyString(marker.issueId); + const issueStatus = readNonEmptyString(marker.issueStatus); + const interactionId = readNonEmptyString(marker.interactionId); + const kind = readNonEmptyString(marker.kind); + const reason = + kind === "interaction_withdrawn" + ? "Question withdrawn while waiting for operator input" + : kind === "interaction_cancelled" + ? "Cancelled while waiting for operator input" + : "Task closed while waiting for operator input"; + try { + await cancelRunInternal(request.id, reason, { + resultJson: { + ...(kind === "interaction_withdrawn" && interactionId + ? { withdrawnInteractionId: interactionId } + : {}), + ...(kind === "interaction_cancelled" && interactionId + ? { cancelledInteractionId: interactionId } + : {}), + ...((!kind || kind === "issue_terminal") && issueStatus + ? { cancelledByIssueStatus: issueStatus } + : {}), + ...(issueId ? { cancelledIssueId: issueId } : {}), + }, + }); + } catch (err) { + // Keep the marker intact for the next startup/periodic sweep. + logger.warn( + { err, runId: request.id }, + "native question cancellation recovery attempt failed", + ); + } + } + + // Find all runs stuck in "running" state (queued runs are legitimately waiting; resumeQueuedRuns handles them) + const activeRuns = await db + .select({ + run: heartbeatRuns, + adapterType: agents.adapterType, + adapterConfig: agents.adapterConfig, + nativeCoordinatorPhase: nativeRunFinalizations.phase, + nativeRecoveryState: nativeRunFinalizations.recoveryState, + nativeControllerBootId: nativeRunFinalizations.controllerBootId, + nativeControllerPid: nativeRunFinalizations.controllerPid, + nativeControllerProcessStartedAt: + nativeRunFinalizations.controllerProcessStartedAt, + nativeControllerLeaseExpiresAt: nativeRunFinalizations.leaseExpiresAt, + }) + .from(heartbeatRuns) + .innerJoin(agents, eq(heartbeatRuns.agentId, agents.id)) + .leftJoin( + nativeRunFinalizations, + eq(nativeRunFinalizations.runId, heartbeatRuns.id), + ) + .where(eq(heartbeatRuns.status, "running")); + + const monitorIssueIds = [ + ...new Set( + activeRuns.flatMap(({ run }) => { + const runContext = parseObject(run.contextSnapshot); + if (readNonEmptyString(runContext.wakeReason) !== "issue_monitor_due") + return []; + const issueId = readNonEmptyString(runContext.issueId); + return issueId ? [issueId] : []; + }), + ), + ]; + const monitorIssues = + monitorIssueIds.length > 0 + ? await db + .select({ + id: issues.id, + companyId: issues.companyId, + monitorNextCheckAt: issues.monitorNextCheckAt, + }) + .from(issues) + .where(inArray(issues.id, monitorIssueIds)) + : []; + const monitorNextCheckAtByIssue = new Map( + monitorIssues.map((issue) => [ + `${issue.companyId}:${issue.id}`, + issue.monitorNextCheckAt, + ]), + ); + + const reaped: string[] = []; + const currentNativeController = await currentNativeControllerIdentity(); + + for (const { + run, + adapterType, + adapterConfig, + nativeCoordinatorPhase, + nativeRecoveryState, + nativeControllerBootId, + nativeControllerPid, + nativeControllerProcessStartedAt, + nativeControllerLeaseExpiresAt, + } of activeRuns) { + // Authentication timeout requires an explicit ownership resolution, not + // repeated reattachment or a process-gone guess on subsequent sweeps. + if (isNativeRunnerOwnershipHeld(run)) continue; + const nativeRun = run.runtimeMode === "native"; + const nativeProcessPidAlive = + nativeRun && !!run.processPid && isProcessAlive(run.processPid); + const nativeProcessGroupAlive = + nativeRun && + !!run.processGroupId && + isProcessGroupAlive(run.processGroupId); + const coordinatorOwnedByCurrentController = + nativeRun && + nativeControllerBootId === currentNativeController.bootId && + nativeControllerPid === currentNativeController.pid && + nativeControllerProcessStartedAt?.getTime() === + currentNativeController.processStartedAt.getTime() && + !!nativeControllerLeaseExpiresAt && + nativeControllerLeaseExpiresAt.getTime() > now.getTime(); + const locallyTracked = + runningProcesses.has(run.id) || + activeRunExecutions.has(run.id) || + coordinatorOwnedByCurrentController; + if ( + nativeRun && + ([ + "awaiting_evidence", + "awaiting_runner_reattach", + "resuming_session", + "bootstrap_incomplete", + ].includes(nativeRecoveryState ?? "") || + nativeCoordinatorPhase === "retryable_failure") + ) { + continue; + } + const observedOwnerUnverified = + nativeRun && + (nativeCoordinatorPhase === "observed" || + (nativeCoordinatorPhase === null && + run.nativePhase === "observed")) && + !resumedRunIds.has(run.id) && + !locallyTracked; + // Persisted numeric process identifiers prove only that some process is + // alive, not that Paperclip still owns it. Likewise an observed native + // coordinator without a live in-process execution has no durable proof + // that its prior provider owner stopped. Keep both cases running but + // blocked: never signal, finalize, or retry them automatically. This gate + // intentionally precedes resumedRunIds so a claim cannot bypass the + // ownership check. + if ( + !locallyTracked && + (nativeProcessPidAlive || + nativeProcessGroupAlive || + observedOwnerUnverified) + ) { + await markNativeOwnershipUnverified(run, { + reason: + nativeProcessPidAlive || nativeProcessGroupAlive + ? "live_process_identifier" + : "observed_owner_unverified", + processPidAlive: nativeProcessPidAlive, + processGroupAlive: nativeProcessGroupAlive, + }); + continue; + } + if (resumedRunIds.has(run.id)) continue; + if (locallyTracked) continue; + if (await hasLiveLegacyController(db, run)) continue; + + // Apply staleness threshold to avoid false positives + if (staleThresholdMs > 0) { + const refTime = run.updatedAt ? new Date(run.updatedAt).getTime() : 0; + if (now.getTime() - refTime < staleThresholdMs) continue; + } + + const currentAdapterTracksLocalChild = + isTrackedLocalChildProcessAdapter(adapterType); + const tracksLegacyLocalChild = + run.runtimeMode !== "native" && currentAdapterTracksLocalChild; + // Native runner processes also persist child metadata, but they must not + // inherit legacy retry or termination authority. Use their PID/group only + // for a read-only liveness check so a lost in-memory handle cannot cause + // overlapping provider/tool execution while that child is still alive. + const checksPersistedChildLiveness = + currentAdapterTracksLocalChild || run.runtimeMode === "native"; + const processPidAlive = + checksPersistedChildLiveness && + run.processPid && + isProcessAlive(run.processPid); + const processGroupAlive = + checksPersistedChildLiveness && + run.processGroupId && + isProcessGroupAlive(run.processGroupId); + if ( + (processPidAlive || processGroupAlive) && + readHotRestartAdoptionMetadata(parseObject(run.resultJson)) + ) { + continue; + } + if (processPidAlive || processGroupAlive) { + if (run.errorCode !== DETACHED_PROCESS_ERROR_CODE) { + const detachedMessage = processPidAlive + ? `Lost in-memory process handle, but child pid ${run.processPid} is still alive` + : `Lost in-memory process handle, but persisted process group ${run.processGroupId} is still alive`; + const detachedRun = await setRunStatus(run.id, "running", { + error: detachedMessage, + errorCode: DETACHED_PROCESS_ERROR_CODE, + }); + if (detachedRun) { + await appendRunEvent(detachedRun, { + eventType: "lifecycle", + stream: "system", + level: "warn", + message: detachedMessage, + payload: { + processPid: run.processPid ?? null, + processGroupId: run.processGroupId ?? null, + ownedProcessHandle: false, + }, + }); + } + } + continue; + } + + const runContext = parseObject(run.contextSnapshot); + const monitorIssueId = readNonEmptyString(runContext.issueId); + const monitorNextCheckAt = monitorIssueId + ? monitorNextCheckAtByIssue.get(`${run.companyId}:${monitorIssueId}`) + : undefined; + const monitorDispatchLostWithoutFutureWake = + readNonEmptyString(runContext.wakeReason) === "issue_monitor_due" && + monitorNextCheckAt !== undefined && + (!monitorNextCheckAt || monitorNextCheckAt.getTime() <= now.getTime()); + const shouldRetry = + (run.processLossRetryCount ?? 0) < 1 && + ((tracksLegacyLocalChild && + (!!run.processPid || !!run.processGroupId)) || + monitorDispatchLostWithoutFutureWake); + if (!(await revokeExpiredLegacyController(db, run))) continue; + const baseMessage = buildProcessLossMessage(run); + const processLossDiagnostic = buildProcessLossDiagnostic({ + run, + nowMs: Date.now(), + observerStartedAtMs: performance.timeOrigin, + checksPersistedChildLiveness, + retryEligible: shouldRetry, + }); + const conversationContinuationEligible = await runUsedConversationAdapter(db, run); + + const failureWrite = await setRunStatusFromLive( + run.id, + "failed", + ["running"], + { + error: shouldRetry ? `${baseMessage}; retrying once` : baseMessage, + errorCode: "process_lost", + finishedAt: now, + resultJson: (() => { + const result = mergeRunStopMetadataForAgent( + { adapterType, adapterConfig }, + "failed", + { + conversationContinuationEligible, + resultJson: { ...parseObject(run.resultJson), processLossDiagnostic }, + errorCode: "process_lost", + errorMessage: shouldRetry + ? `${baseMessage}; retrying once` + : baseMessage, + }, + ); + return result; + })(), + }, + ); + if (!failureWrite.updated || !failureWrite.run) continue; + let finalizedRun: typeof heartbeatRuns.$inferSelect | null = + failureWrite.run; + await setWakeupStatus(run.wakeupRequestId, "failed", { + finishedAt: now, + error: shouldRetry ? `${baseMessage}; retrying once` : baseMessage, + }); + if (!finalizedRun) finalizedRun = await getRun(run.id); + if (!finalizedRun) continue; + finalizedRun = + (await classifyAndPersistRunLiveness( + finalizedRun, + parseObject(finalizedRun.resultJson), + )) ?? finalizedRun; + await releaseEnvironmentLeasesForRun({ + runId: finalizedRun.id, + companyId: finalizedRun.companyId, + agentId: finalizedRun.agentId, + status: finalizedRun.status, + failureReason: finalizedRun.error ?? undefined, + }); + + let retriedRun: typeof heartbeatRuns.$inferSelect | null = null; + const retryAgent = await getAgent(run.agentId); + if (shouldRetry) { + if (retryAgent) { + retriedRun = await enqueueProcessLossRetry( + finalizedRun, + retryAgent, + now, + ); + } + } else if (retryAgent) { + const scheduled = + await scheduleInteractionContinuationInfrastructureRetryIfEligible( + finalizedRun, + retryAgent, + ); + retriedRun = scheduled?.outcome === "scheduled" ? scheduled.run : null; + } + + if (!retriedRun) { + await releaseIssueExecutionAndPromote(finalizedRun); + } + + await appendRunEvent(finalizedRun, { + eventType: "lifecycle", + stream: "system", + level: "error", + message: shouldRetry + ? `${baseMessage}; queued retry ${retriedRun?.id ?? ""}`.trim() + : baseMessage, + payload: { + ...(run.processPid ? { processPid: run.processPid } : {}), + ...(run.processGroupId ? { processGroupId: run.processGroupId } : {}), + ...(retriedRun ? { retryRunId: retriedRun.id } : {}), + }, + }); + + await finalizeAgentStatus(run.agentId, "failed", baseMessage, { + wasFirstHeartbeat: timerClaimWasFirstHeartbeat(run), + }); + await startNextQueuedRunForAgent(run.agentId); + runningProcesses.delete(run.id); + reaped.push(run.id); + } + + if (reaped.length > 0) { + logger.warn( + { reapedCount: reaped.length, runIds: reaped }, + "reaped orphaned heartbeat runs", + ); + } + + // Recover an active lease whose run already ended before the same-tick + // pending_cleanup sweep, so this tick can stop the recovered sandbox. + // Isolate the sweep so its failure never hides the reaper result. + try { + const orphanedActiveLeaseSweep = await sweepOrphanedActiveLeases({ + backoffMs: staleThresholdMs, + }); + if (orphanedActiveLeaseSweep.recovered > 0) { + logger.warn( + { recovered: orphanedActiveLeaseSweep.recovered }, + "recovered orphaned active environment leases", + ); + } + } catch { + // Log a constant errorKind only. The exception can carry a credential in + // its name, code, message, cause, or stack, so the sweep never reads it. + logger.error( + { errorKind: ORPHANED_ACTIVE_LEASE_SWEEP_ERROR_KIND }, + "orphaned active environment lease sweep failed", + ); + } + + // Retry stranded pending_cleanup leases on the same tick. Isolate the sweep + // so its failure never hides the reaper result. The backoff equals the + // reaper staleness threshold. + try { + const sweep = await sweepPendingCleanupLeases({ + backoffMs: staleThresholdMs, + }); + if (sweep.destroyed > 0 || sweep.capped > 0) { + logger.warn( + { + destroyed: sweep.destroyed, + capped: sweep.capped, + swept: sweep.swept, + }, + "swept pending_cleanup environment leases", + ); + } + } catch { + // Log a constant errorKind only. The exception can carry a credential in + // its name, code, message, cause, or stack, so the sweep never reads it. + logger.error( + { errorKind: PENDING_CLEANUP_SWEEP_ERROR_KIND }, + "pending_cleanup lease sweep failed", + ); + } + + return { reaped: reaped.length, runIds: reaped }; + } + + return { + sweepPendingCleanupLeases, + markNativeOwnershipUnverified, + prepareHotRestartShutdown, + reconcileHotRestartAdoption, + recoverNativeRunsAfterRestart, + reapOrphanedRuns, + sweepOrphanedActiveLeases, + drainRunningRunsForShutdown, + }; +} diff --git a/server/src/services/public-mcp/events.ts b/server/src/services/public-mcp/events.ts index d2cb45d4f70..39c1ce07043 100644 --- a/server/src/services/public-mcp/events.ts +++ b/server/src/services/public-mcp/events.ts @@ -212,7 +212,12 @@ export function createPublicMcpEvents(db: Db, oauth: PublicMcpOAuth, api: ApiDis async function enqueue(s: Subscription) { if (s.bindingId) { if (!options.enableDotRunner) return; - const [b] = await db.select().from(dotAgentBindings).where(and(eq(dotAgentBindings.id, s.bindingId), eq(dotAgentBindings.companyId, s.companyId), isNull(dotAgentBindings.revokedAt))); + const [binding] = await db.select().from(dotAgentBindings).where(and(eq(dotAgentBindings.id, s.bindingId), eq(dotAgentBindings.companyId, s.companyId), isNull(dotAgentBindings.revokedAt))); + if (!binding) return; + // SQL idempotency makes this safe across restarts, replicas and callback + // renewals. Reload before filtering delivery against the newly issued test. + await dotRunnerBroker(db).challenge(binding.companyId, binding.agentId, { automatic: true, bindingId: binding.id }); + const [b] = await db.select().from(dotAgentBindings).where(and(eq(dotAgentBindings.id, binding.id), isNull(dotAgentBindings.revokedAt))); if (!b) return; // Materialize only references to newly recorded task input. This does not steer // an external provider or create execution authority; the current run reads its history. diff --git a/server/src/services/public-mcp/oauth.ts b/server/src/services/public-mcp/oauth.ts index f5a3dc6d994..ec878f35a41 100644 --- a/server/src/services/public-mcp/oauth.ts +++ b/server/src/services/public-mcp/oauth.ts @@ -126,7 +126,8 @@ export function createPublicMcpOAuth(db: Db, config: PublicMcpConfig, options: { const refresh = grant.scopes.includes("offline_access") ? secret("pcmcp_rt_") : null; await tx.insert(mcpOauthTokens).values([ { grantId: grant.id, tokenHash: hashMcpSecret(access), kind: "access", expiresAt: new Date(Date.now() + accessLifetime) }, - ...(refresh ? [{ grantId: grant.id, tokenHash: hashMcpSecret(refresh), kind: "refresh" as const, expiresAt: new Date(Date.now() + refreshLifetime) }] : []), + ...(refresh ? [{ grantId: grant.id, tokenHash: hashMcpSecret(refresh), kind: "refresh" as const, + expiresAt: agentConnection && grant.purpose === "agent" ? null : new Date(Date.now() + refreshLifetime) }] : []), ]); return { access_token: access, token_type: "Bearer", expires_in: accessLifetime / 1000, @@ -440,7 +441,7 @@ export function createPublicMcpOAuth(db: Db, config: PublicMcpConfig, options: { if (!access.user || !membership || membership.membershipRole === "viewer" || !company || company.status === "archived") throw invalidGrant(); return { company: { id: company.id, name: company.name }, agent: { id: agent.id, name: agent.name }, permissions: "Start and accept work as this agent, coordinate permitted tasks and people, read assigned skills, and use assigned app tools. Reading assigned task attachment contents sends those contents to OpenAI and requires the agent’s separate attachment setting. Workspace files and sandboxed commands require the agent’s separate workspace setting. No board account or other-company access.", - accessDuration: "Ongoing until revoked. Reconnect after 30 days without refreshing the connection.", + accessDuration: "Ongoing until revoked. This connection does not expire from inactivity.", pairingExpiresAt: binding.pairingExpiresAt!.toISOString() }; }); }, @@ -515,7 +516,9 @@ export function createPublicMcpOAuth(db: Db, config: PublicMcpConfig, options: { }); return null; } - if (token.expiresAt <= new Date()) return null; + // Only agent connections support refresh tokens without an inactivity limit. + // Access tokens still expire, refresh still rotates, and replay still revokes. + if (token.expiresAt ? token.expiresAt <= new Date() : !agentConnection || grant.purpose !== "agent") return null; await actorForGrant(grant, tx as unknown as Db); if (input.scope !== undefined && input.scope !== grant.scopes.join(" ")) { throw new McpOAuthError("invalid_scope", "Refresh cannot change the consented scopes; reconnect instead."); diff --git a/ui/public/brands/adapters/openai-dot.README.md b/ui/public/brands/adapters/openai-dot.README.md new file mode 100644 index 00000000000..a4e283ba2f2 --- /dev/null +++ b/ui/public/brands/adapters/openai-dot.README.md @@ -0,0 +1,7 @@ +# Dot mark + +`openai-dot.svg` is the unmodified Dot ring mark linked by OpenAI's public [Introducing dots](https://openai.com/index/introducing-dots/) announcement. + +Source: https://images.ctfassets.net/kftzwdyauwt9/KKSjto3MtJguvsLQsM1Bp/1704a6937d22b1bb3cac38dc5f43f9df/dots-o.svg + +Retrieved 2026-10-08. Used to identify the Dot provider in Paperclip setup UI. Hermes uses the existing `hermesagent.svg` and `hermesagent-dark.svg` assets. diff --git a/ui/public/brands/adapters/openai-dot.svg b/ui/public/brands/adapters/openai-dot.svg new file mode 100644 index 00000000000..d3c9a81f234 --- /dev/null +++ b/ui/public/brands/adapters/openai-dot.svg @@ -0,0 +1,3 @@ + + + diff --git a/ui/src/api/agents.ts b/ui/src/api/agents.ts index f3b6fef3e57..b3dd11025c0 100644 --- a/ui/src/api/agents.ts +++ b/ui/src/api/agents.ts @@ -110,6 +110,8 @@ function agentPath(id: string, companyId?: string, suffix = "") { } export const agentsApi = { + setAvatar: (companyId: string, agentId: string, imageBase64: string | null) => + api.put<{ agentId: string; appearance: import("@paperclipai/shared").AgentAppearance; avatarUrl: string }>(`/companies/${companyId}/agents/${agentId}/avatar`, { imageBase64 }), getIdentity: (id: string, companyId?: string) => api.get(agentPath(id, companyId, "/identity")), adoptAiConnection: (agentId: string, interactionId: string, connectionId: string, companyId: string) => diff --git a/ui/src/api/dotInvitations.ts b/ui/src/api/dotInvitations.ts new file mode 100644 index 00000000000..5237b704013 --- /dev/null +++ b/ui/src/api/dotInvitations.ts @@ -0,0 +1,11 @@ +import { api } from "./client"; + +import type { DotInvitation, DotConnection, DotPairing } from "@paperclipai/shared"; +export type { DotBinding, DotInvitation, DotConnection, DotPairing } from "@paperclipai/shared"; +const path = (companyId: string, agentId: string) => `/companies/${companyId}/agents/${agentId}/dot-binding`; +export const dotInvitationsApi = { + create: (companyId: string) => api.post(`/companies/${companyId}/dot-invitations`, {}), + connection: (companyId: string, agentId: string, signal?: AbortSignal) => api.get(path(companyId, agentId), { signal }), + pair: (companyId: string, agentId: string, replaceBindingId?: string) => api.post(path(companyId, agentId), { replaceBindingId }), + retry: (companyId: string, agentId: string, bindingId: string) => api.post(path(companyId, agentId) + "/event-test", { bindingId }), +}; diff --git a/ui/src/components/AdapterMark.tsx b/ui/src/components/AdapterMark.tsx index 8d293cbbacc..cc700dc541f 100644 --- a/ui/src/components/AdapterMark.tsx +++ b/ui/src/components/AdapterMark.tsx @@ -2,6 +2,7 @@ import { getAdapterDisplay } from "@/adapters/adapter-display-registry"; import { cn } from "@/lib/utils"; const brandMarks: Record = { + openai_dot: { src: "/brands/adapters/openai-dot.svg" }, claude_local: { src: "/brands/claude-color.svg" }, codex_local: { src: "/brands/codex-color.svg" }, gemini_local: { src: "/brands/adapters/gemini-color.svg" }, diff --git a/ui/src/components/AgentAvatar.test.tsx b/ui/src/components/AgentAvatar.test.tsx new file mode 100644 index 00000000000..c4d5f9ac731 --- /dev/null +++ b/ui/src/components/AgentAvatar.test.tsx @@ -0,0 +1,27 @@ +// @vitest-environment jsdom +import { act } from "react"; +import { createRoot } from "react-dom/client"; +import { expect, it } from "vitest"; +import { appearanceForPalette } from "@paperclipai/shared"; +import { AgentAvatar } from "./AgentAvatar"; +import { AgentCharacter } from "./AgentCharacter"; + +Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }); +it("shows the uploaded image in small and animated-character surfaces, then returns to the palette on reset", async () => { + const base = appearanceForPalette("deep-tide"); + const appearance = { ...base, customAvatarAssetId: "22222222-2222-4222-8222-222222222222" }; + const container = document.createElement("div"); + const root = createRoot(container); + try { + await act(async () => root.render(<>)); + for (const image of container.querySelectorAll("img")) { + expect(image.getAttribute("src")).toBe("/api/assets/22222222-2222-4222-8222-222222222222/content"); + expect(image.hasAttribute("srcset")).toBe(false); + expect(image.parentElement?.classList.contains("invisible")).toBe(false); + } + expect(container.querySelectorAll("img")).toHaveLength(2); + expect(container.querySelector("canvas")).toBeNull(); + await act(async () => root.render()); + expect(container.querySelector("img")?.getAttribute("src")).toContain("/api/agent-avatars/cap-v1/deep-tide/"); + } finally { await act(async () => root.unmount()); } +}); diff --git a/ui/src/components/AgentAvatar.tsx b/ui/src/components/AgentAvatar.tsx index 8ab2d166243..0866c2bf490 100644 --- a/ui/src/components/AgentAvatar.tsx +++ b/ui/src/components/AgentAvatar.tsx @@ -27,7 +27,7 @@ export function AgentAvatar({ agent, appearance, size = 24, name, label, pose = {failedUrl === src ? {deriveInitials(name ?? agent?.name ?? "Agent")} : - setFailedUrl(src)} />} ); diff --git a/ui/src/components/AgentCharacter.tsx b/ui/src/components/AgentCharacter.tsx index d85bd2f650a..7b267333220 100644 --- a/ui/src/components/AgentCharacter.tsx +++ b/ui/src/components/AgentCharacter.tsx @@ -20,7 +20,7 @@ export function AgentCharacter({ agent, appearance, size = 256, state = "idle", const slotId = useRef(Symbol("agent-character")); const owner = useSyncExternalStore(characterSlot.subscribe, characterSlot.getSnapshot, () => null); const [visible, setVisible] = useState(false), [reduced, setReduced] = useState(true), [failed, setFailed] = useState(false), [ready, setReady] = useState(false); - const active = visible && !reduced && !failed && motion === "auto" && state !== "rest"; + const active = !identity.customAvatarAssetId && visible && !reduced && !failed && motion === "auto" && state !== "rest"; useEffect(() => { if (typeof matchMedia !== "function" || typeof IntersectionObserver !== "function") return; const media = matchMedia("(prefers-reduced-motion: reduce)"); @@ -57,7 +57,7 @@ export function AgentCharacter({ agent, appearance, size = 256, state = "idle", }, [identity, muted, state, ready]); return - + ; } diff --git a/ui/src/components/AgentSetupPrompt.tsx b/ui/src/components/AgentSetupPrompt.tsx index df025d7eb3a..f130a91dcbe 100644 --- a/ui/src/components/AgentSetupPrompt.tsx +++ b/ui/src/components/AgentSetupPrompt.tsx @@ -22,15 +22,17 @@ export interface AgentSetupPromptProps { /** Carry over the clipboard result when generating a prompt already copied it. */ initialCopyStatus?: "idle" | "copied" | "failed"; onCopied?: () => void; + /** Brand a handoff for one recipient; omit for the general agent logo stack. */ + agent?: { name: string; src: string; className?: string }; } -const agents = [ +const defaultAgents = [ { name: "Codex", src: "/brands/codex-color.svg", className: "" }, { name: "ChatGPT", src: "/brands/apps/openai.svg", className: "dark:invert" }, { name: "Claude", src: "/brands/claude-color.svg", className: "" }, ]; -function AgentLogos({ ref, hidden }: { ref: Ref; hidden: boolean }) { +function AgentLogos({ ref, hidden, agents }: { ref: Ref; hidden: boolean; agents: NonNullable[] }) { return ( - +
-
+
{status === "failed" ? (