Skip to content

feat(tasks): add tasks-agent-proxy-keep-stream-open flag#67492

Merged
charlesvien merged 1 commit into
masterfrom
feat/tasks-agent-proxy-keep-stream-open
Jul 1, 2026
Merged

feat(tasks): add tasks-agent-proxy-keep-stream-open flag#67492
charlesvien merged 1 commit into
masterfrom
feat/tasks-agent-proxy-keep-stream-open

Conversation

@charlesvien

Copy link
Copy Markdown
Member

Problem

Task-run events stream to the agent-proxy as one long-lived NDJSON upload. In @posthog/code the sender was changed to optionally close that upload per drained batch (companion PR PostHog/code#3067) so a buffering ingress forwards each batch within a round-trip instead of stranding events in a long-lived upload. We want to roll that out gradually rather than flip it for every run, so it needs a server-evaluated feature flag.

Changes

Introduces the tasks-agent-proxy-keep-stream-open feature flag and threads its evaluated value to the sandbox agent-server, mirroring the existing tasks-cloud-runs-sandbox-event-ingest wiring:

  • Add the flag constant and _is_agent_proxy_keep_stream_open_enabled(...), evaluated once in get_task_processing_context and captured on TaskProcessingContext.agent_proxy_keep_stream_open so it stays deterministic across activity retries.
  • Pass it through _prepare_launch -> sandbox.start_agent_server -> build_agent_runtime_env_prefix, which sets POSTHOG_TASK_RUN_EVENT_INGEST_KEEP_STREAM_OPEN=true only when enabled (unset otherwise).
  • The agent-server reads that env var and keeps the proxy ingest stream open when set (companion PR feat(agent): add keep-proxy-stream-open ingest flag code#3067).

Off by default: no env var is emitted unless the flag resolves true, so existing runs are unaffected.

How did you test this code?

Automated (ran locally, all green):

  • pytest -k keep_stream_open across test_docker_sandbox.py, test_modal_sandbox.py, test_get_task_processing_context.py -> 9 passed.
  • ruff check + ruff format --check on all changed files -> clean.
  • Pre-commit hook ran ruff lint/format + ty type check -> clean.

I did not run the full tasks Temporal suite or exercise a live sandbox.

The docker/modal tests catch a regression where the flag stops reaching the sandbox launch command; the evaluator tests catch the flag failing open on a flag-service error or ignoring the run-state override.

Automatic notifications

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

Docs update

No user-facing docs; internal rollout flag.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Tool: Claude Code (Opus), directed by @charlesvien to put the @posthog/code per-batch proxy stream-close behavior behind a real PostHog feature flag, off by default.
  • Approach: mirrored the established tasks-cloud-runs-sandbox-event-ingest mechanism (flag constant -> context evaluator -> TaskProcessingContext field -> _prepare_launch -> sandbox env prefix) so the flag evaluates server-side and reaches the sandbox as an env var, rather than inventing a new path.
  • Polarity chosen deliberately: flag on = keep the proxy stream open (buffered); default off = today's per-batch close, so enabling is the opt-in.

@charlesvien charlesvien self-assigned this Jul 1, 2026
@charlesvien charlesvien added stamphog Request AI approval (no full review) skip-inkeep-docs Use this label to skip an Inkeep docs PR in posthog.com labels Jul 1, 2026
@charlesvien charlesvien marked this pull request as ready for review July 1, 2026 18:23
@assign-reviewers-posthog assign-reviewers-posthog Bot requested a review from a team July 1, 2026 18:24
github-actions[bot]
github-actions Bot previously approved these changes Jul 1, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely additive feature-flag-gated change: new parameter defaults to False throughout, env var set via shlex.quote (no injection risk), fail-closed flag check, and well-tested with parametrized coverage. No behavioral change to existing code paths.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "wire tasks-agent-proxy-keep-stream-open ..." | Re-trigger Greptile

Comment thread products/tasks/backend/logic/services/test_docker_sandbox.py Outdated
Comment thread products/tasks/backend/logic/services/tests/test_modal_sandbox.py Outdated
@charlesvien charlesvien force-pushed the feat/tasks-agent-proxy-keep-stream-open branch from 663831d to 013f21d Compare July 1, 2026 18:33
@github-actions github-actions Bot dismissed their stale review July 1, 2026 18:34

New commits pushed (delta classified non_linear_history) — stamphog approval dismissed; re-review running automatically.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely additive feature-flag-gated change: new parameter defaults to False throughout, env var set via shlex.quote (no injection risk), fail-closed flag check, and well-tested with parameterized coverage. No behavioral change to existing code paths. The greptile comments about parameterized tests were addressed and marked resolved.

@charlesvien charlesvien enabled auto-merge (squash) July 1, 2026 18:43
@veria-ai

veria-ai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

@charlesvien charlesvien merged commit 89857aa into master Jul 1, 2026
193 checks passed
@charlesvien charlesvien deleted the feat/tasks-agent-proxy-keep-stream-open branch July 1, 2026 18:54
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 1, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-01 19:19 UTC Run
prod-us ✅ Deployed 2026-07-01 19:35 UTC Run
prod-eu ✅ Deployed 2026-07-01 19:37 UTC Run

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

Labels

skip-inkeep-docs Use this label to skip an Inkeep docs PR in posthog.com stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants