mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-17 21:34:48 +01:00
fix(queue): let board users discard agent-authored queued messages (#21458)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The task composer holds messages that an agent has not consumed yet. > - A board operator needs to remove an agent-authored pending message before it starts more work. > - The queue currently grants discard only to the human author, so these messages have a disabled trash button and the API rejects the board user. > - This change derives the board discard permission in the queue snapshot and uses that same permission under the existing issue lock. > - The route checks task access before it changes the queue. The benefit is a working discard action with the existing company, privacy, revision, and dispatch guards. ## Linked Issues or Issue Description Fixes #15464. Supersedes #15465 with an independent implementation and red/green regression evidence. Thanks to @MMTE for identifying the gap and proposing a fix. Related: #18958 addresses deletion of comments that have already been delivered; this change covers pending queue entries. ## What Changed - Queue responses grant board users discard permission for agent-authored messages. Editing and other human authors' messages retain their existing permissions. - The discard use case honors the actor-specific permission rebuilt under the queue lock. Author agents keep their existing cancellation path. - The board discard route checks private-task access before deletion. The denial for a non-author agent now points to the board action instead of saying that no board action exists. - Tests cover queue states, cancellation of an empty continuation, persistence, queue linkage, audit attribution, private-task denial, and cross-company denial. The API reference describes the supported action. ## Verification - Red before the fix: the two snapshot regressions returned `canDiscard: false`; the discard regression threw `QueuedCommentMutationForbiddenError`. The route regressions also caught the disabled permission, missing private-task guard, and stale agent denial text. - Green after the fix: 30 queue snapshot and use-case tests; all five focused route regressions with real disposable Postgres; six Postgres adapter tests; 42 existing queue UI tests. - Server typecheck: `cd server && node scripts/typecheck-layers.mjs` passes. `node scripts/check-module-boundaries.mjs` and `git diff --check` pass. - The [complete PR workflow](https://github.com/paperclipai/paperclip/actions/runs/43484735280) passes on head `164200602828e23f01a8b209ff954821c5e14e9a`. [Greptile reports 5/5](https://github.com/paperclipai/paperclip/pull/21458#issuecomment-6861824451) on that same head with no open review threads. - Local scope: the 83 focused snapshot, use-case, route, adapter, and UI checks pass. The existing queue UI suite has 42 tests. The new route cases use real disposable Postgres and verify the resulting database state after reload. - Additional local full-suite attempt: 174 tests passed and 13 approval-related tests failed with cleanup timeouts, Postgres deadlocks, and duplicate-prefix errors after cleanup failed. The first failure, `queues request_confirmation resolution while its legacy source run is still running`, also fails on unchanged base code with the same 30-second `afterEach` and `afterAll` timeouts. This broader local run is not counted as a pass. No test timeout or assertion was weakened. CI supplies the broad passing result for the committed head. - `node scripts/local-verify.mjs --explain` returned exit 2 because the API documentation is a global CI input; all of its required CI lanes passed. The initial adapter attempt could not initialize local Postgres under the sandbox; the same six checks passed with local-process access. The initial cross-company fixture was corrected to use a distinct company prefix. ## Risks - This grants board operators a new action on agent-authored pending messages. The route must pass company membership and private-task access checks; the mutation retains its transaction, revision, and dispatch protections. - No schema or migration is required. The UI uses its existing discard control and error handling. - The staging task was inspected to confirm the cause. No staging data was deleted, and a deployed UI retest is not claimed by these local and CI checks. ## Model Used - OpenAI Codex, GPT-6, with reasoning, repository inspection, tool use, and code execution. The exact runtime model ID and context limit are not exposed in this session. ## 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 — the focused regression, adapter, and UI checks listed above; the additional broad local cleanup failure is documented separately - [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
8b7b2a0701
commit
08341ea134
8 files changed
+164
-14
No files matched your search
@@ -395,7 +395,7 @@ describe("discardQueuedComment", () => {
|
||||
|
||||
it("rejects a discard from an actor who did not author the comment", async () => {
|
||||
const locked = lockedState({ queue: queueSnapshot({ entries: [
|
||||
entry({ comment: commentFixture({ authorUserId: "user-2", authorAgentId: null }) }),
|
||||
entry({ canDiscard: false, comment: commentFixture({ authorUserId: "user-2", authorAgentId: null }) }),
|
||||
] }) });
|
||||
const discardQueuedComment = createDiscardQueuedComment({ issueLock: createFakeIssueLock(locked, createFakeTransaction()) });
|
||||
|
||||
@@ -411,6 +411,46 @@ describe("discardQueuedComment", () => {
|
||||
).rejects.toBeInstanceOf(QueuedCommentMutationForbiddenError);
|
||||
});
|
||||
|
||||
it("lets the board discard an agent message allowed by the locked queue and cancels its empty continuation", async () => {
|
||||
const locked = lockedState({
|
||||
state: "queued",
|
||||
queueRun: runRow(),
|
||||
queue: queueSnapshot({ state: "queued", entries: [entry({
|
||||
comment: commentFixture({ authorType: "agent", authorUserId: null, authorAgentId: "agent-1" }),
|
||||
canEdit: false,
|
||||
canDiscard: true,
|
||||
})] }),
|
||||
});
|
||||
const transaction = createFakeTransaction();
|
||||
const discard = createDiscardQueuedComment({ issueLock: createFakeIssueLock(locked, transaction) });
|
||||
|
||||
const result = await discard({ issue: ISSUE, actor: USER_ACTOR, commentId: "comment-1",
|
||||
queueId: "wake-1", revision: "rev-1", now: new Date(), logActivity: true });
|
||||
|
||||
expect(transaction.deleteComment).toHaveBeenCalledWith({ issueId: ISSUE.id, commentId: "comment-1" });
|
||||
expect(transaction.cancelWake).toHaveBeenCalledOnce();
|
||||
expect(result.cancelledRun).toEqual({ id: "run-1" });
|
||||
expect(transaction.logActivity).toHaveBeenCalledWith(expect.objectContaining({
|
||||
actorType: "user", actorId: USER_ACTOR.actorId, action: "issue.queued_comment_discarded",
|
||||
}));
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ actor: USER_ACTOR, canDiscard: false },
|
||||
{ actor: AGENT_ACTOR, canDiscard: true },
|
||||
])("does not grant a non-author $actor.actorType a denied or board-only discard", async ({ actor, canDiscard }) => {
|
||||
const locked = lockedState({ queue: queueSnapshot({ entries: [entry({
|
||||
comment: commentFixture({ authorType: "agent", authorUserId: null, authorAgentId: "agent-2" }),
|
||||
canDiscard,
|
||||
})] }) });
|
||||
const transaction = createFakeTransaction();
|
||||
const discard = createDiscardQueuedComment({ issueLock: createFakeIssueLock(locked, transaction) });
|
||||
|
||||
await expect(discard({ issue: ISSUE, actor, commentId: "comment-1", queueId: "wake-1",
|
||||
revision: "rev-1", now: new Date() })).rejects.toBeInstanceOf(QueuedCommentMutationForbiddenError);
|
||||
expect(transaction.deleteComment).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("authorizes an agent actor discarding its own queued message", async () => {
|
||||
const locked = lockedState({
|
||||
queue: queueSnapshot({ entries: [
|
||||
|
||||
@@ -263,7 +263,7 @@ export function createDiscardQueuedComment(deps: { issueLock: QueuedCommentIssue
|
||||
authorAgentId: entry.comment.authorAgentId,
|
||||
authorUserId: entry.comment.authorUserId,
|
||||
});
|
||||
if (!owns) {
|
||||
if (!owns && !(input.actor.actorType === "user" && entry.canDiscard)) {
|
||||
throw new QueuedCommentMutationForbiddenError("Only the queued message author can discard it");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user