mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-28 21:46:15 +01:00
fix(ui): confirm cancellation from monitor cards (#15735)
## Thinking Path > - Paperclip helps people manage AI agents and their tasks. > - A task monitor schedules a later agent check. > - The monitor card shows when that check will run. > - The card has no direct control to cancel the monitor. > - This change adds an X button and a confirmation dialog. > - The operator can stop the scheduled check from the card. ## Linked Issues or Issue Description **What existing behavior does this improve?** The monitor card on the task page. **Current behavior** The operator must open task properties to clear a monitor. **Proposed behavior** Select the X in the top right of the card. Select Keep monitor to leave the schedule in place. Select Cancel monitor to remove the scheduled check. **Reason and benefit** The operator can cancel the monitor where its schedule is shown. Confirmation helps prevent an accidental cancellation. **Breaking changes** None. The change uses the existing task update API. ## What Changed - Add an accessible X button at the top right of the monitor card. - Confirm cancellation before the task update. - Keep the dialog open with an error if the update fails. - Preserve the other execution policy settings and refresh the task after success. - Reject stale policy writes under the task row lock with an optional expectedExecutionPolicy snapshot. - Document the snapshot field and add a database test for stale cancellation. - Restrict snapshot requests to policy-only edits before execution-control actions. - Add seven route tests for rejected mixed requests and absent policy updates. - Keep automatic retry waits separate from monitor cancellation. - Add component and task page tests. ## Verification - `pnpm check:token-gates` passed. - Monitor banner and task page tests passed: 199 tests. A targeted database test and seven route tests also passed. - UI typecheck and production build passed. - Open a task with a scheduled monitor. Select X, then Keep monitor. The schedule must remain. - Select X, then Cancel monitor. The card must disappear after the update. - Local full build reached the Rust runner build but could not complete because Cargo is absent. CI must verify the full build. - Full repository typecheck, build, test suites, and E2E checks passed in CI for the final commit. Local full checks were limited by missing Cargo and workspace memory. ## Risks - Low risk. Cancellation uses the existing company access checks and activity log. - A cancelled monitor no longer wakes the agent. The dialog explains this effect. ## Model Used OpenAI Codex, GPT-6. The runtime does not expose a more specific model ID or context window size. Used code editing, shell commands, and tests. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
c27ee928b0
commit
5cf90417d6
12 files changed
+227
-3
No files matched your search
@@ -272,6 +272,34 @@ describe("issue execution policy routes", () => {
|
||||
await loadAppModules();
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ status: "done" },
|
||||
{ status: "cancelled" },
|
||||
{ assigneeAgentId: "33333333-3333-4333-8333-333333333333" },
|
||||
{ assigneeUserId: "operator" },
|
||||
{ interrupt: true },
|
||||
{ comment: "Continue now" },
|
||||
])("rejects mixed snapshot-guarded updates before execution side effects: %j", async (controlFields) => {
|
||||
const res = await request(await createApp({ type: "board", source: "local_implicit", userId: "local-board" }))
|
||||
.patch("/api/issues/aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa")
|
||||
.send({ expectedExecutionPolicy: null, executionPolicy: null, ...controlFields });
|
||||
expect(res.status).toBe(422);
|
||||
expect(res.body.error).toContain("policy-only");
|
||||
expect(mockIssueService.getById).not.toHaveBeenCalled();
|
||||
expect(mockIssueService.update).not.toHaveBeenCalled();
|
||||
expect(mockRunnerGoalService.act).not.toHaveBeenCalled();
|
||||
expect(mockHeartbeatService.cancelRun).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects a snapshot without a policy update", async () => {
|
||||
const res = await request(await createApp({ type: "board", source: "local_implicit", userId: "local-board" }))
|
||||
.patch("/api/issues/aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa")
|
||||
.send({ expectedExecutionPolicy: null });
|
||||
expect(res.status).toBe(422);
|
||||
expect(mockIssueService.getById).not.toHaveBeenCalled();
|
||||
expect(mockIssueService.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reauthorizes a terminal verdict against the review policy held under the update lock", async () => {
|
||||
const issue = {
|
||||
id: "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa",
|
||||
|
||||
@@ -540,6 +540,34 @@ describeEmbeddedPostgres("issueService.list participantAgentId", () => {
|
||||
await ensureIssueRelationsTable(db);
|
||||
}, 20_000);
|
||||
|
||||
it("rejects stale monitor cancellation under the task lock and preserves saved policy settings", async () => {
|
||||
const companyId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
await db.insert(companies).values({ id: companyId, name: "Monitor cancellation", issuePrefix: "MCL", requireBoardApprovalForNewAgents: false });
|
||||
const oldPolicy = {
|
||||
mode: "normal" as const, commentRequired: true, stages: [],
|
||||
monitor: { nextCheckAt: "2026-10-10T12:00:00.000Z", notes: "Check status", scheduledBy: "board" as const },
|
||||
};
|
||||
const savedPolicy = {
|
||||
...oldPolicy,
|
||||
stages: [{ type: "review" as const, approvalsNeeded: 1 as const, participants: [{ type: "user" as const, userId: "reviewer" }] }],
|
||||
maxReviewRounds: 4,
|
||||
authorizationPolicy: { assignmentPolicy: { mode: "protected" as const } },
|
||||
};
|
||||
await db.insert(issues).values({ id: issueId, companyId, title: "Monitored task", executionPolicy: oldPolicy });
|
||||
await svc.update(issueId, { executionPolicy: savedPolicy });
|
||||
const { monitor: _oldMonitor, ...staleCancellation } = oldPolicy;
|
||||
await expect(svc.update(issueId, { executionPolicy: staleCancellation, expectedExecutionPolicy: oldPolicy }))
|
||||
.rejects.toMatchObject({ status: 409 });
|
||||
expect((await svc.getById(issueId))?.executionPolicy).toEqual(savedPolicy);
|
||||
const { monitor: _savedMonitor, ...cancellation } = savedPolicy;
|
||||
await svc.update(issueId, { executionPolicy: cancellation, expectedExecutionPolicy: savedPolicy });
|
||||
expect((await svc.getById(issueId))?.executionPolicy).toEqual(cancellation);
|
||||
await expect(svc.update(issueId, { executionPolicy: null, expectedExecutionPolicy: null }))
|
||||
.rejects.toMatchObject({ status: 409 });
|
||||
expect((await svc.getById(issueId))?.executionPolicy).toEqual(cancellation);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await db.delete(issueComments);
|
||||
await db.delete(issueThreadInteractions);
|
||||
|
||||
@@ -13373,6 +13373,14 @@ export function issueRoutes(
|
||||
"/issues/:id",
|
||||
validateIssueMutationBody(updateIssueRouteSchema),
|
||||
async (req, res) => {
|
||||
// Snapshot-guarded writes are policy-only. Do not admit task-control
|
||||
// actions that can stop execution before the service takes its row lock.
|
||||
if (req.body.expectedExecutionPolicy !== undefined && (
|
||||
req.body.executionPolicy === undefined ||
|
||||
Object.keys(req.body).some((key) => key !== "executionPolicy" && key !== "expectedExecutionPolicy")
|
||||
)) {
|
||||
throw unprocessable("expectedExecutionPolicy requires a policy-only update");
|
||||
}
|
||||
const id = req.params.id as string;
|
||||
const existing = await getAccessibleResource(
|
||||
req,
|
||||
@@ -13459,6 +13467,7 @@ export function issueRoutes(
|
||||
interrupt: interruptRequested,
|
||||
deferWakeForGoal,
|
||||
hiddenAt: hiddenAtRaw,
|
||||
expectedExecutionPolicy,
|
||||
onBehalfOfUserId: _requestedOnBehalfOfUserId,
|
||||
...updateFields
|
||||
} = req.body;
|
||||
@@ -13856,6 +13865,13 @@ export function issueRoutes(
|
||||
lastDecisionId: decisionId,
|
||||
};
|
||||
}
|
||||
if (expectedExecutionPolicy !== undefined && (
|
||||
(transition.patch.status !== undefined && transition.patch.status !== existing.status) ||
|
||||
(transition.patch.assigneeAgentId !== undefined && transition.patch.assigneeAgentId !== existing.assigneeAgentId) ||
|
||||
(transition.patch.assigneeUserId !== undefined && transition.patch.assigneeUserId !== existing.assigneeUserId)
|
||||
)) {
|
||||
throw unprocessable("Snapshot-guarded policy updates cannot change task status or ownership");
|
||||
}
|
||||
Object.assign(updateFields, transition.patch);
|
||||
|
||||
const nextStatus = updateFields.status ?? existing.status;
|
||||
@@ -14178,6 +14194,7 @@ export function issueRoutes(
|
||||
const postCommitIssueActions: IssuePostCommitAction[] = [];
|
||||
const issueUpdateData = {
|
||||
...updateFields,
|
||||
expectedExecutionPolicy,
|
||||
actorAgentId: actor.agentId ?? null,
|
||||
actorRunId: actor.agentId ? actor.runId : null,
|
||||
actorRunStopId: actor.agentId && interruptedRunId === actor.runId ? issueMutationStopId : null,
|
||||
|
||||
@@ -9,6 +9,7 @@ import { createdFromIssueCondition } from "./issue-creation-origin.js";
|
||||
import { executionProjectionsForRuns } from "./execution-projection.js";
|
||||
import type { ExecutionProjection } from "@paperclipai/shared";
|
||||
import { Buffer } from "node:buffer";
|
||||
import { isDeepStrictEqual } from "node:util";
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import { isExplicitContinuationRetryClaim } from "./explicit-continuation-retry-claim.js";
|
||||
import { markdownToPlainText, parseMarkdown } from "chat";
|
||||
@@ -10833,6 +10834,7 @@ export function issueService(db: Db) {
|
||||
actorRunStopId?: string | null;
|
||||
actorUserId?: string | null;
|
||||
companyGuard?: string;
|
||||
expectedExecutionPolicy?: typeof issues.$inferInsert.executionPolicy;
|
||||
},
|
||||
dbOrTx: any = db,
|
||||
postCommitActivityPublications?: ActivityPublication[],
|
||||
@@ -10880,6 +10882,7 @@ export function issueService(db: Db) {
|
||||
actorRunStopId,
|
||||
actorUserId,
|
||||
companyGuard,
|
||||
expectedExecutionPolicy,
|
||||
...issueData
|
||||
} = data;
|
||||
// An explicit edit claims the title, even if it keeps the same text.
|
||||
@@ -11172,6 +11175,14 @@ export function issueService(db: Db) {
|
||||
.for("update")
|
||||
.then((rows: Array<typeof issues.$inferSelect>) => rows[0] ?? null);
|
||||
if (!receiptExisting) return null;
|
||||
if (expectedExecutionPolicy !== undefined && !isDeepStrictEqual(
|
||||
receiptExisting.executionPolicy ?? null,
|
||||
expectedExecutionPolicy,
|
||||
)) {
|
||||
throw conflict("The task execution settings changed. Try cancelling the monitor again.", {
|
||||
code: "execution_policy_changed",
|
||||
});
|
||||
}
|
||||
if (changesPrivacy) {
|
||||
const nextProjectId = issueData.projectId !== undefined ? issueData.projectId : receiptExisting.projectId;
|
||||
const [privacyProject] = nextProjectId ? await tx.select().from(projects)
|
||||
|
||||
Reference in new issue
Block a user