mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-10 12:37:55 +01:00
fix(chat): name the addressee on human-only card denials and list team requirements (#20245)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agent Chat answers a person's requests with a chat agent that reads API results and the chat guidance > - A decision card can be human-only and addressed to one person, and the teams catalog lists ready-made teams with their requirements > - When an agent tried to accept another person's card, the denial said only "human-only", so the agent told the asker to accept the card themselves > - When an agent recommended a catalog team, the guidance asked only for roles, so the agent left out the required skills > - This pull request makes the denial name the addressee as the only resolver, and asks agents to list a team's roles, required skills and configuration inputs > - The benefit is that chat answers send people to the right person and show what a team needs before install ## Linked Issues or Issue Description Refs #20206, #20220, #20239 **What happened** Alex wrote "I approve Riley's request." in Agent Chat. The pending card is human-only and addressed to Riley. The agent tried to record the decision and got `403 interaction_human_only` with only "This issue-thread interaction is human-only". The reply correctly said the card stays pending, but it then told Alex to "accept or decline that request" on the task. Alex cannot do that; only Riley can. In a second chat, a person asked "Do we have a ready-made team for building a website?". The agent recommended Product Engineering and its roles. It did not name the four required skills that the catalog returned in `requiredSkills`. **Expected behavior** When an agent cannot resolve a card that is addressed to another person, the reply names that person as the only one who can resolve it. The reply does not tell the asker to act on the card. When an agent recommends a catalog team, the reply names the team's roles, every required skill and every configuration input. It says that a catalog listing does not mean the accounts are configured. **Steps to reproduce** 1. As user Alex, create a `request_confirmation` card with `resolverPolicy: "human_only"` and `addresseeUserId` set to user Riley on Alex's chat task. 2. In that chat, write "I approve Riley's request." 3. Read the agent run. `resolve-from-comment` returns 403 `interaction_human_only` without the addressee. The reply tells Alex to accept or decline the card. 4. In a new chat, ask "Do we have a ready-made team for building a website?". 5. Read the reply. It names Product Engineering and its roles, but not its required skills. ## What Changed - `server/src/services/issue-thread-interaction-resolution.ts`: when an agent is denied on a human-only card that is addressed to a person other than the verified replying user, the denial says the card is addressed to that person, that only they can accept or decline it, that the denial is final, and that the agent must not ask the asker to act on the card. The details include `addresseeUserId`. Cards without an addressee keep the old message. - `server/src/routes/issues.ts`: the route adds the addressee's display name to that denial (`details.addresseeName` and the message). If the name lookup fails, the generic addressee text stays. - `server/src/services/agent-conversations.ts`: the teams catalog paragraph asks agents to name a recommended team's roles (`agentSlugs`), every required skill (`requiredSkills`, by ref) and every configuration input (`envInputs`), and to say that a listing does not mean accounts are configured. - Tests: evaluator unit tests, a route-level test for the named denial, and a directive assertion. ## Verification - `cd server && npx vitest run src/services/issue-thread-interaction-resolution.test.ts src/__tests__/agent-conversations.test.ts src/__tests__/issue-thread-interaction-routes.test.ts src/__tests__/confirmation-comment-resolution.test.ts`: 4 files, all pass. - `tsc --noEmit -p server/tsconfig.json`: passes. - The change is cherry-picked onto the eval branch `chat-eval/case-reply-completeness`. The live Runner E2E cells `questions-and-approvals.wrong-reviewer` and `teams.find-team` run there. ## Risks - Low risk. The resolver decision does not change: the same requests are allowed and denied. Only the denial text and details change for agents on addressed human-only cards. - The denial reads one user row for the display name. A failed read falls back to the generic text. - The chat directive is slightly longer, so each chat prompt uses a few more tokens. ## Model Used - Anthropic Claude Opus 5.5 (`claude-opus-5-5`), with tool use and code execution in Claude Code. ## 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 - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3374ca54f5
commit
ba75b44c3c
6 files changed
+124
-2
No files matched your search
@@ -1000,6 +1000,7 @@ describe("chat prompt policy", () => {
|
||||
expect(AGENT_CHAT_DIRECTIVE).toContain("do not look for others in package registries, repositories or the web");
|
||||
expect(AGENT_CHAT_DIRECTIVE).toContain("The web app has no teams catalog page, so do not link one");
|
||||
expect(AGENT_CHAT_DIRECTIVE).toContain("paperclipai teams install <team id> --company-id <companyId>");
|
||||
expect(AGENT_CHAT_DIRECTIVE).toContain("When you recommend a team, name its roles (agentSlugs), every required skill (requiredSkills, by its ref) and every configuration input (envInputs)");
|
||||
const prompt = buildPaperclipTaskMarkdown({ issue: { id: "chat", identifier: "RUN-1", title: "Chat", workMode: "ask", conversationAgentId: "agent" } });
|
||||
expect(prompt).toContain("GET /api/teams/catalog");
|
||||
});
|
||||
|
||||
@@ -2753,6 +2753,44 @@ describe("issue thread interaction routes", () => {
|
||||
expect(mockInteractionService.acceptInteraction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("names the addressee as the only resolver when an agent tries another person's human-only card", async () => {
|
||||
mockIssueService.getById.mockResolvedValueOnce(createIssue({ status: "todo" }));
|
||||
mockInteractionService.getForIssue.mockResolvedValueOnce({
|
||||
id: "interaction-for-riley",
|
||||
kind: "request_confirmation",
|
||||
status: "pending",
|
||||
createdByAgentId: null,
|
||||
createdByUserId: "user-alex",
|
||||
addresseeUserId: "user-riley",
|
||||
sourceRunId: null,
|
||||
requestedResolverPolicy: "human_only",
|
||||
effectiveResolverPolicy: "human_only",
|
||||
payload: { version: 1, prompt: "Riley: approve?" },
|
||||
});
|
||||
const defaultWhere = mockDbSelectWhere.getMockImplementation()!;
|
||||
// The addressee name lookup ends in .limit(1); the other reads keep their defaults.
|
||||
mockDbSelectWhere.mockImplementation((() => ({
|
||||
...defaultWhere(),
|
||||
limit: () => Promise.resolve([{ name: "Riley" }]),
|
||||
})) as unknown as typeof defaultWhere);
|
||||
const app = await createApp({ type: "agent", agentId: ASSIGNEE_AGENT_ID, companyId: "company-1", runId: RUN_2 });
|
||||
|
||||
const res = await request(app)
|
||||
.post("/api/issues/aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa/interactions/interaction-for-riley/accept")
|
||||
.send({});
|
||||
|
||||
expect(res.status).toBe(403);
|
||||
expect(res.body).toMatchObject({
|
||||
code: "interaction_human_only",
|
||||
details: { addresseeUserId: "user-riley", addresseeName: "Riley" },
|
||||
});
|
||||
expect(res.body.error).toContain("addressed to Riley.");
|
||||
expect(res.body.error).toContain("Only Riley can accept or decline it");
|
||||
// /accept carries no verified replying user, so the advice stays neutral.
|
||||
expect(res.body.error).not.toContain("do not ask the person asking");
|
||||
expect(mockInteractionService.acceptInteraction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps a same-requester sibling confirmation human-only", async () => {
|
||||
mockReviewTransition.value = {
|
||||
actorType: "agent",
|
||||
|
||||
@@ -394,6 +394,7 @@ import {
|
||||
resolveIssueReviewRequester,
|
||||
} from "../services/issue-review-policy.js";
|
||||
import {
|
||||
addressedHumanOnlyDenialMessage,
|
||||
evaluateIssueThreadInteractionResolverAudience,
|
||||
issueThreadInteractionAttentionAgentAllowed,
|
||||
type IssueThreadInteractionResolverAudienceDecision,
|
||||
@@ -6010,6 +6011,16 @@ export function issueRoutes(
|
||||
return false;
|
||||
}
|
||||
|
||||
/** The addressee's display name, so a denial relayed in chat can name who resolves the card. */
|
||||
async function addresseeDisplayName(userId: string) {
|
||||
try {
|
||||
const [row] = await db.select({ name: authUsers.name }).from(authUsers).where(eq(authUsers.id, userId)).limit(1);
|
||||
return typeof row?.name === "string" && row.name.trim() ? row.name.trim() : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function denyIssueThreadInteractionResolution(
|
||||
res: Response,
|
||||
input: {
|
||||
@@ -6206,13 +6217,18 @@ export function issueRoutes(
|
||||
payload?.secretProposal !== undefined),
|
||||
});
|
||||
if (!decision.allowed) {
|
||||
const addresseeUserId = decision.code === "interaction_human_only" && typeof decision.details?.addresseeUserId === "string"
|
||||
? decision.details.addresseeUserId
|
||||
: null;
|
||||
const addresseeName = addresseeUserId ? await addresseeDisplayName(addresseeUserId) : null;
|
||||
return denyIssueThreadInteractionResolution(res, {
|
||||
status: decision.status,
|
||||
code: decision.code,
|
||||
message: decision.message,
|
||||
message: addresseeName ? addressedHumanOnlyDenialMessage(addresseeName, decision.details?.askerIsNotAddressee === true) : decision.message,
|
||||
details: {
|
||||
effectiveResolverPolicy: decision.effectiveResolverPolicy,
|
||||
...(decision.details ?? {}),
|
||||
...(addresseeName ? { addresseeName } : {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ When a reply lists many tasks, write each task identifier in full, such as RUN-1
|
||||
|
||||
A person's own display name and avatar belong to their account, and only they can change them in their profile settings at /<prefix>/company/settings/instance/profile. Agent credentials cannot edit a person's profile, and renaming an agent, a member record or the company does not change it. When the person asks to change their own name or avatar, link that page instead of attempting the change.
|
||||
|
||||
Ready-made teams are installable packages in Paperclip's teams catalog, not agents already in this company. When the person asks whether a ready-made team exists, or refers to one, list the catalog with GET /api/teams/catalog and choose by its descriptions and roles, since teams are not named after every kind of project. The catalog is the only source of ready-made teams: do not look for others in package registries, repositories or the web. A team chosen earlier in this chat may be recorded in its task context (get_task_context). POST /api/companies/{companyId}/teams/catalog/{catalogId}/preview shows what an install would add and creates no resources. Installing needs a board user or an agent with permission to create agents. The web app has no teams catalog page, so do not link one: name the team and its id, and when you cannot install, tell the person that a board user can run paperclipai teams install <team id> --company-id <companyId>. After an install, link the installed agents and projects at their own pages.
|
||||
Ready-made teams are installable packages in Paperclip's teams catalog, not agents already in this company. When the person asks whether a ready-made team exists, or refers to one, list the catalog with GET /api/teams/catalog and choose by its descriptions and roles, since teams are not named after every kind of project. When you recommend a team, name its roles (agentSlugs), every required skill (requiredSkills, by its ref) and every configuration input (envInputs), and say that a catalog listing does not mean the team's accounts are configured. The catalog is the only source of ready-made teams: do not look for others in package registries, repositories or the web. A team chosen earlier in this chat may be recorded in its task context (get_task_context). POST /api/companies/{companyId}/teams/catalog/{catalogId}/preview shows what an install would add and creates no resources. Installing needs a board user or an agent with permission to create agents. The web app has no teams catalog page, so do not link one: name the team and its id, and when you cannot install, tell the person that a board user can run paperclipai teams install <team id> --company-id <companyId>. After an install, link the installed agents and projects at their own pages.
|
||||
|
||||
This conversation and your credentials belong to one company. A task identifier whose prefix differs from this conversation's prefix belongs to another company or to none, and you cannot read it here, even when the person can open it themselves: a lookup that is not found does not mean the task does not exist. Do not search for it further, guess its content or copy anything from it. Say that this chat can only work in this company, and that to use that task the person can switch to its company and open a chat there. Link the task at /<its prefix>/issues/<identifier>, taking the prefix from the identifier the person gave; this is the one link that does not use this conversation's prefix.
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
addressedHumanOnlyDenialMessage,
|
||||
evaluateIssueThreadInteractionResolverAudience,
|
||||
issueThreadInteractionAttentionAgentAllowed,
|
||||
} from "./issue-thread-interaction-resolution.js";
|
||||
@@ -173,6 +174,44 @@ describe("issue-thread interaction resolver audience", () => {
|
||||
})).toBe(false);
|
||||
});
|
||||
|
||||
describe("human-only card addressed to someone else", () => {
|
||||
const card = interaction({ createdByAgentId: null, createdByUserId: "alex", addresseeUserId: "riley", effectiveResolverPolicy: "human_only" });
|
||||
|
||||
it("tells the agent only the addressee resolves it and not to send the asker to the card", () => {
|
||||
const decision = evaluateIssueThreadInteractionResolverAudience({ actor: { ...agent, relayedHumanUserId: "alex" }, interaction: card });
|
||||
expect(decision).toMatchObject({ allowed: false, status: 403, code: "interaction_human_only", details: { addresseeUserId: "riley", askerIsNotAddressee: true } });
|
||||
const message = decision.allowed ? "" : decision.message;
|
||||
expect(message).toContain("This issue-thread interaction is human-only and addressed to");
|
||||
expect(message).toContain("Only the addressee can accept or decline it");
|
||||
expect(message).toContain("do not ask the person asking to accept or decline it");
|
||||
});
|
||||
|
||||
it("names the addressee once the route knows their display name", () => {
|
||||
const message = addressedHumanOnlyDenialMessage("Riley", true);
|
||||
expect(message).toContain("addressed to Riley.");
|
||||
expect(message).toContain("Only Riley can accept or decline it");
|
||||
expect(message).toContain("the card waits on Riley");
|
||||
expect(message).not.toContain("addresseeUserId");
|
||||
});
|
||||
|
||||
it.each([
|
||||
["no verified replying user", agent],
|
||||
["the addressee as the replying user", { ...agent, relayedHumanUserId: "riley" }],
|
||||
])("keeps the advice neutral with %s", (_name, actor) => {
|
||||
const decision = evaluateIssueThreadInteractionResolverAudience({ actor, interaction: card });
|
||||
expect(decision).toMatchObject({ allowed: false, code: "interaction_human_only", details: { addresseeUserId: "riley", askerIsNotAddressee: false } });
|
||||
const message = decision.allowed ? "" : decision.message;
|
||||
expect(message).toContain("Only the addressee can accept or decline it");
|
||||
expect(message).not.toContain("do not ask the person asking");
|
||||
});
|
||||
|
||||
it("keeps the plain human-only denial when the card has no addressee", () => {
|
||||
const decision = evaluateIssueThreadInteractionResolverAudience({ actor: agent,
|
||||
interaction: interaction({ effectiveResolverPolicy: "human_only" }) });
|
||||
expect(decision).toMatchObject({ allowed: false, code: "interaction_human_only", message: "This issue-thread interaction is human-only" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("relayed human decision", () => {
|
||||
const relay = { ...agent, relayedHumanUserId: "user-1" };
|
||||
const humanOnly = (overrides: Record<string, unknown> = {}) =>
|
||||
|
||||
@@ -183,6 +183,21 @@ function relayedHumanDecisionAllowed(
|
||||
&& (!input.interaction.addresseeUserId || input.interaction.addresseeUserId === userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Denial for a human-only card addressed to one person. Agents relay it in
|
||||
* chat, so it names who resolves the card. Only when the replying user is
|
||||
* known to be someone else does it tell the agent not to send them to the card.
|
||||
*/
|
||||
export function addressedHumanOnlyDenialMessage(addresseeName: string | null | undefined, askerIsNotAddressee: boolean) {
|
||||
const name = addresseeName?.trim() || null;
|
||||
const message = `This issue-thread interaction is human-only and addressed to ${name ?? "one person, its addressee (addresseeUserId)"}. `
|
||||
+ `Only ${name ?? "the addressee"} can accept or decline it from the card; no agent can resolve it for them.`;
|
||||
if (!askerIsNotAddressee) return message;
|
||||
return `${message} The person asking is not the addressee, and their chat message does not count as the addressee's decision. `
|
||||
+ `This denial is final. Tell them the card waits on ${name ?? "the addressee"}, name ${name ? "them" : "the addressee"} as the only one who can resolve it, `
|
||||
+ "and do not ask the person asking to accept or decline it.";
|
||||
}
|
||||
|
||||
/**
|
||||
* The single pure audience evaluator for issue-thread interaction resolution.
|
||||
* Resource access, run validation, containment, and current-target checks must
|
||||
@@ -285,6 +300,19 @@ export function evaluateIssueThreadInteractionResolverAudience(
|
||||
if (relayedHumanDecisionAllowed(input, persistedPolicy, additionalRestriction)) {
|
||||
return { allowed: true, effectiveResolverPolicy, reason: "allow_relayed_human" };
|
||||
}
|
||||
const addresseeUserId = input.interaction.addresseeUserId;
|
||||
if (addresseeUserId && input.actor.type === "agent") {
|
||||
// Only a verified replying user is known; /accept and /reject carry none.
|
||||
const askerIsNotAddressee = Boolean(input.actor.relayedHumanUserId) && input.actor.relayedHumanUserId !== addresseeUserId;
|
||||
return {
|
||||
allowed: false,
|
||||
effectiveResolverPolicy,
|
||||
status: 403,
|
||||
code: "interaction_human_only",
|
||||
message: addressedHumanOnlyDenialMessage(null, askerIsNotAddressee),
|
||||
details: { addresseeUserId, askerIsNotAddressee },
|
||||
};
|
||||
}
|
||||
return {
|
||||
allowed: false,
|
||||
effectiveResolverPolicy,
|
||||
|
||||
Reference in new issue
Block a user