Fence shared workspace readers and preserve projectless chat admission

Retain root source and reader provenance, recheck publication access, keep plain agent transfers independent of repository discovery, and resolve organizational projects without filesystem sources.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-12 08:12:05 -05:00
1 parent c205ab39f0
commit e1863d4fe7
24 files changed
+1088 -58320

No files matched your search

@@ -553,9 +553,10 @@ export async function prepareCommandManagedRuntime(input: {
workspaceSeedCacheCompanyDirectory?: string;
workspaceBaseline?: DirectorySnapshot;
workspaceGitSnapshot?: GitWorkspaceSnapshot | null;
/** Without a Git snapshot, undefined discovers managed task repositories; [] keeps plain directories uninterpreted. */
workspaceRepositories?: NonNullable<GitWorkspaceSnapshot["repositories"]>;
workspaceExclude?: string[];
/** Plain persistent directories include all files, independent of Git and task cache exclusions. */
/** Includes ordinary ignored/cache files; plain directories also set workspaceGitSnapshot: null and workspaceRepositories: []. */
workspaceFileMode?: "all";
preserveAbsentOnRestore?: string[];
assets?: CommandManagedRuntimeAsset[];
@@ -1447,9 +1447,10 @@ export async function prepareAdapterExecutionTargetRuntime(input: {
workspaceSeedCacheCompanyDirectory?: string;
workspaceBaseline?: DirectorySnapshot;
workspaceGitSnapshot?: GitWorkspaceSnapshot | null;
/** Without a Git snapshot, undefined discovers managed task repositories; [] keeps plain directories uninterpreted. */
workspaceRepositories?: NonNullable<GitWorkspaceSnapshot["repositories"]>;
workspaceExclude?: string[];
/** Plain persistent directories include all files, independent of Git and task cache exclusions. */
/** Includes ordinary ignored/cache files; plain directories also set workspaceGitSnapshot: null and workspaceRepositories: []. */
workspaceFileMode?: "all";
preserveAbsentOnRestore?: string[];
assets?: AdapterManagedRuntimeAsset[];
@@ -1153,9 +1153,10 @@ export async function prepareSandboxManagedRuntime(input: {
/** Durable snapshots supplied when reconstructing an interrupted restore. */
workspaceBaseline?: DirectorySnapshot;
workspaceGitSnapshot?: GitWorkspaceSnapshot | null;
/** Without a Git snapshot, undefined discovers managed task repositories; [] keeps plain directories uninterpreted. */
workspaceRepositories?: NonNullable<GitWorkspaceSnapshot["repositories"]>;
workspaceExclude?: string[];
/** Plain persistent directories include all files, independent of Git and task cache exclusions. */
/** Includes ordinary ignored/cache files; plain directories also set workspaceGitSnapshot: null and workspaceRepositories: []. */
workspaceFileMode?: "all";
preserveAbsentOnRestore?: string[];
assets?: SandboxManagedRuntimeAsset[];
@@ -0,0 +1,16 @@
CREATE TABLE "execution_workspace_repository_access" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"company_id" uuid NOT NULL,
"root_key" text NOT NULL,
"canonical_cwd" text NOT NULL,
"kind" text NOT NULL,
"scope_id" uuid NOT NULL,
"issue_id" uuid,
"agent_id" uuid,
"responsible_user_id" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "execution_workspace_repository_access" ADD CONSTRAINT "execution_workspace_repository_access_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "execution_workspace_repository_access_scope_idx" ON "execution_workspace_repository_access" USING btree ("company_id","root_key","kind","scope_id");
File diff suppressed because it is too large. Load diff
@@ -1,6 +1,6 @@
{
"id": "5c09a14d-e323-49b1-b855-dcd12b974bcc",
"prevId": "0a93bc99-bf0c-4ea2-ab27-6043b6746cd5",
"id": "f57ad127-c146-413e-9456-1c7e02e0b7d8",
"prevId": "e39c907f-53d9-4fd9-bd06-e447b2b2cca6",
"version": "7",
"dialect": "postgresql",
"tables": {
@@ -3764,6 +3764,28 @@
"method": "btree",
"with": {}
},
"agent_wakeup_requests_question_response_history_idx": {
"name": "agent_wakeup_requests_question_response_history_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "idempotency_key",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"where": "\"agent_wakeup_requests\".\"idempotency_key\" LIKE 'question-response:%'",
"concurrently": true,
"method": "btree",
"with": {}
},
"agent_wakeup_requests_connection_intent_delivery_idempotency_uq": {
"name": "agent_wakeup_requests_connection_intent_delivery_idempotency_uq",
"columns": [
@@ -9836,6 +9858,12 @@
"notNull": true,
"default": false
},
"execution_defaults": {
"name": "execution_defaults",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"metadata": {
"name": "metadata",
"type": "jsonb",
@@ -10076,6 +10104,12 @@
"notNull": true,
"default": "''"
},
"execution_defaults": {
"name": "execution_defaults",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"allow_direct_messages": {
"name": "allow_direct_messages",
"type": "boolean",
@@ -19603,6 +19637,34 @@
"method": "btree",
"with": {}
},
"cost_events_data_quality_idx": {
"name": "cost_events_data_quality_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "occurred_at",
"isExpression": false,
"asc": false,
"nulls": "last"
},
{
"expression": "id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"where": "\"cost_events\".\"billing_type\" = 'unknown' or (\"cost_events\".\"cost_status\" = 'unpriced' and \"cost_events\".\"billing_type\" <> 'subscription_included')",
"concurrently": false,
"method": "btree",
"with": {}
},
"cost_events_company_occurred_idx": {
"name": "cost_events_company_occurred_idx",
"columns": [
@@ -26208,6 +26270,476 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.execution_workspace_repositories": {
"name": "execution_workspace_repositories",
"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
},
"execution_workspace_id": {
"name": "execution_workspace_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"requested_by_issue_id": {
"name": "requested_by_issue_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"repository_identity": {
"name": "repository_identity",
"type": "text",
"primaryKey": false,
"notNull": true
},
"catalog_repository_id": {
"name": "catalog_repository_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"repo_url": {
"name": "repo_url",
"type": "text",
"primaryKey": false,
"notNull": true
},
"relative_path": {
"name": "relative_path",
"type": "text",
"primaryKey": false,
"notNull": true
},
"requested_ref": {
"name": "requested_ref",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'HEAD'"
},
"pinned_commit": {
"name": "pinned_commit",
"type": "text",
"primaryKey": false,
"notNull": false
},
"branch_name": {
"name": "branch_name",
"type": "text",
"primaryKey": false,
"notNull": false
},
"request_key": {
"name": "request_key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"request_keys": {
"name": "request_keys",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'[]'::jsonb"
},
"state": {
"name": "state",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'pending'"
},
"failure_code": {
"name": "failure_code",
"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": {
"execution_workspace_repositories_identity_idx": {
"name": "execution_workspace_repositories_identity_idx",
"columns": [
{
"expression": "execution_workspace_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "repository_identity",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"execution_workspace_repositories_path_idx": {
"name": "execution_workspace_repositories_path_idx",
"columns": [
{
"expression": "execution_workspace_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "relative_path",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"execution_workspace_repositories_request_idx": {
"name": "execution_workspace_repositories_request_idx",
"columns": [
{
"expression": "execution_workspace_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "request_key",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"execution_workspace_repositories_company_workspace_idx": {
"name": "execution_workspace_repositories_company_workspace_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "execution_workspace_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"execution_workspace_repositories_company_id_companies_id_fk": {
"name": "execution_workspace_repositories_company_id_companies_id_fk",
"tableFrom": "execution_workspace_repositories",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"execution_workspace_repositories_execution_workspace_id_execution_workspaces_id_fk": {
"name": "execution_workspace_repositories_execution_workspace_id_execution_workspaces_id_fk",
"tableFrom": "execution_workspace_repositories",
"tableTo": "execution_workspaces",
"columnsFrom": [
"execution_workspace_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"execution_workspace_repositories_requested_by_issue_id_issues_id_fk": {
"name": "execution_workspace_repositories_requested_by_issue_id_issues_id_fk",
"tableFrom": "execution_workspace_repositories",
"tableTo": "issues",
"columnsFrom": [
"requested_by_issue_id"
],
"columnsTo": [
"id"
],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.execution_workspace_repository_access": {
"name": "execution_workspace_repository_access",
"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
},
"root_key": {
"name": "root_key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"canonical_cwd": {
"name": "canonical_cwd",
"type": "text",
"primaryKey": false,
"notNull": true
},
"kind": {
"name": "kind",
"type": "text",
"primaryKey": false,
"notNull": true
},
"scope_id": {
"name": "scope_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"issue_id": {
"name": "issue_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"agent_id": {
"name": "agent_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"responsible_user_id": {
"name": "responsible_user_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": {
"execution_workspace_repository_access_scope_idx": {
"name": "execution_workspace_repository_access_scope_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "root_key",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "kind",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "scope_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"execution_workspace_repository_access_company_id_companies_id_fk": {
"name": "execution_workspace_repository_access_company_id_companies_id_fk",
"tableFrom": "execution_workspace_repository_access",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.execution_workspace_repository_roots": {
"name": "execution_workspace_repository_roots",
"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
},
"canonical_cwd": {
"name": "canonical_cwd",
"type": "text",
"primaryKey": false,
"notNull": true
},
"root_key": {
"name": "root_key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"mode": {
"name": "mode",
"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": {
"execution_workspace_repository_roots_company_root_idx": {
"name": "execution_workspace_repository_roots_company_root_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "root_key",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"execution_workspace_repository_roots_company_id_companies_id_fk": {
"name": "execution_workspace_repository_roots_company_id_companies_id_fk",
"tableFrom": "execution_workspace_repository_roots",
"tableTo": "companies",
"columnsFrom": [
"company_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.execution_workspace_runtime_leases": {
"name": "execution_workspace_runtime_leases",
"schema": "",
@@ -26463,7 +26995,7 @@
"name": "project_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
"notNull": false
},
"project_workspace_id": {
"name": "project_workspace_id",
@@ -26741,7 +27273,7 @@
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onDelete": "restrict",
"onUpdate": "no action"
},
"execution_workspaces_project_workspace_id_project_workspaces_id_fk": {
@@ -30337,6 +30869,34 @@
"method": "btree",
"with": {}
},
"heartbeat_runs_cost_data_quality_idx": {
"name": "heartbeat_runs_cost_data_quality_idx",
"columns": [
{
"expression": "company_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "coalesce(\"finished_at\", \"created_at\") desc",
"asc": true,
"isExpression": true,
"nulls": "last"
},
{
"expression": "id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"where": "\"heartbeat_runs\".\"cost_accounting_pending\" = true and \"heartbeat_runs\".\"status\" in ('succeeded','failed','timed_out','cancelled','interrupted')",
"concurrently": false,
"method": "btree",
"with": {}
},
"heartbeat_runs_execution_status_delivery_idx": {
"name": "heartbeat_runs_execution_status_delivery_idx",
"columns": [
@@ -37501,6 +38061,25 @@
"primaryKey": false,
"notNull": false
},
"workspace_binding_revision": {
"name": "workspace_binding_revision",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"workspace_selection": {
"name": "workspace_selection",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"workspace_pending_selection": {
"name": "workspace_pending_selection",
"type": "jsonb",
"primaryKey": false,
"notNull": false
},
"execution_workspace_preference": {
"name": "execution_workspace_preference",
"type": "text",
+7
View File
@@ -2339,6 +2339,13 @@
"when": 1791807232294,
"tag": "0335_oval_screwball",
"breakpoints": true
},
{
"idx": 336,
"version": "7",
"when": 1791809240988,
"tag": "0336_chilly_hulk",
"breakpoints": true
}
]
}
@@ -0,0 +1,19 @@
import { pgTable, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
import { companies } from "./companies.js";
/** Sticky source/reader provenance; missing referenced owners fail closed instead of releasing root access. */
export const executionWorkspaceRepositoryAccess = pgTable("execution_workspace_repository_access", {
id: uuid("id").primaryKey().defaultRandom(),
companyId: uuid("company_id").notNull().references(() => companies.id, { onDelete: "cascade" }),
rootKey: text("root_key").notNull(),
canonicalCwd: text("canonical_cwd").notNull(),
kind: text("kind").$type<"source" | "reader">().notNull(),
scopeId: uuid("scope_id").notNull(),
issueId: uuid("issue_id"),
agentId: uuid("agent_id"),
responsibleUserId: text("responsible_user_id"),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
}, (table) => ({
scopeIdx: uniqueIndex("execution_workspace_repository_access_scope_idx").on(table.companyId, table.rootKey, table.kind, table.scopeId),
}));
+1
View File
@@ -247,4 +247,5 @@ export { aiSubscriptions, aiSubscriptionPrices, aiSubscriptionConnections } from
export { executionWorkspaceRepositories } from "./execution_workspace_repositories.js";
export { executionWorkspaceRepositoryRoots } from "./execution_workspace_repository_roots.js";
export { executionWorkspaceRepositoryAccess } from "./execution_workspace_repository_access.js";
export * from "./fast_responses.js";