: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(tasks): disable skills during repository selection (#128138)
Georgiy Tarasov45b2133d219e
diff --git a/packages/agent/packages/agent-contracts/src/domain-types.ts b/packages/agent/packages/agent-contracts/src/domain-types.tsindex d0f67c455cf8..67ab3a9e69f7 100644--- a/packages/agent/packages/agent-contracts/src/domain-types.ts+++ b/packages/agent/packages/agent-contracts/src/domain-types.ts@@ -371,6 +371,7 @@ const taskRunStateFields = {codex_max_subagents: optionalField(z.number().int().positive()),codex_shared_prompt_cache: optionalField(z.boolean()),disable_repo_hooks: optionalField(z.boolean()),+ disable_skills: optionalField(z.boolean()),initial_permission_mode: optionalField(executionModeSchema),initial_prompt_override: optionalField(z.string()),pending_followup_messages: optionalField(diff --git a/packages/agent/packages/agent/src/server/agent-server.test.ts b/packages/agent/packages/agent/src/server/agent-server.test.tsindex 26660cace27a..9d35ecdc0218 100644--- a/packages/agent/packages/agent/src/server/agent-server.test.ts+++ b/packages/agent/packages/agent/src/server/agent-server.test.ts@@ -1009,6 +1009,41 @@ describe("AgentServer HTTP Mode", () => {30000,);+ it.each([true, false])(+ "applies the caller's skill setting (%s)",+ async (disableSkills) => {+ mswServer.use(+ http.get(+ "http://localhost:8000/api/projects/:projectId/tasks/:taskId/runs/:runId/",+ () =>+ HttpResponse.json(+ createTaskRun({+ id: "test-run-id",+ state: { disable_skills: disableSkills },+ }),+ ),+ ),+ );+ mockedClaudeSdk.query.mockClear();+ const s = createServer({+ runtimeAdapter: "claude",+ reasoningEffort: "high",+ });+ await s.start();+ const request = mockedClaudeSdk.query.mock.lastCall?.[0] as unknown as {+ options: { skills?: string[]; effort?: string; tools?: unknown };+ };+ expect(request?.options?.skills).toEqual(+ disableSkills ? [] : undefined,+ );+ expect(request?.options?.effort).toBe("high");+ expect(request?.options?.tools).toEqual({+ type: "preset",+ preset: "claude_code",+ });+ },+ );+it("keeps the run-state system prompt after a transient run fetch failure", async () => {let attempts = 0;mswServer.use(diff --git a/packages/agent/packages/agent/src/server/agent-server.ts b/packages/agent/packages/agent/src/server/agent-server.tsindex a330a3cb31c1..450492d87910 100644--- a/packages/agent/packages/agent/src/server/agent-server.ts+++ b/packages/agent/packages/agent/src/server/agent-server.ts@@ -2496,7 +2496,7 @@ export class AgentServer {this.config.fastMode !== undefined && {fastMode: this.config.fastMode,}),- ...this.buildClaudeCodeSessionMeta(runtimeAdapter),+ ...this.buildClaudeCodeSessionMeta(runtimeAdapter, launch.disableSkills),};await this.measureInitialization("repository_ready", () =>@@ -4570,12 +4570,13 @@ export class AgentServer {*/private buildClaudeCodeSessionMeta(runtimeAdapter: Adapter,+ disableSkills = false,): { claudeCode: { options: Record<string, unknown> } } | undefined {const plugins = this.config.claudeCode?.plugins;const effort =runtimeAdapter === "claude" ? this.config.reasoningEffort : undefined;- if (!plugins?.length && !effort) {+ if (!plugins?.length && !effort && !disableSkills) {return undefined;}@@ -4586,6 +4587,9 @@ export class AgentServer {if (effort) {options.effort = effort;}+ if (disableSkills) {+ options.skills = [];+ }return { claudeCode: { options } };}diff --git a/packages/agent/packages/agent/src/server/launch/run-launch.ts b/packages/agent/packages/agent/src/server/launch/run-launch.tsindex 07041fdfbb0c..6c03aede61a3 100644--- a/packages/agent/packages/agent/src/server/launch/run-launch.ts+++ b/packages/agent/packages/agent/src/server/launch/run-launch.ts@@ -36,6 +36,7 @@ export interface RunLaunch {readonly endRunWhenDone: boolean;readonly callerEndsRun: boolean;readonly disableRepoHooks: boolean;+ readonly disableSkills: boolean;readonly systemPrompt: ClaudeCodeConfig["systemPrompt"];readonly systemPromptValid: boolean;readonly tokenUsage: unknown;@@ -71,6 +72,7 @@ export function readRunLaunch(sources: RunLaunchSources): RunLaunch {endRunWhenDone: runState?.end_run_when_done === true,callerEndsRun: runState?.caller_ends_run === true,disableRepoHooks: runState?.disable_repo_hooks === true,+ disableSkills: runState?.disable_skills === true,systemPrompt: systemPrompt.success ? systemPrompt.data : undefined,systemPromptValid: systemPrompt.success,tokenUsage: runState?.token_usage,diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.pyindex ece277439179..2f7558ae03ac 100644--- a/products/tasks/backend/facade/api.py+++ b/products/tasks/backend/facade/api.py@@ -578,6 +578,7 @@ _TASK_RUN_PUBLIC_STATE_KEYS = frozenset("context_window","custom_image_id","disable_repo_hooks",+ "disable_skills","fast_mode",# An imported transcript's provenance and mirror cursor: the viewer marks the run as# imported, and the legacy mirror reads its own cursor back through this DTO.@@ -3029,6 +3030,7 @@ _PROTECTED_RUN_STATE_KEYS = frozenset("scout_trial_judge","scout_trial_private","include_live_context",+ "disable_skills","analytics_query_context","sandbox_oauth_token_ids",# Sandbox run-start lineage and fan-out count. A child sandbox that removed its parent keysdiff --git a/products/tasks/backend/logic/repo_selection/agent.py b/products/tasks/backend/logic/repo_selection/agent.pyindex 070a1652af66..f93fea52736d 100644--- a/products/tasks/backend/logic/repo_selection/agent.py+++ b/products/tasks/backend/logic/repo_selection/agent.py@@ -760,6 +760,7 @@ async def select_repository(# Read-only PostHog scopes so the agent can call `execute-sql` against `system.integration_repository_cache`.posthog_mcp_scopes="read_only",github_read_access=True,+ disable_skills=True,sandbox_resources=SandboxResources(cpu_cores=2, memory_gb=8),# Optional agent runtime/model override (e.g. the Codex runtime + gpt-5.5). All-None keeps# the agent-server default; threaded through from the caller's per-step resolution.diff --git a/products/tasks/backend/logic/services/custom_prompt_internals.py b/products/tasks/backend/logic/services/custom_prompt_internals.pyindex 753fc0020d22..a380a55752d2 100644--- a/products/tasks/backend/logic/services/custom_prompt_internals.py+++ b/products/tasks/backend/logic/services/custom_prompt_internals.py@@ -145,6 +145,7 @@ class CustomPromptSandboxContext:"""Let runs that start from the same prompt prefix read each other's prompt cache. Codex-only. Theagent server asks the AI gateway to drop Codex's per-session cache key on every request of the run,sub-agents included."""+ disable_skills: bool = Falsedisable_repo_hooks: bool = False"""Stop hooks from the cloned repo's ``.claude/settings*.json`` from running. A repo's Stop hookcan block the turn that must return the caller's JSON. The agent still reads the repo's CLAUDE.md.@@ -363,6 +364,8 @@ async def _create_task_and_trigger(extra_run_state["codex_max_subagents"] = context.codex_max_subagentsif context.codex_shared_prompt_cache:extra_run_state["codex_shared_prompt_cache"] = True+ if context.disable_skills:+ extra_run_state["disable_skills"] = Trueif context.disable_repo_hooks:extra_run_state["disable_repo_hooks"] = Trueif analytics_query_context is not None:diff --git a/products/tasks/backend/logic/services/store_skills.py b/products/tasks/backend/logic/services/store_skills.pyindex dff665b5b17e..6d828f72983e 100644--- a/products/tasks/backend/logic/services/store_skills.py+++ b/products/tasks/backend/logic/services/store_skills.py@@ -88,6 +88,7 @@ def refresh_store_skills_state(task_run: TaskRun, user: User, *, reason: str) ->store_skills = ([]if (task_run.state or {}).get("include_live_context") is False+ or (task_run.state or {}).get("disable_skills") is Trueelse resolve_store_skills(task_run.task.team, user, run_id=run_id))if store_skills is None:diff --git a/products/tasks/backend/logic/services/test_store_skills.py b/products/tasks/backend/logic/services/test_store_skills.pyindex 7fddebb5b3e4..ce4928bbf7a4 100644--- a/products/tasks/backend/logic/services/test_store_skills.py+++ b/products/tasks/backend/logic/services/test_store_skills.py@@ -16,10 +16,12 @@ class TestRefreshStoreSkillsState(BaseTest):(None, None, "unchanged"),(False, True, "empty"),(False, None, "empty"),+ (None, True, "empty", True),+ (None, None, "empty", True),])def test_refresh_respects_live_context_setting(- self, include_live_context: bool | None, flag_value: bool | None, expected: str+ self, include_live_context: bool | None, flag_value: bool | None, expected: str, disable_skills: bool = False) -> None:LLMSkill.objects.create(team=self.team,@@ -32,6 +34,7 @@ class TestRefreshStoreSkillsState(BaseTest):)task = Task.objects.create(team=self.team, title="Review evidence", created_by=self.user)state: dict[str, object] = {STORE_SKILLS_STATE_KEY: [{"name": "stale-live-skill"}]}+ state["disable_skills"] = disable_skillsif include_live_context is not None:state["include_live_context"] = include_live_contextrun = TaskRun.objects.create(task=task, team=self.team, state=state)diff --git a/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py b/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.pyindex f1d5a60d496d..f3d1d34ca785 100644--- a/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py+++ b/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py@@ -1073,7 +1073,7 @@ def get_task_processing_context(input: GetTaskProcessingContextInput) -> TaskPro# sandbox needs no extra request on its boot path, and best-effort: a store failure must not# stop the run, it only leaves the sandbox without store skills for this session.try:- if not include_live_context:+ if not include_live_context or state.get("disable_skills") is True:store_skills: list[dict[str, Any]] | None = []state[STORE_SKILLS_STATE_KEY] = []else:diff --git a/products/tasks/backend/temporal/process_task/activities/tests/test_get_task_processing_context.py b/products/tasks/backend/temporal/process_task/activities/tests/test_get_task_processing_context.pyindex 1e6ddaf5e499..0d63763b28e3 100644--- a/products/tasks/backend/temporal/process_task/activities/tests/test_get_task_processing_context.py+++ b/products/tasks/backend/temporal/process_task/activities/tests/test_get_task_processing_context.py@@ -799,17 +799,27 @@ class TestGetTaskProcessingContextActivity:@pytest.mark.django_db(transaction=True)@pytest.mark.parametrize(- "flag_value,include_live_context,expected_state",+ "flag_value,include_live_context,expected_state,disable_skills",[- (True, None, "resolved"),- (False, None, []),- (None, None, "untouched"), # a flag-service outage must not clear stubs a resumed sandbox still has- (True, False, []),- (None, False, []),+ (True, None, "resolved", False),+ (False, None, [], False),+ (None, None, "untouched", False), # a flag-service outage must not clear stubs a resumed sandbox still has+ (True, False, [], False),+ (None, False, [], False),+ (True, None, [], True),+ (None, None, [], True),],)def test_store_skills_state_follows_the_sandbox_flag(- self, activity_environment, test_task, user, mocker, flag_value, include_live_context, expected_state+ self,+ activity_environment,+ test_task,+ user,+ mocker,+ flag_value,+ include_live_context,+ expected_state,+ disable_skills,):LLMSkill.objects.create(team=test_task.team,@@ -821,7 +831,7 @@ class TestGetTaskProcessingContextActivity:created_by=user,)task_run = test_task.create_run(- extra_state={"include_live_context": include_live_context} if include_live_context is not None else {}+ extra_state={"include_live_context": include_live_context, "disable_skills": disable_skills})TaskRun.update_state_atomic(task_run.id, updates={STORE_SKILLS_STATE_KEY: [{"name": "from-last-session"}]})input_data = GetTaskProcessingContextInput(run_id=str(task_run.id))@@ -839,7 +849,7 @@ class TestGetTaskProcessingContextActivity:result = async_to_sync(activity_environment.run)(get_task_processing_context, input_data)assert result.context_layer_enabled is (include_live_context is not False)- if include_live_context is False:+ if include_live_context is False or disable_skills:assert result.state is not Noneassert result.state[STORE_SKILLS_STATE_KEY] == []for name in ("run_gateway_env_vars", "mcp_exec_skills_env_vars", "get_git_identity_env_vars"):diff --git a/products/tasks/backend/temporal/process_task/tests/test_utils.py b/products/tasks/backend/temporal/process_task/tests/test_utils.pyindex 227280ae2b19..0ae72baab0ee 100644--- a/products/tasks/backend/temporal/process_task/tests/test_utils.py+++ b/products/tasks/backend/temporal/process_task/tests/test_utils.py@@ -1907,23 +1907,26 @@ class TestMcpExecSkillsEnvVars(SimpleTestCase):("eval_flag_on", "eval", None, True, True),("desktop_keeps_bundled_skills_even_with_flag_on", None, None, True, False),("web_phai_flag_off", "posthog_ai", None, False, False),+ ("caller_disables_skills", None, "signal_report", False, True, True),("web_phai_task_without_interaction_origin_flag_on", None, "posthog_ai", True, True),("web_phai_task_without_interaction_origin_flag_off", None, "posthog_ai", False, False),])- def test_strips_bundled_skills_only_for_learn_capable_runs_with_the_flag_on(+ def test_strips_bundled_skills_for_caller_or_learn_capable_runs(self,_name: str,interaction_origin: str | None,origin_product: str | None,flag_enabled: bool,expect_stripped: bool,+ disable_skills: bool = False,) -> None:ctx = MagicMock(interaction_origin=interaction_origin,origin_product=origin_product,organization_id="org-1",distinct_id="user-1",+ state={"disable_skills": disable_skills},)with patch("products.tasks.backend.temporal.process_task.utils.is_mcp_exec_skills_enabled", return_value=flag_enabled@@ -1931,7 +1934,7 @@ class TestMcpExecSkillsEnvVars(SimpleTestCase):env = mcp_exec_skills_env_vars(ctx)assert env == ({"POSTHOG_CODE_DISABLE_BUNDLED_SKILLS": "1"} if expect_stripped else {})- if interaction_origin is None and origin_product is None:+ if disable_skills or (interaction_origin is None and origin_product is None):flag_check.assert_not_called()else:flag_check.assert_called_once_with("org-1", "user-1")diff --git a/products/tasks/backend/temporal/process_task/utils.py b/products/tasks/backend/temporal/process_task/utils.pyindex 6470dec813bc..9dcfa27476ad 100644--- a/products/tasks/backend/temporal/process_task/utils.py+++ b/products/tasks/backend/temporal/process_task/utils.py@@ -811,6 +811,8 @@ def mcp_exec_skills_env_vars(ctx: TaskProcessingContext) -> dict[str, str]:Desktop runs keep their bundled skills: the MCP server excludes the `posthog-code`consumer from `learn`, so stripping them there would leave the agent with no skills."""+ if (ctx.state or {}).get("disable_skills") is True:+ return {ENV_DISABLE_BUNDLED_SKILLS: "1"}if _resolve_mcp_consumer(ctx.interaction_origin, origin_product=ctx.origin_product) == "posthog-code":return {}if not is_mcp_exec_skills_enabled(ctx.organization_id, ctx.distinct_id):diff --git a/products/tasks/backend/tests/test_multi_turn_session.py b/products/tasks/backend/tests/test_multi_turn_session.pyindex 630efd3876d4..f65c4e81c971 100644--- a/products/tasks/backend/tests/test_multi_turn_session.py+++ b/products/tasks/backend/tests/test_multi_turn_session.py@@ -2007,11 +2007,11 @@ class TestCreateTaskAndTriggerForwardsContext:assert [written[entry["storage_path"]] for entry in manifest.values()] == [b"Review the PR.", "Ü".encode()]@pytest.mark.asyncio- async def test_codex_options_reach_the_state_the_agent_server_reads(self) -> None:+ async def test_caller_options_reach_the_state_the_agent_server_reads(self) -> None:# The agent server sees only allowlisted state keys, so a dropped key silently keeps the Codex default.team, user = await sync_to_async(self._setup_team_and_user)()context = CustomPromptSandboxContext(- team_id=team.id, user_id=user.id, codex_max_subagents=9, codex_shared_prompt_cache=True+ team_id=team.id, user_id=user.id, codex_max_subagents=9, codex_shared_prompt_cache=True, disable_skills=True)with patch("products.tasks.backend.temporal.client.execute_task_processing_workflow"):@@ -2021,6 +2021,7 @@ class TestCreateTaskAndTriggerForwardsContext:public_state = _public_task_run_state(persisted.state)assert public_state["codex_max_subagents"] == 9assert public_state["codex_shared_prompt_cache"] is True+ assert public_state["disable_skills"] is True@pytest.mark.asyncio@pytest.mark.parametrize(("output_schema", "expected_flag"), [({"type": "object"}, True), (None, None)])diff --git a/products/tasks/backend/tests/test_repo_selection_prompt.py b/products/tasks/backend/tests/test_repo_selection_prompt.pyindex e0cf35cd62d8..43d0941f814c 100644--- a/products/tasks/backend/tests/test_repo_selection_prompt.py+++ b/products/tasks/backend/tests/test_repo_selection_prompt.py@@ -120,6 +120,7 @@ def test_select_repository_renders_team_rules_and_visibility_into_prompt() -> Nocandidate_repos=["acme/a", "acme/b"],)+ assert start.call_args.kwargs["context"].disable_skills is Trueassert selected.repository == "acme/b"prompt = start.call_args.kwargs["prompt"]assert "Team routing rules" in prompt