Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion scripts/monitor-pilot/live-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,20 @@ function parseArgs(call: { readonly id: string; readonly function: { readonly na
}

function toolCallMessage(response: LlmResponse): ChatMessage {
return response.message
const toolCalls = response.message.tool_calls?.map((call) => {
if (isJsonObjectArguments(call.function.arguments)) return call
return { ...call, function: { ...call.function, arguments: "{}" } }
})
return { ...response.message, tool_calls: toolCalls }
}

function isJsonObjectArguments(raw: string): boolean {
try {
const parsed: unknown = JSON.parse(raw)
return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)
} catch {
return false
}
}

function stableCallBatchSignature(calls: readonly PilotToolCall[]): string {
Expand Down
20 changes: 20 additions & 0 deletions src/monitoring/__tests__/live-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,25 @@ async function testReasoningHeavyNativeOverrunIsAccepted(): Promise<void> {
} finally { await fs.rm(directory, { recursive: true, force: true }) }
}

async function testMalformedArgumentsAreSanitizedOnEcho(): Promise<void> {
const directory = await scratch()
try {
const broken = { name: "apply_diff", args: "{\"content\":\"truncated" }
const done = { name: "attempt_completion",
args: JSON.stringify({ result: "done" }) }
const client = new MockBillingClient([broken, done])
const summary = await collectLiveDevelopment({ outputDir: directory, client })
assert.equal(summary.abortedAttempts, 0)
assert.equal(summary.completedRuns, 32)
const history = client.requests[1]?.messages ?? []
const calls = history.filter((message) => {
return (message.tool_calls?.length ?? 0) > 0
})
const echoed = calls[0]?.tool_calls?.[0]?.function.arguments
assert.equal(echoed, "{}")
} finally { await fs.rm(directory, { recursive: true, force: true }) }
}

async function testHeldoutCannotStartWithoutQualifiedDevelopment(): Promise<void> {
const directory = await scratch()
try {
Expand Down Expand Up @@ -537,6 +556,7 @@ await testCopiedGlobalLedgerEpochsDoNotBlockResume()
await testKnownPerRunAdmissionStopCompletesAndSettlesTrajectory()
await testCompletionOverrunIsJournaledBeforeAnyToolDispatch()
await testReasoningHeavyNativeOverrunIsAccepted()
await testMalformedArgumentsAreSanitizedOnEcho()
await testHeldoutCannotStartWithoutQualifiedDevelopment()
await testHeldoutRejectsDifferentFrozenOutputCapBeforeInference()
await testStorageRootSymlinkIsRejectedBeforeInference()
Expand Down
Loading