Skip to content

fix(agents-runtime): carry message_type through inbox timeline so composer_input reaches the agent as text#4718

Open
andresberrios wants to merge 1 commit into
electric-sql:mainfrom
andresberrios:fix/composer-input-inbox-message-type
Open

fix(agents-runtime): carry message_type through inbox timeline so composer_input reaches the agent as text#4718
andresberrios wants to merge 1 commit into
electric-sql:mainfrom
andresberrios:fix/composer-input-inbox-message-type

Conversation

@andresberrios

Copy link
Copy Markdown

Problem

Messages typed in the composer arrive to the agent as raw JSON — e.g. the model receives {"source":"summarize the article"} instead of the plain text summarize the article. This makes the agent respond about JSON rather than the actual message.

Root cause

composer_input inbox messages are projected to model text by projectInboxPayload (timeline-context.ts), which extracts payload.source (or payload.text) only when item.message_type === COMPOSER_INPUT_MESSAGE_TYPE. Otherwise it falls back to JSON.stringify(payload).

When the entity timeline is materialized from the db, buildInboxMessages in entity-timeline.ts rebuilds each inbox row but drops message_type. So by the time projectInboxPayload runs, message_type is undefined, the composer_input branch is never taken, and the raw payload is stringified.

message_type is present on the underlying collection row (MessageReceivedValue) and is already permitted on IncludesInboxMessage (the Omit doesn't exclude it) — it was simply not copied through.

Fix

Carry message_type through buildInboxMessages. One field; no type changes needed.

Test

Added a regression test to test/timeline-context.test.ts that drives the db read path (timelineToMessages) with a composer_input row and asserts the source text is extracted. The existing composer_input test only exercised buildTimelineMessages with a hand-built timeline, so it bypassed buildInboxMessages and didn't catch this. Verified the new test fails before the fix and passes after.

Notes

  • Changeset included (patch for @electric-ax/agents-runtime).
  • pnpm --filter @electric-ax/agents-runtime test passes for the timeline suite. Two unrelated failures exist in a fresh clone and are not touched by this change: tool-providers.test.ts (can't resolve the unbuilt @electric-ax/agents-mcp sibling package) and a flaky heartbeat-timing assertion in pull-wake-runner.test.ts.

…poser_input reaches the agent as text

buildInboxMessages dropped the message_type field when materializing the
entity timeline from the db. Without it, projectInboxPayload could no longer
recognize composer_input messages and fell back to JSON.stringify(payload),
so the model received `{"source":"..."}` instead of the plain text the user
typed. Carry message_type through and add a regression test that exercises
the db read path.
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