Skip to content

A successful tool result without data strands the turn (TypeError in spillOrTruncate) #229

Open

Description

@Anarchid

Found while reviewing #220. Present on main (e457abd).

What happens. ToolResult.data is optional, but a successful result without it throws while the result is being stored, before the tool_result is handed back to the stream:

TypeError: Cannot read properties of undefined (reading 'length')
    at AgentFramework.spillOrTruncate
    at AgentFramework.buildStoredToolResultContent
    at AgentFramework.handleProcessEvent

Repro. A module tool that returns { success: true }; one mock-membrane turn calling it. The agent stays in ready, the stream never receives tool results, the tool_use is already persisted, and framework.stop() then hung in my probe. Same on main and on #220's head.

The MCPL path can produce the same shape: a successful tools/call with content: [] (or only empty text blocks) maps to data: undefined:

agent-framework/src/framework.ts

Lines 14518 to 14527 in e457abd

const textContent = result.content
?.filter((c) => c.type === 'text' && c.text)
.map((c) => c.text!)
.join('\n');
const hasNonText = result.content?.some((c) => c.type !== 'text');
const data = result.isError
? undefined
: hasNonText
? result.content
: (textContent || undefined);

Direction. Normalize absent data to a stable string (e.g. '' or '(no output)') in toolResultDataToHistoryString, and make the result-storage step fail the one call rather than the event, so a bad result still pairs its tool_use.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions