Skip to content

Relay background-turn responses to Slack#3704

Draft
VojtechBartos wants to merge 1 commit into
mainfrom
vojtab/relay-background-turn-slack
Draft

Relay background-turn responses to Slack#3704
VojtechBartos wants to merge 1 commit into
mainfrom
vojtab/relay-background-turn-slack

Conversation

@VojtechBartos

@VojtechBartos VojtechBartos commented Jul 22, 2026

Copy link
Copy Markdown
Member

Problem

When the cloud agent starts a background process and ends its turn to wait for it ("I'll wait for the completion notification"), the wake-up turn that eventually produces the answer never reaches Slack. A background (task-notification) turn resolves no tracked prompt() call, and relayAgentResponse only fires at the three prompt-resolution sites, so the relay for that turn simply never happens. The agent's transcript contains the answer, the user's thread doesn't, and the agent has no way to know the reply was dropped.

Origin: https://posthog.slack.com/archives/C09SK2PAGKF/p1784716116964029

Changes

  • agent-server.ts: the ACP transport tap now triggers relayAgentResponse when a clean _posthog/background_turn_complete (stop reason end_turn) passes through. Refusal/error background turns stay silent, matching the tracked path's end_turn gating.
  • session-log-writer.ts: relays now consume prose through a new takeUnrelayedAgentResponseParts, which returns only the text blocks no prior relay has delivered. Background turns append to the same turn buffer as the tracked turn before them (only a new prompt resets it), so an unscoped read would re-post already-delivered prose, and a silent wake-up (e.g. the agent just reschedules) would re-post the previous answer verbatim.
  • Tracked-turn relays behave exactly as before: the buffer resets at prompt start, so the first take returns the full turn.

Companion backend PR (accepts late relays from completed runs): PostHog/posthog#72897

How did you test this?

Automated only, all in packages/agent:

  • New: agent-server.test.ts "background turn relay" — relays prose on a clean background_turn_complete, skips non-end_turn stop reasons, skips silent wake-ups.
  • New: session-log-writer.test.ts — take-cursor semantics (only prose since previous take; reset starts over).
  • Updated existing relay stubs (question-relay.test.ts, relay-echo tests) to the consuming API.
  • Full runs: agent-server.test.ts (150 passed), session-log-writer.test.ts + question-relay.test.ts (87 passed), claude-agent.task-notification.test.ts (2 passed), tsc --noEmit, biome check.

Automatic notifications

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

A background (task-notification) turn resolves no tracked prompt, so the
prompt-resolution relay sites never fire for it: when the agent ends its
turn to wait on a background process, the answer it produces on wake-up
never reaches Slack, and the agent has no way to know it was dropped.

Trigger the relay from the ACP transport tap when a clean
_posthog/background_turn_complete passes through, and scope every relay
to the prose no prior relay has delivered (background turns append to
the same turn buffer as the tracked turn before them, so an unscoped
read would re-post already-delivered prose, and a silent wake-up would
re-post the previous answer).
@VojtechBartos VojtechBartos self-assigned this Jul 22, 2026
@trunk-io

trunk-io Bot commented Jul 22, 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

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit cc759dc.

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