:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(autoresearch): grant user:read to the training sandbox token (#109726)
posthog[bot]6e41c3ba0506
diff --git a/products/autoresearch/backend/training/AGENTS.md b/products/autoresearch/backend/training/AGENTS.mdindex 9bf9547858e3..703e0d3790de 100644--- a/products/autoresearch/backend/training/AGENTS.md+++ b/products/autoresearch/backend/training/AGENTS.md@@ -11,7 +11,7 @@ The other half is `../inference/`, which consumes what this package produces and- `runner.py`The real path. `run_training()` creates the `AutoresearchTrainingRun` (status `RUNNING`) and fires `Task.create_and_run()` with `internal=True` and no repository, so the run shows up as an internal Task rather than in the normal Tasks list.- The brief carries user-authored text, so the sandbox token holds only `TRAINING_MCP_SCOPES` (the `execute-sql` reads and the autoresearch scopes), and an empty connector allowlist keeps the team's shared MCP connectors out of the sandbox.+ The brief carries user-authored text, so the sandbox token holds only `TRAINING_MCP_SCOPES` (the `execute-sql` reads, the autoresearch scopes, and `user:read`, which the PostHog MCP server needs to start a session), and an empty connector allowlist keeps the team's shared MCP connectors out of the sandbox.`build_agent_description()` assembles the agent's brief — the target, the horizon, the population, and the contract for the bundle it must author.The agent drives the rest _itself_ through the `autoresearch-*` MCP tools: it records each iteration, uploads the bundle, and calls complete. Nothing polls it.- `stub.py`diff --git a/products/autoresearch/backend/training/runner.py b/products/autoresearch/backend/training/runner.pyindex 56df1b8afbed..938803ee367a 100644--- a/products/autoresearch/backend/training/runner.py+++ b/products/autoresearch/backend/training/runner.py@@ -68,9 +68,10 @@ MAX_SUGGESTION_PROMPT_CHARS = 1500MAX_PENDING_SUGGESTIONS = 10# The agent explores with execute-sql (query:read, insight:read) and writes only through-# the autoresearch tools. The brief carries user-authored text, so the token grants-# nothing beyond that.-TRAINING_MCP_SCOPES = ["query:read", "insight:read", "autoresearch:read", "autoresearch:write"]+# the autoresearch tools. The PostHog MCP server reads /api/users/@me/ to start a session,+# so without user:read it refuses the connection and the agent gets none of those tools.+# The brief carries user-authored text, so the token grants nothing beyond that.+TRAINING_MCP_SCOPES = ["query:read", "insight:read", "user:read", "autoresearch:read", "autoresearch:write"]# Task.title is a 255-character column, and a pipeline name and target event can each# take all of it.diff --git a/products/autoresearch/backend/training/test_training.py b/products/autoresearch/backend/training/test_training.pyindex 40ad29b86dae..b80452328d14 100644--- a/products/autoresearch/backend/training/test_training.py+++ b/products/autoresearch/backend/training/test_training.py@@ -164,6 +164,7 @@ class TestRunTraining(TeamScopedTestMixin, BaseTest):kwargs = facade.create_and_run_task.call_args.kwargsassert kwargs["posthog_mcp_scopes"] == TRAINING_MCP_SCOPES+ assert "user:read" in kwargs["posthog_mcp_scopes"]assert kwargs["extra_run_state"] == {"autoresearch_training_run_id": str(training_run.id),"config_snapshot": {"connectors": {"mcp_installation_ids": []}},