Skip to content

feat(agent): echo initiating message_id on relay_message#3434

Draft
VojtechBartos wants to merge 1 commit into
mainfrom
vojtab/relay-echo-message-id
Draft

feat(agent): echo initiating message_id on relay_message#3434
VojtechBartos wants to merge 1 commit into
mainfrom
vojtab/relay-echo-message-id

Conversation

@VojtechBartos

@VojtechBartos VojtechBartos commented Jul 14, 2026

Copy link
Copy Markdown
Member

Problem

When a turn finishes, the agent-server relays the final answer to the backend's relay_message endpoint with only text/text_parts. The relay carries no correlation to the user message it answers, so the backend has to guess who to @-mention in Slack from mutable state, which mis-tags replies in multiplayer threads.

Changes

  • Echo the messageId of the user_message command that initiated the turn (the same id already used for duplicate-delivery suppression) as an optional message_id field in the relay_message POST body. The id is captured in the handler closure, so overlapping turns each relay their own initiating message's id.
  • Backward compatible: the field is omitted whenever no message id is known (e.g. the boot prompt), so older backends see the exact same payload as before.

The consuming backend change (using message_id to attribute Slack replies) lands separately in PostHog/posthog, as a follow-up to the Slack follow-up queue work (PostHog/posthog#70806, PostHog/posthog#70762).

How did you test this?

  • Added tests: relay echoes each turn's own initiating id end-to-end through the /command HTTP endpoint (including overlapping turns, the no-id case, and no id leaking from a failed turn into the next), relayAgentResponse pass-through, and the relay_message request body shape.
  • pnpm --filter @posthog/agent test — 78 files, 1295 tests passed.
  • pnpm --filter @posthog/agent typecheck and biome check on touched files — clean.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

@VojtechBartos VojtechBartos self-assigned this Jul 14, 2026
@trunk-io

trunk-io Bot commented Jul 14, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit f11ab9f.

Pass the id of the user_message command that initiated a turn from the
handler closure to relayAgentResponse and include it as an optional
message_id field in the relay_message POST body. Each turn's relay
carries its own initiating message's id; the field is omitted when no
id is known (e.g. the boot prompt), so older backends are unaffected.
@VojtechBartos VojtechBartos force-pushed the vojtab/relay-echo-message-id branch from 4c745d2 to f11ab9f Compare July 15, 2026 08:01
@VojtechBartos VojtechBartos changed the title feat(agent): echo initiating message_id on relay_message and turn_complete feat(agent): echo initiating message_id on relay_message Jul 15, 2026
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