fix(tasks): relay late Slack answers from completed runs - #72897
VojtechBartos wants to merge 1 commit into
Conversation
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.
|
Merging to
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 |
|
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 |
|
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 |
|
This PR was closed due to lack of activity. Feel free to reopen if it's still relevant. |
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_messageskipped every terminal run, so a wake-up answer landing during or shortly after teardown was silently dropped even though theSlackThreadTaskMappingstill exists.Origin: https://posthog.slack.com/archives/C09SK2PAGKF/p1784716116964029
Changes
relay_task_run_messagenow accepts runs whose terminal status isCOMPLETED;FAILEDandCANCELLEDruns stay silent since their terminal Slack card is the last word.agent_text_deltasignal, so the message goes through theposthog-code-agent-relayworkflow, which only needs the thread mapping.How did you test this code?
Automated only:
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
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).