Skip to content

Commit f4cb545

Browse files
authored
docs(mantis): script catalog-tool turns through Code Mode exec (#127878)
* docs(mantis): script catalog-tool turns through Code Mode exec Run 32570733988 blocked both lanes with 'Tool pdf not found': the proof agent scripted a top-level pdf function_call, but the SUT agent runs Code Mode where catalog tools execute from JavaScript inside exec. Document the canonical route in the proof prompt, add a complete exec(pdf) scripted-event example plus the document-extract configPatch to the staged-media recipe, and pin the new guidance in the workflow test. * docs(mantis): wait for the exec round trip before finish ClawSweeper P2: send releases the mock response once the outbound message is visible, and finish tears the lane down, so a slow exec/pdf round trip could lose its function_call_output follow-up. Observe until the cumulative provider-request count covers the follow-up and assert the recorded function_call_output before finish; pin the contract in the workflow test.
1 parent c5121ad commit f4cb545

3 files changed

Lines changed: 108 additions & 7 deletions

File tree

‎.github/codex/prompts/mantis-recipes/staged-media-provider-proof.md‎

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ $lane observe --lane baseline --seconds 60 --until-provider-requests 1
1111
requests="$($lane requests --lane baseline)"
1212
jq -e '[.requests[].contentFacts[]? | select(.type == "legacy_media")] | length > 0' \
1313
<<<"$requests"
14-
$lane finish --lane baseline --focus-message-id "$message_id"
1514
```
1615

16+
With no tool round trip, finish now using `message_id`. Otherwise continue below;
17+
`finish` stops the lane.
18+
1719
For a reply-mention turn, first `send --media "$media"` without text, capture its
1820
`.sent.messageId`, then `send --reply-to "$message_id" --text '@{sut} inspect this document'`.
1921
A bare unmentioned upload stages the file but produces no provider turn.
@@ -22,9 +24,93 @@ Repeat for `candidate` with its returned message id, selecting `type == "input_f
2224
Assert the complete selected facts: `filename`, `mimeType`, and `byteLength` when present.
2325
The structured facts are comparison evidence; never scrape `body` strings.
2426

25-
If baseline needs a tool round trip, take the tool argument from the recorded
26-
`legacy_media.filename`. Build a complete response-events JSON array from
27-
`toolCallEvents()` in `scripts/e2e/mock-openai-server.mjs`
28-
(`response.output_item.added`, `response.function_call_arguments.delta`,
29-
`response.output_item.done`, `response.completed`), then install it before the
30-
next turn with `mock --lane baseline --response-events-file <public-json>`.
27+
For a PDF tool round trip, start each lane with this patch. `pdf` is already in
28+
the Code Mode catalog; `document-extract` lets the mock OpenAI route execute it.
29+
30+
```json
31+
{ "configPatch": { "plugins": { "allow": ["telegram", "openai", "document-extract"] } } }
32+
```
33+
34+
Replace `<legacy_media.filename>` below with the recorded value and save the
35+
array as `pdf-exec-events.json` under `MANTIS_OUTPUT_DIR`:
36+
37+
```json
38+
[
39+
{
40+
"type": "response.output_item.added",
41+
"item": {
42+
"type": "function_call",
43+
"id": "fc_mantis_pdf_exec",
44+
"call_id": "call_mantis_pdf_exec",
45+
"name": "exec",
46+
"arguments": ""
47+
}
48+
},
49+
{
50+
"type": "response.function_call_arguments.delta",
51+
"delta": "{\"language\":\"javascript\",\"code\":\"return await pdf({ pdf: \\\"<legacy_media.filename>\\\", prompt: \\\"Inspect this PDF.\\\" });\"}"
52+
},
53+
{
54+
"type": "response.output_item.done",
55+
"item": {
56+
"type": "function_call",
57+
"id": "fc_mantis_pdf_exec",
58+
"call_id": "call_mantis_pdf_exec",
59+
"name": "exec",
60+
"arguments": "{\"language\":\"javascript\",\"code\":\"return await pdf({ pdf: \\\"<legacy_media.filename>\\\", prompt: \\\"Inspect this PDF.\\\" });\"}"
61+
}
62+
},
63+
{
64+
"type": "response.completed",
65+
"response": {
66+
"id": "resp_mantis_pdf_exec",
67+
"status": "completed",
68+
"output": [
69+
{
70+
"type": "function_call",
71+
"id": "fc_mantis_pdf_exec",
72+
"call_id": "call_mantis_pdf_exec",
73+
"name": "exec",
74+
"arguments": "{\"language\":\"javascript\",\"code\":\"return await pdf({ pdf: \\\"<legacy_media.filename>\\\", prompt: \\\"Inspect this PDF.\\\" });\"}"
75+
}
76+
],
77+
"usage": {
78+
"input_tokens": 64,
79+
"output_tokens": 16,
80+
"total_tokens": 80,
81+
"input_tokens_details": { "cached_tokens": 0 }
82+
}
83+
}
84+
}
85+
]
86+
```
87+
88+
Save this beside it as `pdf-exec-script.json`, install the two-response script,
89+
then send the tool-driven turn:
90+
91+
```json
92+
{
93+
"responses": [
94+
{ "eventsFile": "pdf-exec-events.json" },
95+
{ "text": "PDF tool round trip complete." }
96+
]
97+
}
98+
```
99+
100+
```bash
101+
script="$MANTIS_OUTPUT_DIR/pdf-exec-script.json"
102+
sha256="$(sha256sum "$script" | cut -d ' ' -f 1)"
103+
$lane mock --lane baseline --script "$script" "$sha256"
104+
tool_sent="$($lane send --lane baseline --text '@{sut} inspect the staged PDF with the pdf tool')"
105+
tool_message_id="$(jq -er '.sent.messageId' <<<"$tool_sent")"
106+
$lane observe --lane baseline --seconds 120 --until-provider-requests 3
107+
requests="$($lane requests --lane baseline)"
108+
jq -e '[.requests[] | .body.input[]? | select(.type == "function_call_output"
109+
and .call_id == "call_mantis_pdf_exec")] | length > 0' <<<"$requests"
110+
$lane finish --lane baseline --focus-message-id "$tool_message_id"
111+
```
112+
113+
`finish` tears the lane down, so wait for the cumulative provider-request count
114+
(staging turn, exec turn, follow-up) and assert the recorded
115+
`function_call_output` before finishing; its `output` carries the serialized
116+
exec result. Repeat the same script, turn, wait, and assertions for `candidate`.

‎.github/codex/prompts/mantis-telegram-desktop-proof.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ from `responseEvents` in `scripts/e2e/mock-openai-server.mjs`, and use
106106
`packages/ai/src/transports/openai-responses-stream-parity.test.ts` for reasoning
107107
event examples. These harness sources are safe to read; prepared proof worktrees
108108
remain off limits.
109+
The SUT agent runs Code Mode. Script catalog-tool turns as an `exec` function
110+
call whose JavaScript invokes the catalog tool, such as `pdf(...)`. See
111+
`mantis-recipes/staged-media-provider-proof.md` for the complete event script.
109112
For normal group turns, address the current bot with `@{sut}`; the harness
110113
expands it to the live SUT username. Omit it only when an unmentioned message
111114
is intentionally part of the scenario.

‎test/scripts/mantis-telegram-desktop-proof-workflow.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,18 @@ describe("Mantis Telegram Desktop proof workflow", () => {
781781
expect(prompt).toContain("not who sent it");
782782
expect(prompt).not.toContain("trusted, tamper-protected");
783783
expect(prompt).not.toContain("Provider request logs are diagnostic and pacing signals");
784+
expect(prompt).toContain("Script catalog-tool turns as an `exec` function");
785+
// The exec/pdf round trip outlives `send`; the recipe must wait for the
786+
// follow-up function_call_output request before `finish` tears the lane down.
787+
const stagedMediaRecipe = readFileSync(
788+
".github/codex/prompts/mantis-recipes/staged-media-provider-proof.md",
789+
"utf8",
790+
);
791+
expect(stagedMediaRecipe).toContain("--until-provider-requests 3");
792+
expect(stagedMediaRecipe).toContain('select(.type == "function_call_output"');
793+
expect(stagedMediaRecipe.indexOf("--until-provider-requests 3")).toBeLessThan(
794+
stagedMediaRecipe.lastIndexOf("finish --lane baseline"),
795+
);
784796
expect(prompt).toContain("mantis-recipes/");
785797
expect(prompt).toContain("recipe-suggestion.md");
786798
expect(prompt).toContain("do not call `finish` and describe the block only in prose");

0 commit comments

Comments
 (0)