feat(tasks): add tasks-agent-proxy-keep-stream-open flag#67492
Conversation
There was a problem hiding this comment.
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.
|
Reviews (1): Last reviewed commit: "wire tasks-agent-proxy-keep-stream-open ..." | Re-trigger Greptile |
663831d to
013f21d
Compare
New commits pushed (delta classified non_linear_history) — stamphog approval dismissed; re-review running automatically.
There was a problem hiding this comment.
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.
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 1 · PR risk: 0/10 |
Problem
Task-run events stream to the agent-proxy as one long-lived NDJSON upload. In
@posthog/codethe 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-openfeature flag and threads its evaluated value to the sandbox agent-server, mirroring the existingtasks-cloud-runs-sandbox-event-ingestwiring:_is_agent_proxy_keep_stream_open_enabled(...), evaluated once inget_task_processing_contextand captured onTaskProcessingContext.agent_proxy_keep_stream_openso it stays deterministic across activity retries._prepare_launch->sandbox.start_agent_server->build_agent_runtime_env_prefix, which setsPOSTHOG_TASK_RUN_EVENT_INGEST_KEEP_STREAM_OPEN=trueonly when enabled (unset otherwise).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_openacrosstest_docker_sandbox.py,test_modal_sandbox.py,test_get_task_processing_context.py-> 9 passed.ruff check+ruff format --checkon all changed files -> clean.rufflint/format +tytype 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
Docs update
No user-facing docs; internal rollout flag.
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
@posthog/codeper-batch proxy stream-close behavior behind a real PostHog feature flag, off by default.tasks-cloud-runs-sandbox-event-ingestmechanism (flag constant -> context evaluator ->TaskProcessingContextfield ->_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.