fix: harden sessions_spawn attachment schema landing (#33648) (thanks @anisoptera)
This commit is contained in:
@@ -611,13 +611,14 @@ export async function spawnSubagentDirect(
|
||||
}
|
||||
buf = strictBuf;
|
||||
} else {
|
||||
buf = Buffer.from(contentVal, "utf8");
|
||||
const estimatedBytes = buf.byteLength;
|
||||
// Avoid allocating oversized UTF-8 buffers before enforcing file limits.
|
||||
const estimatedBytes = Buffer.byteLength(contentVal, "utf8");
|
||||
if (estimatedBytes > maxFileBytes) {
|
||||
fail(
|
||||
`attachments_file_bytes_exceeded (name=${name} bytes=${estimatedBytes} maxFileBytes=${maxFileBytes})`,
|
||||
);
|
||||
}
|
||||
buf = Buffer.from(contentVal, "utf8");
|
||||
}
|
||||
|
||||
const bytes = buf.byteLength;
|
||||
|
||||
@@ -164,4 +164,26 @@ describe("sessions_spawn tool", () => {
|
||||
expect(hoisted.spawnAcpDirectMock).not.toHaveBeenCalled();
|
||||
expect(hoisted.spawnSubagentDirectMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps attachment content schema unconstrained for llama.cpp grammar safety", () => {
|
||||
const tool = createSessionsSpawnTool();
|
||||
const schema = tool.parameters as {
|
||||
properties?: {
|
||||
attachments?: {
|
||||
items?: {
|
||||
properties?: {
|
||||
content?: {
|
||||
type?: string;
|
||||
maxLength?: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
const contentSchema = schema.properties?.attachments?.items?.properties?.content;
|
||||
expect(contentSchema?.type).toBe("string");
|
||||
expect(contentSchema?.maxLength).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user