fix(agent): attachments no longer crash linked-session turns; ask_user closes its tool batch

Two agent-loop bugs found in the Sep 24 loop evaluation, folded into the
1.5.7 line:

1. A linked-session turn whose user message carried an image/video/document
   attachment crashed 100% of the time: derive_llm_history projects multimodal
   content as an OpenAI parts list, and orchestrate() read that list as the
   goal and called .strip() on it (AttributeError: 'list' object has no
   attribute 'strip'). New log.text_of_content() extracts the text part; the
   goal read uses it, so single-loop and swarm paths both survive attachments.

2. When ask_user paused the turn mid tool-batch, the remaining calls of that
   step never executed but also never received tool results, leaving an
   assistant tool_calls message with dangling ids - an invalid request
   sequence that strict OpenAI-compatible servers 400 on the next turn. The
   pause path now synthesizes skipped tool/call + tool/result events and
   tool-role messages for the un-executed ids before ending the turn.

The new multimodal-goal tests now stub the planner LLM: the attachment
appendix puts newlines in the extracted goal, so the message is never
trivial-path and the unstubbed planner made a real network call - the source
of the tests' flakiness (and the swarm-path test now attaches the document
it always claimed to).

Backend suite: 538 passed.
This commit is contained in:
Benjiyaya
2026-09-24 03:28:19 +08:00
parent d2240b9c5a
commit a8fc4e451c
6 changed files with 366 additions and 7 deletions
@@ -5,7 +5,8 @@ Three reported issues fixed — [#66](https://github.com/benjiyaya/Calliope/issu
[#64](https://github.com/benjiyaya/Calliope/issues/64) (scripts ignored the
story's target length), and
[#67](https://github.com/benjiyaya/Calliope/issues/67) (a directory path
passed as a video input crashed ComfyUI with `Errno 21`).
passed as a video input crashed ComfyUI with `Errno 21`) — plus two agent-loop
bugs found in the Sep 24 loop evaluation.
## #66 — Workflow choice is per clip
@@ -53,10 +54,32 @@ opaque `ValueError: [Errno 21] Is a directory`.
fails the tool call with correction guidance instead of creating a doomed
job.
## Agent loop — attachments crash and dangling tool calls
Two crashes found by the Sep 24 agent-loop evaluation, folded into this line:
- **Attached images/videos/documents crashed every linked-session turn.**
Multimodal user content projects as an OpenAI parts *list*, but the
orchestrator read that list as the turn's goal and called `.strip()` on it
(`AttributeError: 'list' object has no attribute 'strip'`) — any
project-linked session turn with an attachment failed 100% of the time.
A new `text_of_content()` helper extracts the text part, and both the
single-loop and swarm (planner) paths now survive attachments.
- **`ask_user` mid tool-batch left dangling tool calls.** When the model
issued `ask_user` alongside other tool calls, the rest of the batch never
executed but also never received results — an assistant `tool_calls`
message with missing results is an invalid request sequence that strict
OpenAI-compatible servers reject on the next turn. The pause path now
synthesizes skipped tool results for the un-executed ids before ending
the turn.
## Testing
- `tests/test_script_chunking.py` — per-scene budget present in both prompt
builders; oversized-script durations shrink toward the target.
- `tests/test_video_continue.py` — directory and missing-file rejection,
bare-name passthrough, existing-file upload still works.
- Full backend suite: 534 passed; `svelte-check`: 0 errors.
- `tests/test_agent_harness.py` — multimodal goal (single + swarm paths),
`text_of_content` shapes, mid-batch `ask_user` closure; planner stubbed so
the tests never make a real LLM call.
- Full backend suite: 538 passed; `svelte-check`: 0 errors.
+1 -1
View File
@@ -2,7 +2,7 @@
Dated notes for GitHub releases. Newest first.
- [2026-09-24 clip workflow + runtime budget](./2026-09-24-clip-workflow-runtime-budget.md) — workflow per clip (not per scene); target runtime is a budget that can shrink; media inputs that are directories fail fast with a node-naming error (1.5.7)
- [2026-09-24 clip workflow + runtime budget](./2026-09-24-clip-workflow-runtime-budget.md) — workflow per clip (not per scene); target runtime is a budget that can shrink; media inputs that are directories fail fast with a node-naming error; attachment turns no longer crash the orchestrator, `ask_user` closes its tool batch (1.5.7)
- [2026-09-22 project name alias patch](./2026-09-22-project-name-alias.md) — `name` accepted for a project's title on the REST API and agent tools; fixes storyline builds dead-ending on a 422 (1.5.6)
- [2026-09-22 swarm render/scene fixes](./2026-09-22-swarm-render-scene-fixes.md) — video-role render tools reachable (ask_user recovery); story role gains scene tools; deep-link sessions no longer orphan; canvas auto-seeds new entities (1.5.5)
- [2026-09-19 steering + Asset Library + hardening](./2026-09-19-steering-library-hardening.md) — mid-run steering; Asset Library page (filter + lazy loading); canvas delete that deletes; agent-loop hardening batch; Build Scene Brief/Cut gates (1.5.4)