Skip to content

fix(headless): persist tool calls on -p --session (resume cutoff); mermaid validation - #407

Merged
yogthos merged 2 commits into
mainfrom
session-resume-cutoff
Jun 11, 2026
Merged

fix(headless): persist tool calls on -p --session (resume cutoff); mermaid validation#407
yogthos merged 2 commits into
mainfrom
session-resume-cutoff

Conversation

@yogthos

@yogthos yogthos commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

The resume "cutoff" bug

Found while testing the MCP delegation loop. dirge -p --session <id> saved the conversation, but the assistant message stored only its final text — every tool call/result was dropped (verified: a saved MCP session had tool_calls=0 on assistant turns that actually wrote/edited files). Consequences on resume:

  • A resumed --session (e.g. an MCP delegation follow-up) lost the substance of prior turns — dirge saw "I did X" but not what the tools actually did.
  • A tool-heavy final turn — which often ends with little or no trailing text — saved an empty/thin assistant message, reading as a cut-off end.

(The companion resume fix — feeding the loaded history back to the model at all — already shipped in #406. This adds full fidelity.)

Fix: run_print now accumulates the turn's ToolCall/ToolResult events (mirroring the interactive run_handlers/tool_call.rs + tool_result.rs) and returns them; the print path saves via add_message_with_tool_calls, so convert_history re-emits the tool_use/tool_result blocks on resume. The --loop caller ignores them.

Verified live: dirge -p --session X "create a file FOO.txt" now saves the assistant message with tool_calls=[write, read] instead of 0.

Plugin review: plugins/mermaid_diagram.janet

Reviewed as requested. The structure is sound (the stem-prefixed hook names are a supported form; request-prompt/append-system-prompt/3-arg add-custom-message all exist). Fixed validation gaps in validate-diagram:

  • The edge check only matched --> / ->> / ---, so valid er/class/state diagrams (and flowchart -.-> / ==>) were rejected for "no connections". Broadened to -- / ->> / ==> / -.-.
  • Added a {}-balance check ({decision} / {{hexagon}} nodes were unchecked).
  • Dropped a stray [ from the unbalanced-brackets error message.
  • max-retriesdef (never reassigned).

Parses clean (janet parse-all).

Tests

Full suite 2612 pass; run_print signature change covered by the existing print tests + live verification.

Yogthos added 2 commits June 11, 2026 18:43
The headless save stored only the user prompt + the assistant's final
text, dropping every tool call/result. So a resumed --session (e.g. an
MCP delegation follow-up) lost the actual work history, and a tool-heavy
final turn — which often has little or no trailing text — saved an
empty/thin assistant message that read as a cut-off end.

run_print now accumulates the turn's ToolCall/ToolResult events (mirroring
the interactive run_handlers) and returns them; the print path saves via
add_message_with_tool_calls so convert_history re-emits the tool_use /
tool_result blocks on resume. The --loop caller ignores them.

Verified live: 'dirge -p --session X "create a file"' now saves the
assistant message with tool_calls=[write, read] instead of 0.
- Edge check only matched --> / ->> / ---, so valid er/class/state
  diagrams (and flowchart -.-> / ==>) were rejected for 'no connections'.
  Broaden to the common --/->> /==>/-.- connectors.
- Add a {}-balance check ({decision}/{{hexagon}} nodes were unchecked).
- Drop a stray '[' from the unbalanced-brackets error message.
- max-retries is never reassigned — def, not var.

Parses clean (janet parse-all).
@yogthos
yogthos merged commit 33f10cb into main Jun 11, 2026
11 checks passed
@yogthos
yogthos deleted the session-resume-cutoff branch June 11, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant