Skip to content

Commit d4ee708

Browse files
committed
Merge remote-tracking branch 'origin/dev' into fix/paginated-history-incident-20260912
2 parents ad7c687 + 8f1471b commit d4ee708

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎src/adapters/devin/cloud-direct/chat.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,34 @@ const MAX_TOOL_DESC_LEN = 6998;
505505
* Cognition-specific constraint alongside the length limit above; if
506506
* Cognition adds more blocklisted phrases, extend this table and add a
507507
* regression test in tests/devin-adapter.test.ts.
508+
*
509+
* Not every entry is matched the same way. The Claude Code phrase above is
510+
* case-sensitive and whitespace-exact, but the two Codex entries below are
511+
* not: against a live account, lowercasing the first word and doubling an
512+
* interior space both still produced `permission_denied`, while changing any
513+
* single word passed. So those two match case-insensitively with flexible
514+
* whitespace and an optional comma, and the rewrite swaps only the leading
515+
* verb — the smallest edit measured to clear the filter.
516+
*
517+
* These two sentences are Codex's own built-in `exec_command` and
518+
* `write_stdin` descriptions, verbatim. Every Codex turn carries them, so
519+
* before this table knew about them the cloud refused literally every request
520+
* from a Codex client — a bare "hi" included — while the same account
521+
* answered a hand-built request with an ordinary shell tool. The visible
522+
* symptom was the adapter's own blocklist message pointing back at this
523+
* table, which is why they are named here rather than left to the next person
524+
* to re-bisect.
508525
*/
509526
const COGNITION_BLOCKLIST_REWRITES: ReadonlyArray<[RegExp, string]> = [
510527
[/\bTakes a task_id parameter identifying the task\b/g, "Accepts a task_id parameter identifying the task"],
528+
[
529+
/\bRuns\s+a\s+command\s+in\s+a\s+PTY,?\s+returning\s+output\s+or\s+a\s+session\s+ID\s+for\s+ongoing\s+interaction\b/gi,
530+
"Executes a command in a PTY, returning output or a session ID for ongoing interaction",
531+
],
532+
[
533+
/\bWrites\s+characters\s+to\s+an\s+existing\s+unified\s+exec\s+session\s+and\s+returns\s+recent\s+output\b/gi,
534+
"Sends characters to an existing unified exec session and returns recent output",
535+
],
511536
];
512537

513538
function sanitizeToolDescriptionForCognition(description: string): string {
@@ -1203,6 +1228,11 @@ export async function* streamChatEvents(req: CloudChatRequest): AsyncGenerator<C
12031228
`Cognition denied this request (permission_denied). If tool descriptions ` +
12041229
`are present, a blocklisted phrase may have triggered this — see the ` +
12051230
`COGNITION_BLOCKLIST_REWRITES table in cloud-direct/chat.ts. ` +
1231+
// Keep the cloud's own sentence. Replacing it outright is what made the
1232+
// two Codex entries in that table expensive to find: the message named
1233+
// the table but dropped the only text that could have said whether this
1234+
// was a phrase match at all.
1235+
`(cloud message: ${trailerError.message}) ` +
12061236
`(cloud trace ID: ${trailerError.traceId ?? 'n/a'})`;
12071237
throw new CloudChatError(enriched, trailerError.code, trailerError.traceId);
12081238
}

‎tests/providers/devin-adapter.test.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,33 @@ describe("devin adapter", () => {
8787
// Descriptions without the trigger pass through unchanged
8888
expect(sanitizeToolDescriptionForCognitionForTests("A benign description.")).toBe("A benign description.");
8989
});
90-
});
9190

91+
test("rewrites the Codex built-in tool descriptions Cognition refuses", () => {
92+
// These two are Codex's own exec_command and write_stdin descriptions,
93+
// verbatim. Every Codex turn carries them, so leaving them intact made the
94+
// cloud refuse every request from a Codex client, a bare "hi" included.
95+
// Measured against a live account: the sentences below were refused, and
96+
// the rewritten forms were accepted.
97+
const execCommand = "Runs a command in a PTY, returning output or a session ID for ongoing interaction.";
98+
expect(sanitizeToolDescriptionForCognitionForTests(execCommand))
99+
.toBe("Executes a command in a PTY, returning output or a session ID for ongoing interaction.");
100+
101+
const writeStdin = "Writes characters to an existing unified exec session and returns recent output.";
102+
expect(sanitizeToolDescriptionForCognitionForTests(writeStdin))
103+
.toBe("Sends characters to an existing unified exec session and returns recent output.");
104+
105+
// Cognition matches these two case-insensitively and tolerates both a
106+
// doubled interior space and a missing comma, so the rewrite has to reach
107+
// every variant that still gets refused rather than only the exact bytes.
108+
expect(sanitizeToolDescriptionForCognitionForTests(execCommand.toLowerCase()))
109+
.toContain("Executes a command in a PTY");
110+
expect(sanitizeToolDescriptionForCognitionForTests(
111+
"Runs a command in a PTY returning output or a session ID for ongoing interaction.",
112+
)).toContain("Executes a command in a PTY");
113+
114+
// Changing any single word already clears the filter, so a description that
115+
// merely resembles these must survive untouched.
116+
const nearMiss = "Runs a command in a terminal, returning output or a session ID for ongoing interaction.";
117+
expect(sanitizeToolDescriptionForCognitionForTests(nearMiss)).toBe(nearMiss);
118+
});
119+
});

0 commit comments

Comments
 (0)