Skip to content

[Bug]: CLI JSONL fallback parser drops final-answer semantics and can surface commentary instead #59918

Closed as not planned
BingqingLyu/openclaw
#1889

Description

@mySebbe

Summary

In a fallback run using an OpenAI/Codex-style CLI backend with output: "jsonl", OpenClaw can surface commentary/intermediate text instead of the terminal answer.

This looks adjacent to the broader “text between tool calls leaks to messaging channels” issue family, but narrower: in the captured fallback run, the JSONL stream already contained explicit phase markers plus a terminal task_complete.last_agent_message. The failure appears to be that the CLI JSONL parser loses those semantics and collapses the wrong text into the outbound reply.

Why this seems distinct from #25592

#25592 and related reports describe intermediate assistant text leaking from normal multi-turn tool loops.

In this case, the captured fallback JSONL already distinguishes:

  • phase: "commentary"
  • phase: "final_answer"
  • terminal task_complete.last_agent_message

So the problem here seems to be later in the pipeline: the CLI JSONL parser for fallback delivery is not preferring the terminal fields and can therefore surface commentary instead of the final answer.

Verified on

  • OpenClaw 2026.4.2 (d74a122)
  • npm-installed build on macOS arm64
  • Channel: WhatsApp DM
  • Trigger path: primary model stalled after a tool result, then fallback switched to an OpenAI CLI backend configured with output: "jsonl"

Observed chain

  1. Primary model started normally and made one tool call.
  2. The tool result came back.
  3. The primary model then stalled and OpenClaw recorded LLM idle timeout (60s): no response from model.
  4. Fallback switched to an OpenAI CLI backend with output: "jsonl".
  5. The fallback run itself completed successfully.
  6. User-visible delivery surfaced commentary/intermediate text instead of the final answer.

Important evidence

The captured fallback JSONL already had a clean separation between commentary and final answer. Sanitized shape:

{"type":"event_msg","payload":{"type":"agent_message","phase":"commentary","message":"..."}}
{"type":"response_item","payload":{"type":"message","role":"assistant","phase":"commentary","content":[{"type":"output_text","text":"..."}]}}
{"type":"event_msg","payload":{"type":"agent_message","phase":"final_answer","message":"..."}}
{"type":"response_item","payload":{"type":"message","role":"assistant","phase":"final_answer","content":[{"type":"output_text","text":"..."}]}}
{"type":"event_msg","payload":{"type":"task_complete","last_agent_message":"..."}}

So the terminal answer was already present twice:

  • as an assistant message tagged phase: "final_answer"
  • as task_complete.last_agent_message

Current parser gap

In the shipped 2026.4.2 build, the CLI JSONL parsing path still appears to:

  • special-case Claude CLI type: "result" lines
  • otherwise fall back to collecting generic text from parsed items
  • not prefer task_complete.last_agent_message
  • not prefer assistant messages tagged phase: "final_answer"
  • not ignore phase: "commentary" for outbound user delivery

I realize that statement is based on inspection of the installed npm dist build rather than the TypeScript source tree, but it matches the observed runtime behavior on 2026.4.2.

Expected behavior

For JSONL-style CLI backends used as user-visible fallbacks:

  1. Prefer task_complete.last_agent_message when present.
  2. Otherwise prefer assistant messages explicitly tagged phase: "final_answer".
  3. Ignore phase: "commentary" for outbound user delivery.
  4. Preserve current Claude CLI handling separately if needed.

Related

Happy to test a patch build if maintainers want a real-world confirmation case.

Activity

  1. mySebbe commented on Apr 2, 2026

    @mySebbe
    Author

    Opened a matching PR for this parser path: #59920

    Scope is intentionally narrow:

    • only src/agents/cli-output.ts
    • only parser regression tests in src/agents/cli-output.test.ts

    The patch prefers task_complete.last_agent_message, then phase:"final_answer", and skips commentary text for the generic fallback path.

    Verified locally with:

    • pnpm exec vitest run src/agents/cli-output.test.ts src/agents/cli-backends.test.ts
    • repo commit hooks / pnpm check during commit

    If maintainers want, I can also attach a sanitized real-world JSONL fixture from the failing fallback shape, but I kept the initial PR test coverage synthetic and minimal on purpose.

  2. clawsweeper commented on Apr 26, 2026

    @clawsweeper
    Contributor

    Closing this as duplicate or superseded after Codex automated review.

    #59918 should close as superseded by the matching open PR #59920. Current main does not yet implement the requested parser behavior, but the remaining work is already tracked in the reporter's narrow parser PR.

    What I checked:

    So I’m closing this here and keeping the remaining discussion on the canonical linked item.

    Codex Review notes: model gpt-5.5, reasoning high; reviewed against b64bfc5d9abf.

  3. locked as resolved and limited conversation to collaborators on Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions