Skip to content

fix(tasks): relay late Slack answers from completed runs - #72897

Closed
VojtechBartos wants to merge 1 commit into
masterfrom
vojtab/slack-relay-terminal-run
Closed

VojtechBartos wants to merge 1 commit into
masterfrom
vojtab/slack-relay-terminal-run

Conversation

@VojtechBartos

Copy link
Copy Markdown
Member

Problem

When the sandbox agent ends its turn to wait on a background process, the wake-up turn that produces the answer is a background (task-notification) turn. Those never resolved a tracked prompt, so agent-server never relayed them to Slack (fixed in PostHog/code#3704). On this side there is a second hole: a Slack-origin run idling on background work hits the 30-minute inactivity timeout and gets marked completed, and relay_task_run_message skipped every terminal run, so a wake-up answer landing during or shortly after teardown was silently dropped even though the SlackThreadTaskMapping still exists.

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

Changes

  • relay_task_run_message now accepts runs whose terminal status is COMPLETED; FAILED and CANCELLED runs stay silent since their terminal Slack card is the last word.
  • For a completed run the agent-design inline-stream branch is bypassed: the run's workflow is closed and can't receive the agent_text_delta signal, so the message goes through the posthog-code-agent-relay workflow, which only needs the thread mapping.
  • Non-terminal runs behave exactly as before.

How did you test this code?

Automated only:

  • New: relay accepted for a completed run with a Slack mapping (catches the dropped late background answer).
  • New: completed run with agent-design state posts via the relay workflow instead of signaling the closed workflow.
  • New (parameterized): failed and cancelled runs with a mapping still skip.
  • Full run: pytest products/tasks/backend/tests/test_api.py -k relay_message (10 passed), ruff, file-scoped mypy clean, hogli ci:preflight --fix (0 failures).

Automatic notifications

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

Docs update

Not needed: internal relay behavior, no user-facing workflow change.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Built with Claude Code from an investigation of the Slack thread above: the bot answered questions in its transcript but never posted the answers when the work went through a background process. The classic relay is push-based from agent-server on prompt resolution, so the fix has two halves: PostHog/code#3704 makes agent-server relay background turns, and this PR stops the backend from rejecting relays that arrive after the run's inactivity-timeout completion. An alternative of keeping the run alive while background work is pending was considered and deferred as a follow-up with real design surface (heartbeat semantics, caps).

A background (task-notification) turn can finish while its run is being
torn down, or just after the inactivity timeout marked the run
completed. relay_task_run_message skipped every terminal run, so that
answer was silently dropped even though the Slack thread mapping still
exists. Accept completed runs (failed and cancelled stay silent) and
route them to the relay workflow directly, since a closed workflow can
no longer receive the agent-design inline-stream signal.
@trunk-io

trunk-io Bot commented Jul 28, 2026

Copy link
Copy Markdown

Merging to master 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

@scheduled-actions-posthog

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the stale label – otherwise this will be closed in another week. If you want to permanently keep it open, use the waiting label.

@scheduled-actions-posthog

Copy link
Copy Markdown
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the stale label – otherwise this will be closed in another week. If you want to permanently keep it open, use the waiting label.

@scheduled-actions-posthog

Copy link
Copy Markdown
Contributor

This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant