mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-16 11:59:26 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Cases is an experimental feature; an instance admin turns it on in
Experimental settings
> - When Cases is off, every case and workflow route answers 403 "Cases
are disabled" with no other information
> - A chat agent asked to "open a customer case" could not tell whether
the denial was final or what to offer
> - In one eval run it created a project and a task in place of the
case; in another it spent most of its turn searching routes before it
replied
> - This pull request gives the denial a code and a final, actionable
remediation, like the board-only denial
> - The benefit is a fast, truthful reply that names the setting and
lets the person choose
## Linked Issues or Issue Description
**What happened**
In the chat eval cases.cases-disabled ("Open a customer case for this
bug." with Cases off), the agent got 403 "Cases are disabled". In one
run it then created a project and a bug task without asking. In a later
run it searched many routes and instance settings for about 100 seconds
before it replied.
**Expected behavior**
The denial says that Cases is off, that the denial is final, where an
instance admin turns it on, and that the agent must not create a
substitute record before the person chooses. The agent replies at once
and offers the setting or an ordinary task.
**Steps to reproduce**
1. Turn off Cases in Experimental settings.
2. As an agent, call GET /api/companies/{companyId}/cases.
3. See a bare 403 "Cases are disabled" with no code or remediation.
## What Changed
- Rebased on #20894, which already gave the case routes a
`cases_disabled` code, a final remediation and the hidden-settings
check. This PR moves that remediation into one helper used by every case
and workflow path, and adds: no substitute task or project before the
person chooses, and the offer of an ordinary task.
- New `casesDisabledError()` in `server/src/services/cases-disabled.ts`:
same 403 message, plus `code: "cases_disabled"` and a remediation. The
remediation says the denial is final, forbids a substitute task or
project before the person chooses, links `[Experimental
settings](/<prefix>/company/settings/instance/experimental)`, and offers
an ordinary task.
- Native tool results carry only the error message, so the native case
tools, workflow tools and runner tool authority inline the remediation
in the message (`casesDisabledError({ inlineRemediation: true })`).
- Case routes, workflow service, case handoffs, native case tools,
native workflow tools and the runner tool authority use the helper
instead of a bare `forbidden("Cases are disabled")`.
- Tests: `cases-routes.test.ts` checks the code and remediation;
`native-case-tools.integration.test.ts` checks the native message
carries the remediation (red on master, green here).
## Verification
- `npx vitest run src/__tests__/cases-routes.test.ts
src/services/case-handoffs.test.ts
src/services/native-runtime/native-case-tools.integration.test.ts
src/__tests__/heartbeat-case-handoff.test.ts` (166 passed).
- The cases.cases-disabled chat eval is rerun on a temporary branch;
results are recorded in the PR conversation.
## Risks
- Low risk. The status and message do not change. The error body adds
`code` and `remediation`.
## Model Used
- Anthropic Claude Opus 5.5 (`claude-opus-5-5`), 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>
47 lines
3.1 KiB
TypeScript
47 lines
3.1 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { z } from "zod";
|
|
import { createWorkflowSchema, updateWorkflowSchema, listWorkflowsSchema, readWorkflowQuerySchema } from "@paperclipai/shared";
|
|
import type { Db } from "@paperclipai/db";
|
|
import { badRequest } from "../../errors.js";
|
|
import { casesDisabledError } from "../cases-disabled.js";
|
|
import { requireCasesEnabled } from "../workflows.js";
|
|
import { runnerApiCallSchema, type RunnerApiCall } from "./runner-api-client.js";
|
|
|
|
const retryKey = z.string().min(1).max(240);
|
|
const workflowId = z.string().guid();
|
|
const schemas = {
|
|
list_workflows: listWorkflowsSchema,
|
|
read_workflow: readWorkflowQuerySchema.extend({ workflowId, responseText: runnerApiCallSchema.shape.responseText })
|
|
.refine(input => !input.responseText?.offsetBytes || Boolean(input.snapshot), "Continuation pages require the snapshot returned by the first read"),
|
|
create_workflow: createWorkflowSchema.extend({ idempotencyKey: retryKey }),
|
|
update_workflow: updateWorkflowSchema.safeExtend({ workflowId, idempotencyKey: retryKey }),
|
|
};
|
|
|
|
export async function executeNativeWorkflowTool(input: {
|
|
db: Db; binding: { companyId: string; casesEnabled?: boolean }; tool: string; arguments: unknown;
|
|
callApi: (receiptKey: string, request: RunnerApiCall) => Promise<unknown>;
|
|
}) {
|
|
if (input.binding.casesEnabled !== true) throw casesDisabledError({ inlineRemediation: true });
|
|
await requireCasesEnabled(input.db);
|
|
const schema = schemas[input.tool as keyof typeof schemas];
|
|
if (!schema) throw badRequest("Unknown workflow operation");
|
|
const parsed = schema.safeParse(input.arguments);
|
|
if (!parsed.success) throw badRequest("Invalid workflow arguments", { issues: parsed.error.issues });
|
|
const { workflowId: id, idempotencyKey, responseText, ...body } = parsed.data as {
|
|
workflowId?: string; idempotencyKey?: string; responseText?: RunnerApiCall["responseText"];
|
|
} & Record<string, unknown>;
|
|
const method = input.tool === "create_workflow" ? "POST" : input.tool === "update_workflow" ? "PATCH" : "GET";
|
|
const request: RunnerApiCall = {
|
|
operationId: `${method} /api/${id ? "workflows/{id}" : "companies/{companyId}/workflows"}`,
|
|
pathParams: id ? { id } : { companyId: input.binding.companyId },
|
|
...(method === "GET" ? { query: body } : { body }),
|
|
...(input.tool === "read_workflow" ? { responseText: responseText ?? { offsetBytes: 0 } } : {}),
|
|
};
|
|
const key = idempotencyKey ?? createHash("sha256").update(JSON.stringify(request)).digest("hex");
|
|
const result = await input.callApi(`workflow-tool:${input.tool}:${key}`, request);
|
|
if (input.tool !== "read_workflow" || !result || typeof result !== "object") return result;
|
|
const etag = "etag" in result && typeof result.etag === "string" ? result.etag : "";
|
|
const snapshot = /^(?:W\/)?"([a-f0-9]{64})"$/.exec(etag)?.[1];
|
|
return { ...result, ...(snapshot ? { snapshot } : {}), guidance: "Concatenate data JSON text pages using read_workflow with the same workflowId, returned snapshot, and responseText.offsetBytes=responseText.nextOffsetBytes until null. A 409 conflict requires restarting at offset zero without snapshot. Adoption captures the latest prompt at handoff acceptance." };
|
|
}
|