mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-17 21:34:48 +01:00
fix(acpx): only treat an error result as a Claude sign-in failure (#21921)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Claude agents run through the Claude ACP bridge (`claude-agent-acp` 0.73.0), which Paperclip patches in `patches/` > - The bridge reads Claude Code's final result for each turn. If the result text contains "Please run /login", the bridge fails the turn as a sign-in failure > - That check does not look at `is_error`. A successful reply that quotes the CLI's sign-in hint also fails the turn > - Agents quote that hint when they report the output of a `claude` command that they ran. The work is done, but the run fails with "ACP agent reported a terminal access failure." > - Upstream fixed this in [agentclientprotocol/claude-agent-acp#1103](https://github.com/agentclientprotocol/claude-agent-acp/pull/1103) (commit [`6e97e07`](https://github.com/agentclientprotocol/claude-agent-acp/commit/6e97e071c581002b43d9556dbd1d1376ebf9516f), released in 0.81.1), "fix: gate login result text on error state" > - This pull request ports that upstream change into the 0.73.0 bridge patch > - The benefit is that a correct, finished run is not reported as a failed sign-in ## Linked Issues or Issue Description Upstream fix: [agentclientprotocol/claude-agent-acp#1103](https://github.com/agentclientprotocol/claude-agent-acp/pull/1103) (commit [`6e97e07`](https://github.com/agentclientprotocol/claude-agent-acp/commit/6e97e071c581002b43d9556dbd1d1376ebf9516f), released in 0.81.1). This pull request ports it. Refs #14089. That pull request fixes the same class of problem in the Claude CLI lane (`execute.ts`). This pull request fixes the ACP lane. Related: #14093 shows the same error text, but it has a different cause. This pull request does not fix #14093. **What happened?** An agent ran a script that calls the `claude` CLI without credentials. The CLI printed "Not logged in · Please run /login". The agent finished its task and quoted that text in its final reply. Claude Code ended the turn with a successful result (`is_error: false`). The bridge saw "Please run /login" in the result text and failed the turn with `auth_required`. Paperclip then failed the run with "ACP agent reported a terminal access failure." **Expected behavior** A successful result completes the turn. Only an error result with the sign-in hint is a sign-in failure. **Steps to reproduce** 1. Run a Claude agent on the ACP lane. 2. Make the model's final reply contain the text "Please run /login" (for example, quote the output of `claude -p hi` without credentials). 3. See that the run fails with "ACP agent reported a terminal access failure." The new test in this pull request does these steps against a local API stand-in. **Agent adapter(s) involved** `claude_local` on the ACP engine, and the Runner's ACPX Claude profile. Both use the same patched bridge. ## What Changed - `patches/@agentclientprotocol__claude-agent-acp@0.73.0.patch`: port [agentclientprotocol/claude-agent-acp#1103](https://github.com/agentclientprotocol/claude-agent-acp/pull/1103) (commit [`6e97e07`](https://github.com/agentclientprotocol/claude-agent-acp/commit/6e97e071c581002b43d9556dbd1d1376ebf9516f), released in 0.81.1). It has two parts, the same as upstream: - The `success` result check is now `message.is_error && message.result.includes("Please run /login")`. A successful result that quotes the sign-in hint no longer fails the turn. - The goal-command check also requires `message.is_error`. A `/goal` command whose successful result quotes the sign-in hint no longer rolls the session goal back. - Both patch comments name the upstream change. All other patch hunks are unchanged. - `packages/paperclip-runner/src/drivers/acpx/acpx-runtime-adapter.claude-login-text.test.ts`: a new test. It runs the real bridge and the bundled Claude Code against a local API stand-in. The model's reply quotes the sign-in hint, and the test expects the turn to complete. ## Verification - Red: on `master`'s patch, the new test fails with `{"status":"failed","error":{"message":"ACP agent reported a terminal access failure."}}`. - Green: with this patch, the new test passes (`status: "completed"`, `stopReason: "end_turn"`). - I ran Claude Code 2.1.286 (the bundled version) with no credentials. Its real sign-in failure is a result with `is_error: true` and the text "Not logged in · Please run /login". The guard still catches it. The separate synthetic sign-in message check is unchanged. - The goal-command part has no new test here. The upstream change adds a test for it. The runner's `session-goals.test.ts` passes with the new patch. - `node --test scripts/acpx-patch-packaging.test.mjs`: 26 passed. - `node --test packages/paperclip-runner/test/acpx-codex-package-contract.test.mjs`: 9 passed. - Runner real-bridge Claude tests (`acpx-runtime-adapter.claude-*.test.ts`, `acpx-runtime-adapter.test.ts`, `claude-scheduling-tools.claude-acp.test.ts`, `runner-tool-bridge.claude-*.test.ts`): 139 passed. - `claude-local` ACP tests (`acp.test.ts`, `acp.auth.test.ts`, `acp.quota.test.ts`): 95 passed. - `pnpm --filter @paperclipai/paperclip-runner run typecheck:typescript`: passed. - I did not commit `pnpm-lock.yaml`. The patch hash changes, and CI resolves the lockfile for this run. ## Risks - Low risk. The change adds one condition to each of two checks in the bridge patch. Both match the upstream change. - The bridge's `commandDigest` does not change, because the patch does not touch `dist/index.js`. Saved sessions are not reset. - A sign-in failure that Claude Code reports as a successful, non-error result is no longer caught by this check. Claude Code 2.1.286 reports sign-in failures as error results, and upstream uses the same rule. ## Model Used Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, subagents) and extended thinking. ## 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 🤖 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
cc9ff75cb8
commit
fb288f5666
2 files changed
+132
-5
No files matched your search
+107
@@ -0,0 +1,107 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
||||
import { createServer } from "node:http";
|
||||
import { createRequire } from "node:module";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import type { AcpRuntimeEvent } from "acpx/runtime";
|
||||
import { expect, it, vi } from "vitest";
|
||||
|
||||
import { openCodexAcpxRuntime } from "./acpx-runtime-adapter.js";
|
||||
import type { VerifiedAcpxCommandLease } from "./installation-integrity.js";
|
||||
import { resolveQualifiedAcpxProfile } from "./qualified-profiles.js";
|
||||
import type { AcpxRuntimePortOpenOptions } from "./runtime-host.js";
|
||||
|
||||
const QUOTED_LOGIN_TEXT = 'The probe exited 1: "Not logged in · Please run /login". I posted its output.';
|
||||
|
||||
async function runTurn() {
|
||||
const root = await mkdtemp(join(tmpdir(), "claude-login-text-"));
|
||||
const home = join(root, "home"), cwd = join(root, "workspace"), config = join(home, ".claude");
|
||||
await Promise.all([mkdir(config, { recursive: true }), mkdir(cwd)]);
|
||||
let sequence = 0;
|
||||
const api = createServer(async (request, response) => {
|
||||
let raw = "";
|
||||
for await (const chunk of request) raw += chunk;
|
||||
if (request.method === "GET") {
|
||||
response.writeHead(200, { "content-type": "application/json" });
|
||||
response.end(JSON.stringify({ data: [], has_more: false }));
|
||||
return;
|
||||
}
|
||||
if (request.url?.includes("count_tokens")) {
|
||||
response.writeHead(200, { "content-type": "application/json" });
|
||||
response.end(JSON.stringify({ input_tokens: 1 }));
|
||||
return;
|
||||
}
|
||||
const body = JSON.parse(raw || "{}") as { model?: string; stream?: boolean };
|
||||
const model = body.model ?? "claude-sonnet-5";
|
||||
if (body.stream !== true) {
|
||||
response.writeHead(200, { "content-type": "application/json" });
|
||||
response.end(JSON.stringify({ id: "msg_fixture", type: "message", role: "assistant", model,
|
||||
content: [{ type: "text", text: "OK" }], stop_reason: "end_turn", usage: { input_tokens: 1, output_tokens: 1 } }));
|
||||
return;
|
||||
}
|
||||
const frames: Array<Record<string, unknown>> = [
|
||||
{ type: "message_start", message: { id: `msg_${++sequence}`, type: "message", role: "assistant", model, content: [],
|
||||
stop_reason: null, stop_sequence: null, usage: { input_tokens: 7, output_tokens: 0 } } },
|
||||
{ type: "content_block_start", index: 0, content_block: { type: "text", text: "" } },
|
||||
{ type: "content_block_delta", index: 0, delta: { type: "text_delta", text: QUOTED_LOGIN_TEXT } },
|
||||
{ type: "content_block_stop", index: 0 },
|
||||
{ type: "message_delta", delta: { stop_reason: "end_turn", stop_sequence: null }, usage: { output_tokens: 3 } },
|
||||
{ type: "message_stop" },
|
||||
];
|
||||
response.writeHead(200, { "content-type": "text/event-stream" });
|
||||
for (const frame of frames) response.write(`event: ${frame.type}\ndata: ${JSON.stringify(frame)}\n\n`);
|
||||
response.end();
|
||||
});
|
||||
await new Promise<void>(resolve => api.listen(0, "127.0.0.1", resolve));
|
||||
const address = api.address() as { port: number };
|
||||
|
||||
const entry = createRequire(import.meta.url).resolve("@agentclientprotocol/claude-agent-acp/dist/index.js");
|
||||
const command: VerifiedAcpxCommandLease = {
|
||||
spawn: (args, input) => spawn(process.execPath, [entry, ...(args ?? [])], { ...input, detached: true, stdio: ["pipe", "pipe", "pipe"] }),
|
||||
close: async () => undefined,
|
||||
};
|
||||
const options: AcpxRuntimePortOpenOptions = {
|
||||
command,
|
||||
profile: resolveQualifiedAcpxProfile("claude", "claude-sonnet-5"),
|
||||
cwd,
|
||||
stateDirectory: join(root, "state"),
|
||||
providerSessionKey: "claude-login-text",
|
||||
permissionMode: "approve-all",
|
||||
permissionPolicy: { autoApprove: ["read", "write", "execute", "other"], defaultAction: "approve" },
|
||||
launchEnvironment: { HOME: home, CLAUDE_CONFIG_DIR: config, PATH: "/usr/bin:/bin", TMPDIR: root,
|
||||
ANTHROPIC_API_KEY: "local-fixture-only", ANTHROPIC_BASE_URL: `http://127.0.0.1:${address.port}`,
|
||||
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1", DISABLE_TELEMETRY: "1", DISABLE_ERROR_REPORTING: "1", ENABLE_TOOL_SEARCH: "false" },
|
||||
credentialFenceFds: [42, 43] as const,
|
||||
activateCredentialFenceOwner: async () => undefined,
|
||||
systemInstructions: "Report the probe output.",
|
||||
mcpServers: [],
|
||||
retainFailedAdmissionCleanup: vi.fn(),
|
||||
} as AcpxRuntimePortOpenOptions;
|
||||
let port: Awaited<ReturnType<typeof openCodexAcpxRuntime>> | undefined;
|
||||
try {
|
||||
port = await openCodexAcpxRuntime(options, {
|
||||
awaitProviderOwnership: async () => undefined,
|
||||
awaitProviderExit: child => new Promise<void>(resolve => child.once("exit", () => resolve())),
|
||||
});
|
||||
const turn = port.startTurn({ text: "Run the probe and report its output.", requestId: "turn-1",
|
||||
onPermissionRequest: async () => ({ outcome: "allow_once" }) });
|
||||
const events: AcpRuntimeEvent[] = [];
|
||||
for await (const event of turn.events) events.push(event);
|
||||
return { result: await turn.result, events };
|
||||
} finally {
|
||||
try { await port?.close({ reason: "sign-in hint verified" }); }
|
||||
finally {
|
||||
api.closeAllConnections();
|
||||
await new Promise<void>(resolve => api.close(() => resolve()));
|
||||
await rm(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 50 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
it("completes a turn whose successful reply quotes the CLI's sign-in hint through the real ACP stream", async () => {
|
||||
const { result, events } = await runTurn();
|
||||
expect(result).toMatchObject({ status: "completed", stopReason: "end_turn" });
|
||||
expect(JSON.stringify(events)).toContain("Please run /login");
|
||||
}, 60_000);
|
||||
@@ -1,5 +1,5 @@
|
||||
diff --git a/dist/acp-agent.js b/dist/acp-agent.js
|
||||
index 0214a50..73f0c16 100644
|
||||
index 0214a50..a68121d 100644
|
||||
--- a/dist/acp-agent.js
|
||||
+++ b/dist/acp-agent.js
|
||||
@@ -2490,11 +2490,88 @@ export class ClaudeAcpAgent {
|
||||
@@ -117,7 +117,18 @@ index 0214a50..73f0c16 100644
|
||||
await subagents.finishTask(message.task_id, message.patch.status, sendUpdate);
|
||||
session.liveBackgroundTasks.delete(message.task_id);
|
||||
}
|
||||
@@ -2922,9 +3002,19 @@ export class ClaudeAcpAgent {
|
||||
@@ -2794,7 +2874,9 @@ export class ClaudeAcpAgent {
|
||||
session.pendingGoalUpdate = undefined;
|
||||
const goalCommandFailed = message.is_error ||
|
||||
message.stop_reason === "refusal" ||
|
||||
- ("result" in message && message.result.includes("Please run /login"));
|
||||
+ ("result" in message &&
|
||||
+ message.is_error &&
|
||||
+ message.result.includes("Please run /login"));
|
||||
if (goalCommandFailed) {
|
||||
await this.publishGoal(params.sessionId, pendingGoalUpdate.previous ?? null);
|
||||
}
|
||||
@@ -2922,9 +3004,19 @@ export class ClaudeAcpAgent {
|
||||
amount: message.total_cost_usd,
|
||||
currency: "USD",
|
||||
},
|
||||
@@ -140,7 +151,16 @@ index 0214a50..73f0c16 100644
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -4506,6 +4596,48 @@ export class ClaudeAcpAgent {
|
||||
@@ -3081,7 +3173,7 @@ export class ClaudeAcpAgent {
|
||||
}
|
||||
switch (message.subtype) {
|
||||
case "success": {
|
||||
- if (message.result.includes("Please run /login")) {
|
||||
+ if (message.is_error && message.result.includes("Please run /login")) {
|
||||
await failActiveWithSessionFailure("auth_required", RequestError.authRequired(), message.result);
|
||||
break;
|
||||
}
|
||||
@@ -4506,6 +4598,48 @@ export class ClaudeAcpAgent {
|
||||
* `$/cancel_request`, and our local abort race settles even if the client
|
||||
* ignores it. A `cancelled` outcome, request rejection, and local abort all
|
||||
* surface the same "Tool use aborted" the callers already expect. */
|
||||
@@ -189,7 +209,7 @@ index 0214a50..73f0c16 100644
|
||||
async requestPermissionFromClient(params, toolName, signal, parentToolUseId, ownerSessionId = params.sessionId) {
|
||||
if (signal.aborted)
|
||||
throw new Error("Tool use aborted");
|
||||
@@ -5311,14 +5443,24 @@ export class ClaudeAcpAgent {
|
||||
@@ -5311,14 +5445,24 @@ export class ClaudeAcpAgent {
|
||||
settingSources: ["user", "project", "local"],
|
||||
...(thinking !== undefined && { thinking }),
|
||||
...userProvidedOptions,
|
||||
@@ -215,7 +235,7 @@ index 0214a50..73f0c16 100644
|
||||
...mcpServers,
|
||||
...(fileChangeAuditSupport
|
||||
? { [FILE_CHANGE_AUDIT_SERVER_NAME]: fileChangeAuditSupport.mcpServer }
|
||||
@@ -5329,6 +5471,16 @@ export class ClaudeAcpAgent {
|
||||
@@ -5329,6 +5473,16 @@ export class ClaudeAcpAgent {
|
||||
allowDangerouslySkipPermissions: ALLOW_BYPASS,
|
||||
permissionMode: initialPermissionMode,
|
||||
canUseTool: this.canUseTool(sessionId),
|
||||
|
||||
Reference in new issue
Block a user