Files
PaperClipAI/server/src/services/issue-thread-interaction-resolution.test.ts
T
DottaandPaperclip 10d0555189 fix(interactions): authorize resolvers consistently (#11376)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Issue interactions give agents and people a structured decision
record.
> - Resolver routes used different authorization rules.
> - Some routes blocked valid agents, including task watchdogs with
normal issue access.
> - The API did not show who could resolve a pending interaction.
> - This pull request gives every interaction kind one resolver policy
evaluator.
> - The benefit is a clear decision path with consistent governance and
company isolation.

## Linked Issues or Issue Description

Fixes: #8087

Refs: #7403

Related PR: #11082 proposes board-only confirmation rules. This change
keeps human-only review as an explicit policy.

**What happened?**

Agents could create issue interactions. Some resolver routes still
required board access.

This left valid agent confirmations pending. Task watchdogs could see
the same problem without board identity.

**Expected behavior**

Every interaction kind must use one resolver policy contract.

The contract must support `anyone`, `not_creator`, and `human_only`. It
must also apply all normal governance controls.

**Steps to reproduce**

1. Create a `request_confirmation` interaction as an agent.
2. Resolve it with another authorized agent.
3. Observe the board-only denial.

**Paperclip version or commit**

The problem exists on `master` before this change.

**Deployment mode**

Local development with `pnpm dev`.

## What Changed

- Add canonical policies for `anyone`, `not_creator`, and `human_only`.
- Use one server evaluator for every interaction kind.
- Apply named addressees, company limits, review rules, and task
watchdog scope.
- Charge cross-issue resolutions to the existing per-run action limit.
- Return the effective resolver audience in attention and interaction
data.
- Show the audience, governance choices, and denial reasons in the board
UI.
- Add telemetry, API documents, product documents, and regression
fixtures.
- Add migration provenance for safe legacy behavior.
- Make migration `0218` safe for complete replays and partial prior
runs.

## Product Rules

- An interaction records a response. It does not grant authority for the
next action.
- `anyone` lets any authorized issue participant respond.
- `not_creator` requires a responder other than the interaction creator.
- `human_only` requires an authorized person.
- A named addressee, company policy, or governed action can narrow the
audience.
- These controls cannot widen the audience.
- A task watchdog uses the same rules as an ordinary agent.
- A task watchdog does not receive board authority.
- An agent resolution on another issue uses the shared cross-issue
action limit.
- Legacy pending interactions keep their earlier restrictions.
- The UI shows the effective audience and a permanent denial reason.

## Verification

- `pnpm --filter @paperclipai/db check:migrations`
- `pnpm --filter @paperclipai/db typecheck`
- `pnpm exec vitest run
packages/db/src/issue-thread-interaction-resolver-policy-migration.test.ts`
- The focused PostgreSQL test applies migration `0218` twice.
- The test also completes a partial prior run and preserves existing
provenance.
- The latest GitHub head has 29 successful checks.
- The opt-in Storybook visual check skipped as expected.
- Greptile reports 5/5 with no open comments.

## Risks

- New interaction writes use `anyone` by default.
- Callers must select `not_creator` or `human_only` when they need
stricter review.
- Legacy pending interactions keep the old creator and human
restrictions.
- Migration `0218` fills only missing provenance fields during recovery.
- Cross-issue resolutions can reach the existing action limit.
- The shared evaluator affects every interaction kind.
- Route, service, database, shared contract, and UI tests cover these
rules.

> This work matches the Agent Reviews and Approvals direction in
`ROADMAP.md`. It does not duplicate a planned item.

## Model Used

OpenAI Codex, GPT-5. The runtime does not expose the exact deployment ID
or context window.

The agent used reasoning, repository tools, shell commands, and test
execution.

## 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 linked public issues or described the issue with the
required labels
- [x] I have not referenced internal Paperclip issues or links
- [x] My branch name describes the change and contains no internal
ticket id
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation
- [x] I have considered and documented the risks
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open comments
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-08-16 13:46:50 -05:00

169 lines
6.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
evaluateIssueThreadInteractionResolverAudience,
issueThreadInteractionAttentionAgentAllowed,
} from "./issue-thread-interaction-resolution.js";
const agent = { type: "agent", agentId: "agent-1", runId: "run-1" } as const;
function interaction(overrides: Record<string, unknown> = {}) {
return {
createdByAgentId: "agent-1",
createdByUserId: null,
sourceRunId: "run-1",
addresseeAgentId: null,
effectiveResolverPolicy: "anyone",
...overrides,
};
}
describe("issue-thread interaction resolver audience", () => {
it.each([
"suggest_tasks",
"ask_user_questions",
"request_confirmation",
"request_checkbox_confirmation",
"request_item_verdicts",
])("allows the creator and creating run under anyone for %s", () => {
expect(evaluateIssueThreadInteractionResolverAudience({
actor: agent,
interaction: interaction(),
})).toMatchObject({ allowed: true, effectiveResolverPolicy: "anyone", reason: "allow_anyone" });
});
it.each([
["creator agent", { createdByAgentId: "agent-1", sourceRunId: "run-other" }],
["creating run", { createdByAgentId: "agent-other", sourceRunId: "run-1" }],
])("excludes the %s only when not_creator is effective", (_name, creator) => {
const decision = evaluateIssueThreadInteractionResolverAudience({
actor: agent,
interaction: interaction({ ...creator, effectiveResolverPolicy: "not_creator" }),
});
expect(decision).toMatchObject({ allowed: false, code: "interaction_creator_excluded" });
});
it("enforces an explicit addressee", () => {
const decision = evaluateIssueThreadInteractionResolverAudience({
actor: agent,
interaction: interaction({ addresseeAgentId: "agent-2" }),
});
expect(decision).toMatchObject({ allowed: false, code: "interaction_addressee_mismatch" });
});
it("requires run attribution for agents", () => {
const decision = evaluateIssueThreadInteractionResolverAudience({
actor: { type: "agent", agentId: "agent-1", runId: null },
interaction: interaction(),
});
expect(decision).toMatchObject({
allowed: false,
status: 422,
code: "interaction_run_attribution_required",
});
});
it("allows a server-derived restriction to narrow but never widen the audience", () => {
expect(evaluateIssueThreadInteractionResolverAudience({
actor: agent,
interaction: interaction({ createdByAgentId: "agent-other", sourceRunId: "run-other" }),
additionalRestriction: "human_only",
})).toMatchObject({ allowed: false, code: "interaction_human_only" });
expect(evaluateIssueThreadInteractionResolverAudience({
actor: agent,
interaction: interaction({ effectiveResolverPolicy: "human_only" }),
additionalRestriction: "anyone",
})).toMatchObject({ allowed: false, code: "interaction_human_only" });
});
it("intersects human-only and creator-separation restrictions", () => {
expect(evaluateIssueThreadInteractionResolverAudience({
actor: { type: "user", userId: "user-1" },
interaction: interaction({
createdByAgentId: null,
createdByUserId: "user-1",
effectiveResolverPolicy: "not_creator",
}),
additionalRestriction: "human_only",
})).toMatchObject({ allowed: false, code: "interaction_creator_excluded" });
expect(evaluateIssueThreadInteractionResolverAudience({
actor: { type: "user", userId: "user-1" },
interaction: interaction({
createdByAgentId: null,
createdByUserId: "user-1",
effectiveResolverPolicy: "human_only",
}),
additionalRestriction: "not_creator",
})).toMatchObject({ allowed: false, code: "interaction_creator_excluded" });
});
it("excludes the review requester when a review card has null creator columns", () => {
const restriction = {
policy: "not_creator",
excludedActor: { type: "user", id: "review-requester" },
source: "issue_review",
} as const;
expect(evaluateIssueThreadInteractionResolverAudience({
actor: { type: "user", userId: "review-requester" },
interaction: interaction({
createdByAgentId: null,
createdByUserId: null,
sourceRunId: null,
}),
additionalRestriction: restriction,
})).toMatchObject({
allowed: false,
code: "review_policy_denied",
details: {
policy: "not_creator",
allowedActor: "writer_other_than_review_requester",
},
});
expect(evaluateIssueThreadInteractionResolverAudience({
actor: { type: "user", userId: "peer-reviewer" },
interaction: interaction({
createdByAgentId: null,
createdByUserId: null,
sourceRunId: null,
}),
additionalRestriction: restriction,
})).toMatchObject({ allowed: true, effectiveResolverPolicy: "not_creator" });
});
it("keeps governed actions independently human-only", () => {
const decision = evaluateIssueThreadInteractionResolverAudience({
actor: agent,
interaction: interaction(),
governedAction: true,
});
expect(decision).toMatchObject({ allowed: false, code: "interaction_governed_action_denied" });
});
it("preserves legacy inherited board_or_agents creator separation", () => {
const decision = evaluateIssueThreadInteractionResolverAudience({
actor: agent,
interaction: interaction({
effectiveResolverPolicy: "board_or_agents",
resolverPolicyProvenance: "legacy_inherited_restriction",
}),
});
expect(decision).toMatchObject({ allowed: false, code: "interaction_creator_excluded" });
});
it("derives agent attention ownership from the same effective audience", () => {
expect(issueThreadInteractionAttentionAgentAllowed({
agentId: "agent-1",
interaction: interaction(),
})).toBe(true);
expect(issueThreadInteractionAttentionAgentAllowed({
agentId: "agent-1",
interaction: interaction({ effectiveResolverPolicy: "not_creator" }),
})).toBe(false);
expect(issueThreadInteractionAttentionAgentAllowed({
agentId: "agent-2",
interaction: interaction({ effectiveResolverPolicy: "human_only" }),
})).toBe(false);
});
});