fix(issues): address review feedback and rolling-deploy scope safety

Remove issues_conversation_scope_check from migration 0511 so rolling deploys and existing test fixtures do not fail 1:1 chat writes, convert the backfill into bounded 1,000-row primary-key cursor batches, honor issues.scope in client applyIssueFilters, preserve nonIdleSlackIssueCondition on scope-filtered queries, drop duplicate IssueFilters in shared, and document scope in docs/api/issues.md.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-11-30 18:11:55 -06:00
1 parent a6b22197b4
commit 926c67e569
13 files changed
+77 -78

No files matched your search

+7 -1
View File
@@ -35,6 +35,7 @@ Query parameters:
| Param | Description |
|-------|-------------|
| `status` | Filter by status (comma-separated: `todo,in_progress`) |
| `scope` | Filter by surface scope (`board`, `channel`, `agent`, `chat`); accepts comma-separated values (`scope=board,agent`) or repeated query parameters (`scope=board&scope=agent`). Invalid values return `400` |
| `assigneeAgentId` | Filter by assigned agent |
| `projectId` | Filter by project |
| `view` | `index`: collection rows without bodies or diagnostics; `rows`: rows with diagnostic summaries but no bodies; `compact`: existing board row contract |
@@ -48,6 +49,8 @@ Query parameters:
Results sorted by priority.
Default exclusions: when `scope`, `q`, and `ids` are omitted, `GET /api/companies/{companyId}/issues` and `GET /api/companies/{companyId}/issues/count` exclude `chat` and `channel` scoped issues. `GET /api/companies/{companyId}/issues/count` accepts the same `scope` query syntax and returns `400` on invalid values.
`inboxArchive` requires a signed-in board user. The filter cannot be combined
with `attention`. When `inboxArchive` is present, each result includes the
boolean `isArchivedForMe`. Paperclip uses the same activity rules as Mine to
@@ -94,6 +97,7 @@ POST /api/companies/{companyId}/issues
"title": "Implement caching layer",
"description": "Add Redis caching for hot queries",
"status": "todo",
"scope": "board",
"priority": "high",
"assigneeAgentId": "{agentId}",
"parentId": "{parentIssueId}",
@@ -102,6 +106,8 @@ POST /api/companies/{companyId}/issues
}
```
`scope` is optional (`board` | `channel` | `agent` | `chat`). When omitted, the server derives `chat` for 1:1 conversations, `board` for manual human issues and explicit chat-to-board handoffs, and `agent` for agent-created or automated issues. Passing a non-`chat` scope on a 1:1 conversation returns `422`.
## Update Issue
```
@@ -115,7 +121,7 @@ Headers: X-Paperclip-Run-Id: {runId}
The optional `comment` field adds a comment in the same call. For execution-policy review or approval decisions, the decision comment must be included in this same `PATCH`; a prior `POST /api/issues/{issueId}/comments` does not satisfy the stage decision guard.
Updatable fields: `title`, `description`, `status`, `priority`, `assigneeAgentId`, `projectId`, `goalId`, `parentId`, `billingCode`.
Updatable fields: `title`, `description`, `status`, `scope`, `priority`, `assigneeAgentId`, `projectId`, `goalId`, `parentId`, `billingCode`. Existing 1:1 conversation issues must keep `scope: "chat"` (other values return `422`).
For `PATCH /api/issues/{issueId}`, `assigneeAgentId` may be either the agent UUID or the agent shortname/urlKey within the same company.
+1 -1
View File
@@ -923,7 +923,7 @@ const MIGRATIONS_WITH_TOP_LEVEL_STATEMENTS = new Set([
"0505_nice_rawhide_kid.sql",
"0508_normal_riptide.sql",
"0507_special_kang.sql",
"0511_pale_kronos.sql",
"0511_simple_the_hunter.sql",
]);
async function applyPendingMigrationsManually(
@@ -1,10 +0,0 @@
-- paperclip:migration-compat online_compatible: adds issues.scope with constant default 'board', backfills existing conversation and agent-created rows, adds check constraints as NOT VALID then validates under SHARE UPDATE EXCLUSIVE, and builds both scope indexes CONCURRENTLY. Every statement is idempotent because this file runs outside a transaction.
ALTER TABLE "issues" ADD COLUMN IF NOT EXISTS "scope" text DEFAULT 'board' NOT NULL;--> statement-breakpoint
UPDATE "issues" SET "scope" = 'chat' WHERE "conversation_agent_id" IS NOT NULL AND "scope" <> 'chat';--> statement-breakpoint
UPDATE "issues" SET "scope" = 'agent' WHERE "conversation_agent_id" IS NULL AND "scope" = 'board' AND ("created_by_agent_id" IS NOT NULL OR "origin_kind" NOT IN ('manual', 'onboarding_first_task'));--> statement-breakpoint
ALTER TABLE "issues" DROP CONSTRAINT IF EXISTS "issues_scope_check", ADD CONSTRAINT "issues_scope_check" CHECK ("issues"."scope" in ('board', 'channel', 'agent', 'chat')) NOT VALID;--> statement-breakpoint
ALTER TABLE "issues" VALIDATE CONSTRAINT "issues_scope_check";--> statement-breakpoint
ALTER TABLE "issues" DROP CONSTRAINT IF EXISTS "issues_conversation_scope_check", ADD CONSTRAINT "issues_conversation_scope_check" CHECK (("issues"."conversation_agent_id" is null) or ("issues"."scope" = 'chat')) NOT VALID;--> statement-breakpoint
ALTER TABLE "issues" VALIDATE CONSTRAINT "issues_conversation_scope_check";--> statement-breakpoint
CREATE INDEX CONCURRENTLY IF NOT EXISTS "issues_company_scope_status_idx" ON "issues" USING btree ("company_id","scope","status");--> statement-breakpoint
CREATE INDEX CONCURRENTLY IF NOT EXISTS "issues_company_scope_updated_idx" ON "issues" USING btree ("company_id","scope","updated_at");
@@ -0,0 +1,43 @@
-- paperclip:migration-compat online_compatible: adds issues.scope with constant default 'board', backfills existing conversation and agent-created rows in bounded primary-key batches, adds issues_scope_check as NOT VALID then validates under SHARE UPDATE EXCLUSIVE, and builds both scope indexes CONCURRENTLY. Every statement is idempotent because this file runs outside a transaction; issues_conversation_scope_check is deferred to a follow-up contract migration so rolling deploys with previous writers do not fail 1:1 chat inserts.
ALTER TABLE "issues" ADD COLUMN IF NOT EXISTS "scope" text DEFAULT 'board' NOT NULL;--> statement-breakpoint
DO $$
DECLARE
cursor_id uuid := '00000000-0000-0000-0000-000000000000';
batch_ids uuid[];
BEGIN
LOOP
SELECT ARRAY(
SELECT "id"
FROM "issues"
WHERE "id" > cursor_id
ORDER BY "id"
LIMIT 1000
) INTO batch_ids;
EXIT WHEN coalesce(cardinality(batch_ids), 0) = 0;
UPDATE "issues" AS i
SET "scope" = CASE
WHEN i."conversation_agent_id" IS NOT NULL THEN 'chat'
WHEN i."scope" = 'board'
AND (i."created_by_agent_id" IS NOT NULL OR i."origin_kind" NOT IN ('manual', 'onboarding_first_task'))
THEN 'agent'
ELSE i."scope"
END
WHERE i."id" = ANY(batch_ids)
AND (
(i."conversation_agent_id" IS NOT NULL AND i."scope" <> 'chat')
OR (
i."conversation_agent_id" IS NULL
AND i."scope" = 'board'
AND (i."created_by_agent_id" IS NOT NULL OR i."origin_kind" NOT IN ('manual', 'onboarding_first_task'))
)
);
cursor_id := batch_ids[cardinality(batch_ids)];
COMMIT;
END LOOP;
END $$;--> statement-breakpoint
ALTER TABLE "issues" DROP CONSTRAINT IF EXISTS "issues_scope_check", ADD CONSTRAINT "issues_scope_check" CHECK ("issues"."scope" in ('board', 'channel', 'agent', 'chat')) NOT VALID;--> statement-breakpoint
ALTER TABLE "issues" VALIDATE CONSTRAINT "issues_scope_check";--> statement-breakpoint
CREATE INDEX CONCURRENTLY IF NOT EXISTS "issues_company_scope_status_idx" ON "issues" USING btree ("company_id","scope","status");--> statement-breakpoint
CREATE INDEX CONCURRENTLY IF NOT EXISTS "issues_company_scope_updated_idx" ON "issues" USING btree ("company_id","scope","updated_at");
+1 -5
View File
@@ -1,5 +1,5 @@
{
"id": "2cc13a19-e7a2-4561-be70-733611070aa0",
"id": "081cc14c-5504-4a93-8b4c-e5945f3936c3",
"prevId": "bd7706ab-f548-43f0-9dbb-4f1d52d9c135",
"version": "7",
"dialect": "postgresql",
@@ -45617,10 +45617,6 @@
"name": "issues_scope_check",
"value": "\"issues\".\"scope\" in ('board', 'channel', 'agent', 'chat')"
},
"issues_conversation_scope_check": {
"name": "issues_conversation_scope_check",
"value": "(\"issues\".\"conversation_agent_id\" is null) or (\"issues\".\"scope\" = 'chat')"
},
"issues_conversation_identity_check": {
"name": "issues_conversation_identity_check",
"value": "(\n \"issues\".\"conversation_agent_id\" is null and \"issues\".\"conversation_user_id\" is null and \"issues\".\"conversation_state\" is null\n ) or (\n \"issues\".\"conversation_agent_id\" is not null and \"issues\".\"conversation_user_id\" is not null\n and \"issues\".\"assignee_agent_id\" = \"issues\".\"conversation_agent_id\" and \"issues\".\"assignee_agent_id\" is not null\n and \"issues\".\"assignee_user_id\" is null and \"issues\".\"conversation_state\" is not null\n and \"issues\".\"conversation_state\" in ('active', 'waiting')\n and \"issues\".\"status\" not in ('done', 'cancelled')\n )"
+2 -2
View File
@@ -3568,8 +3568,8 @@
{
"idx": 511,
"version": "7",
"when": 1796071038991,
"tag": "0511_pale_kronos",
"when": 1796075417353,
"tag": "0511_simple_the_hunter",
"breakpoints": true
}
]
-1
View File
@@ -104,7 +104,6 @@ export const issues = pgTable(
(table) => ({
visibilityCheck: check("issues_visibility_check", sql`${table.visibility} in ('open', 'private')`),
scopeCheck: check("issues_scope_check", sql`${table.scope} in ('board', 'channel', 'agent', 'chat')`),
conversationScopeCheck: check("issues_conversation_scope_check", sql`(${table.conversationAgentId} is null) or (${table.scope} = 'chat')`),
conversationIdentityIdx: uniqueIndex("issues_conversation_identity_idx").on(table.companyId, table.conversationAgentId, table.conversationUserId),
conversationIdentityCheck: check("issues_conversation_identity_check", sql`(
${table.conversationAgentId} is null and ${table.conversationUserId} is null and ${table.conversationState} is null
-1
View File
@@ -1195,7 +1195,6 @@ export type {
ExternalObjectSummary,
ExternalObjectSummaryItem,
CompactIssue,
IssueFilters,
IssueInboxArchiveFilter,
IssueSummary,
Issue,
-1
View File
@@ -736,7 +736,6 @@ export type {
} from "./external-object.js";
export type {
CompactIssue,
IssueFilters,
IssueInboxArchiveFilter,
IssueSummary,
Issue,
-47
View File
@@ -1051,53 +1051,6 @@ export interface Issue {
export type IssueInboxArchiveFilter = "include" | "archived";
export interface IssueFilters {
attention?: "blocked";
status?: string | readonly string[];
displayStatus?: string | readonly string[];
scope?: IssueScope | string;
assigneeAgentId?: string | null;
participantAgentId?: string;
issueIds?: string[];
listProjection?: "index" | "rows";
parentIds?: string[];
oneChildPerParent?: boolean;
assigneeUserId?: string;
touchedByUserId?: string;
touchedCandidates?: "participation";
inboxArchivedByUserId?: string;
inboxArchive?: { userId: string; mode: IssueInboxArchiveFilter };
unreadForUserId?: string;
readStateForUserId?: string;
projectId?: string;
workspaceId?: string;
executionWorkspaceId?: string;
parentId?: string;
descendantOf?: string;
createdFromIssueId?: string;
labelId?: string;
originKind?: string;
originKindPrefix?: string;
originId?: string;
includeAgentCreatedTasks?: boolean;
creationVisibilityUserId?: string;
includeRoutineExecutions?: boolean;
excludeRoutineExecutions?: boolean;
includePluginOperations?: boolean;
includeBlockedBy?: boolean;
includeBlockedInboxAttention?: boolean;
includeLiveDescendantSummary?: boolean;
hasPlanDocument?: boolean;
q?: string;
limit?: number;
offset?: number;
sortField?: "updated" | "created" | "id";
afterId?: string;
sortDir?: "asc" | "desc";
updatedSince?: string;
updatedBefore?: string;
}
export type CompactIssue = Pick<
Issue,
| "listProjection"
+8 -8
View File
@@ -8648,11 +8648,11 @@ export function issueService(db: Db) {
conditions.push(scopes.length === 1 ? eq(issues.scope, scopes[0]!) : inArray(issues.scope, scopes));
} else if (!filters?.q?.trim() && !filters?.issueIds) {
conditions.push(nonChatAndChannelIssueCondition());
// Explicit child navigation includes waiting chat tasks, just like
// readable-child counts. Ambient lists still omit idle conversations.
if (!filters?.parentId && !filters?.parentIds && !filters?.descendantOf && !filters?.touchedByUserId && !filters?.unreadForUserId && !filters?.inboxArchivedByUserId && inboxArchive?.mode !== "archived") {
conditions.push(nonIdleSlackIssueCondition());
}
}
// Explicit child navigation includes waiting chat tasks, just like
// readable-child counts. Ambient lists still omit idle conversations.
if (!filters?.q?.trim() && !filters?.issueIds && !scopes.includes("channel") && !scopes.includes("chat") && !filters?.parentId && !filters?.parentIds && !filters?.descendantOf && !filters?.touchedByUserId && !filters?.unreadForUserId && !filters?.inboxArchivedByUserId && inboxArchive?.mode !== "archived") {
conditions.push(nonIdleSlackIssueCondition());
}
if (filters?.afterId) conditions.push(gt(issues.id, filters.afterId));
if (filters?.readCondition) conditions.push(filters.readCondition);
@@ -9060,9 +9060,9 @@ export function issueService(db: Db) {
conditions.push(scopes.length === 1 ? eq(issues.scope, scopes[0]!) : inArray(issues.scope, scopes));
} else if (!filters?.q?.trim() && !filters?.issueIds) {
conditions.push(nonChatAndChannelIssueCondition());
if (!filters?.parentId && !filters?.parentIds && !filters?.touchedByUserId && !filters?.unreadForUserId && !filters?.inboxArchivedByUserId) {
conditions.push(nonIdleSlackIssueCondition());
}
}
if (!filters?.q?.trim() && !filters?.issueIds && !scopes.includes("channel") && !scopes.includes("chat") && !filters?.parentId && !filters?.parentIds && !filters?.touchedByUserId && !filters?.unreadForUserId && !filters?.inboxArchivedByUserId) {
conditions.push(nonIdleSlackIssueCondition());
}
const displayStatuses = parseStatusFilter(filters?.displayStatus);
if (displayStatuses.length) conditions.push(inArray(issueDisplayStatusSql(), displayStatuses));
+9
View File
@@ -94,6 +94,15 @@ describe("issue filters", () => {
expect(countActiveIssueFilters({ ...defaultIssueFilterState, showAgentCreatedTasks: true }, true)).toBe(1);
});
it("keeps agent-created board handoffs visible by default when scope is set", () => {
const handoff = makeIssue({ id: "handoff", scope: "board", createdByAgentId: "agent" });
const agentTask = makeIssue({ id: "agent-scoped", scope: "agent", createdByAgentId: "agent" });
const channelPost = makeIssue({ id: "channel", scope: "channel", createdByUserId: "person" });
const issues = [handoff, agentTask, channelPost];
expect(applyIssueFilters(issues, defaultIssueFilterState, null, true).map((issue) => issue.id)).toEqual(["handoff"]);
expect(applyIssueFilters(issues, { ...defaultIssueFilterState, showAgentCreatedTasks: true }, null, true).map((issue) => issue.id)).toEqual(["handoff", "agent-scoped", "channel"]);
});
it("selects only routine executions even when automatic tasks are hidden", () => {
const routine = makeIssue({ id: "routine", originKind: "routine_execution", createdByUserId: "person" });
const issues = [makeIssue({ id: "manual", createdByUserId: "person" }), routine,
+6 -1
View File
@@ -377,6 +377,11 @@ export function issueCreationRequestFilters(
: {};
}
export function isBoardVisibleByDefault(issue: Issue): boolean {
if (issue.scope !== undefined) return issue.scope === "board";
return !isAgentCreatedIssue(issue);
}
export function applyIssueFilters(
issues: Issue[],
state: IssueFilterState,
@@ -403,7 +408,7 @@ export function applyIssueFilters(
result = result.filter((issue) => issue.originKind === "routine_execution");
}
if (enableAgentCreatedVisibilityFilter && !state.showAgentCreatedTasks && !state.routineTasksOnly) {
result = result.filter((issue) => !isAgentCreatedIssue(issue));
result = result.filter(isBoardVisibleByDefault);
}
if (state.statuses.length > 0) result = result.filter((issue) => state.statuses.includes(issue.displayStatus ?? issue.status));
if (state.priorities.length > 0) result = result.filter((issue) => state.priorities.includes(issue.priority));