Skip to content

: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.

chore(tasks): remove the loop context internal scope (#114449)

Charles Vien7ec43bada236
diff --git a/posthog/scopes.py b/posthog/scopes.py
index f6fc86af6699..41b5763b93bf 100644
--- a/posthog/scopes.py
+++ b/posthog/scopes.py
@@ -93,7 +93,6 @@ APIScopeObject = Literal[
"llm_skill",
"logs",
"loop", # Endpoints are gone; kept advertised until desktop OAuth clients stop requesting it.
- "loop_context_internal",
"marketing_analytics",
"mcp_builtin_agent",
"mcp_analytics",
@@ -194,8 +193,6 @@ INTERNAL_API_SCOPE_OBJECTS: frozenset[APIScopeObject] = frozenset(
# it on the internal products that share the PostHog Desktop OAuth app so a user's
# own credential can't reach them — see services/llm-gateway products/config.py.
"internal_run",
- # Grants context maintenance tools only to Loop runs configured with update_context.
- "loop_context_internal",
# Marks a sandbox OAuth token as belonging to a trusted built-in agent.
# MCP Store uses it to deny the human/member control plane and force the
# agent through its own explicit gateway grants.
diff --git a/posthog/temporal/oauth.py b/posthog/temporal/oauth.py
index 6bbd925b6dc5..3c35263c62d0 100644
--- a/posthog/temporal/oauth.py
+++ b/posthog/temporal/oauth.py
@@ -166,7 +166,6 @@ SCOUT_REPORT_SCOPES: list[str] = [
"signal_scout_report:write",
]
-LOOP_CONTEXT_INTERNAL_SCOPE = "loop_context_internal:write"
CONTEXT_LAYER_INTERNAL_SCOPE = "context_layer_internal:write"
diff --git a/products/context_layer/backend/presentation/views.py b/products/context_layer/backend/presentation/views.py
index bbdc44c5c3b7..61f0841f011f 100644
--- a/products/context_layer/backend/presentation/views.py
+++ b/products/context_layer/backend/presentation/views.py
@@ -15,7 +15,7 @@ from posthog.models.user import User
from posthog.oauth_provenance import INTERNAL_RUN_SCOPE, get_oauth_access_token
from posthog.permissions import APIScopePermission, PostHogFeatureFlagPermission
from posthog.redis import get_client
-from posthog.temporal.oauth import CONTEXT_LAYER_INTERNAL_SCOPE, LOOP_CONTEXT_INTERNAL_SCOPE
+from posthog.temporal.oauth import CONTEXT_LAYER_INTERNAL_SCOPE
from products.context_layer.backend.facade import api as facade
from products.context_layer.backend.presentation.serializers import (
@@ -42,11 +42,9 @@ from products.tasks.backend.facade import api as tasks_facade
RUN_COMMITS_PER_DAY_CAP = 20
-def _context_actor_type(request: Request) -> Literal["user_or_api", "task_agent", "loop_agent"]:
+def _context_actor_type(request: Request) -> Literal["user_or_api", "task_agent"]:
access_token = get_oauth_access_token(request)
token_scopes = set((getattr(access_token, "scope", "") or "").split())
- if LOOP_CONTEXT_INTERNAL_SCOPE in token_scopes:
- return "loop_agent"
if INTERNAL_RUN_SCOPE in token_scopes:
return "task_agent"
return "user_or_api"
@@ -185,29 +183,21 @@ def _assert_run_write_in_scope(organization_id, team_id, request: Request, path:
"""
access_token = get_oauth_access_token(request)
token_scopes = set((getattr(access_token, "scope", "") or "").split())
- is_loop_run = LOOP_CONTEXT_INTERNAL_SCOPE in token_scopes
- is_ordinary_run = INTERNAL_RUN_SCOPE in token_scopes
- if not is_loop_run and not is_ordinary_run:
+ if INTERNAL_RUN_SCOPE not in token_scopes:
return
denied = PermissionDenied(
- "This loop can update only its configured channel's context page."
- if is_loop_run
- else "This task can update only its own channel's context page. "
+ "This task can update only its own channel's context page. "
"Use task-context-wiki-page-propose for shared content, then ask the user to review it in Context > Suggested edits."
)
sandbox_task_id = getattr(access_token, "sandbox_task_id", None)
if sandbox_task_id is None or team_id is None or not facade.is_run_content_path(path):
raise denied
- configured_channel_id = (
- tasks_facade.loop_context_channel_id_for_task(sandbox_task_id)
- if is_loop_run
- else tasks_facade.task_channel_id(sandbox_task_id, team_id)
- )
- if configured_channel_id is None:
+ channel_id = tasks_facade.task_channel_id(sandbox_task_id, team_id)
+ if channel_id is None:
raise denied
- configured_channel_id = str(configured_channel_id)
+ configured_channel_id = str(channel_id)
# Both sides resolve inside this organization's own wiki index, so a run
# cannot reach another organization's pages even by naming its channel.
@@ -238,7 +228,7 @@ def _assert_run_may_create_channel_page(
instructions forever. Everything is pinned: the channel must have no page,
the path must be exactly the one resolution proposed, nothing may already
exist there, and the content's frontmatter must claim the configured
- channel — so the loop cannot plant a page that resolution would hand to a
+ channel — so the run cannot plant a page that resolution would hand to a
different channel.
"""
if facade.resolve_channel_page(organization_id, channel_id) is not None:
@@ -316,8 +306,7 @@ def _write_page(organization_id, request: Request, *, team_id=None) -> Response:
def _assert_run_commit_cap(request: Request) -> None:
"""Cap how many landings (bundles or page writes) one sandbox run gets per day.
- Loops have their own daily fire caps, but an ordinary task run landing
- wiki changes has nothing but the writer lock pacing it. Keyed on the run
+ A task run landing wiki changes has nothing but the writer lock pacing it. Keyed on the run
provenance the token carries; human and PAT callers have none and stay
uncapped.
"""
@@ -336,10 +325,6 @@ def _assert_run_commit_cap(request: Request) -> None:
def _land_commits(organization_id, request: Request) -> Response: # noqa: ANN001
access_token = get_oauth_access_token(request)
token_scopes = set((getattr(access_token, "scope", "") or "").split())
- if LOOP_CONTEXT_INTERNAL_SCOPE in token_scopes:
- # Bundles bypass the page binding _assert_loop_write_in_scope enforces,
- # so a loop run must land its edits through the page endpoint instead.
- raise PermissionDenied("This loop can update only its context page, not land commit bundles.")
is_task_run = INTERNAL_RUN_SCOPE in token_scopes
maintenance_run = None
if is_task_run:
@@ -486,7 +471,7 @@ class ContextLayerViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
200: ContextLayerStatusSerializer,
400: LintErrorSerializer,
403: OpenApiResponse(
- description="The wiki is unavailable, or a loop run targeted a page outside its own context."
+ description="The wiki is unavailable, or a run targeted a page outside its own context."
),
409: HeadConflictSerializer,
},
@@ -514,7 +499,7 @@ class ContextLayerViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
user_id = cast(int, user.id)
token = get_oauth_access_token(request)
scopes = set((getattr(token, "scope", "") or "").split())
- if INTERNAL_RUN_SCOPE in scopes or LOOP_CONTEXT_INTERNAL_SCOPE in scopes:
+ if INTERNAL_RUN_SCOPE in scopes:
raise PermissionDenied(
"A task cannot approve a wiki edit. Review and apply it from Context > Suggested edits."
)
@@ -620,8 +605,8 @@ class ContextLayerAgentViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
read_actions = ["page", "channel_page"]
write_actions = ["update_page", "commits", "propose_page"]
- # Each task scope must come with server-minted run provenance. Page actions
- # accept ordinary and loop runs; the write path binds each to its own target.
+ # Each task scope must come with server-minted run provenance. The write path
+ # binds each run to its own channel.
_RUN_TASK_SCOPES = {
"commits": "task:write",
"page": "task:read",
@@ -646,8 +631,6 @@ class ContextLayerAgentViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
if task_scope is not None:
access_token = get_oauth_access_token(request)
token_scopes = set((getattr(access_token, "scope", "") or "").split())
- if self.action != "commits" and LOOP_CONTEXT_INTERNAL_SCOPE in token_scopes:
- return [task_scope, LOOP_CONTEXT_INTERNAL_SCOPE]
if INTERNAL_RUN_SCOPE in token_scopes:
required = [task_scope, INTERNAL_RUN_SCOPE]
if self.action in self.write_actions:
@@ -678,7 +661,7 @@ class ContextLayerAgentViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
# nosemgrep: api-path-underscore -- shipped public API path, a rename breaks clients
@action(methods=["GET"], detail=False, url_path=r"channel-pages/(?P<channel_id>[^/.]+)")
def channel_page(self, request: Request, channel_id: str, **kwargs) -> Response:
- # Unlike the organization route, a miss proposes a create path: a loop
+ # Unlike the organization route, a miss proposes a create path: a run
# maintaining a post-enablement channel needs somewhere to publish.
return _read_channel_page(self.organization.id, channel_id, propose_on_miss=True)
@@ -708,7 +691,6 @@ class ContextLayerAgentViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
task_id = getattr(token, "sandbox_task_id", None)
if (
INTERNAL_RUN_SCOPE not in scopes
- or LOOP_CONTEXT_INTERNAL_SCOPE in scopes
or task_id is None
or tasks_facade.task_channel_id(task_id, self.team_id) is None
):
diff --git a/products/context_layer/backend/test/test_api.py b/products/context_layer/backend/test/test_api.py
index 0450ba7f8b72..f7d19e4e0c41 100644
--- a/products/context_layer/backend/test/test_api.py
+++ b/products/context_layer/backend/test/test_api.py
@@ -438,28 +438,15 @@ class TestContextLayerAPI(APIBaseTest):
page = self.client.get(f"{self.base_url}/pages/", {"path": "areas/from-agent.md"}).json()
assert page["content"] == _page("From an agent")
- def _loop_run_token(self, channel_id) -> str: # noqa: ANN001
- """A token shaped like the one a context-maintaining loop run carries."""
+ def _channel_task_token(self, channel_id) -> str: # noqa: ANN001
task = apps.get_model("tasks", "Task").objects.create(
team=self.team,
created_by=self.user,
title="Keep the space context current",
- origin_product="loop",
- )
- apps.get_model("tasks", "TaskRun").objects.create(
- task=task,
- team=self.team,
- state={
- "config_snapshot": {
- "context_target": {
- "channel_id": str(channel_id),
- "outputs": {"update_context": True},
- }
- }
- },
+ channel_id=channel_id,
)
return self._bearer(
- "task:read task:write loop_context_internal:write",
+ "task:read task:write internal_run:read context_layer_internal:write",
scoped_teams=[self.team.id],
sandbox_task_id=task.id,
)
@@ -498,7 +485,7 @@ class TestContextLayerAPI(APIBaseTest):
# Reads stay open across the wiki: it is organization-wide reference
# material every agent is meant to draw on.
self._enable()
- token = self._bearer("task:read task:write loop_context_internal:write", scoped_teams=[self.team.id])
+ token = self._bearer("task:read internal_run:read", scoped_teams=[self.team.id])
self.client.logout()
page = self.client.get(
f"{self.agent_url}/pages/",
@@ -507,41 +494,6 @@ class TestContextLayerAPI(APIBaseTest):
)
assert page.status_code == 200, page.content
- def test_loop_token_writes_only_the_page_configured_for_its_run(self, _flag) -> None:
- with team_scope(self.team.id):
- channel = tasks_facade.resolve_channel(self.team.id, self.user.id, name="growth", star=False)
- assert channel is not None
- tasks_facade.publish_channel_instructions(
- channel.id, self.team.id, self.user.id, content="Focus on activation.", base_version=0
- )
- head = self._enable()
- token = self._loop_run_token(channel.id)
- self.client.logout()
-
- in_scope = self.client.put(
- f"{self.agent_url}/pages/",
- {
- "path": f"projects/{self.team.id}/spaces/growth.md",
- # A real loop reads the page and edits in place, so the frontmatter
- # that identifies the channel survives the write.
- "content": f"---\nteam_id: {self.team.id}\nchannel_id: {channel.id}\nsummary: Growth channel context.\nstatus: active\n---\n\n# Growth (project {self.team.id})\n\nRefreshed by the loop.\n",
- "base_head": head,
- },
- format="json",
- HTTP_AUTHORIZATION=f"Bearer {token}",
- )
- assert in_scope.status_code == 200, in_scope.content
-
- # AGENTS.md is what every agent bootstraps from, so a loop reaching it
- # would rewrite the whole organization's starting instructions.
- out_of_scope = self.client.put(
- f"{self.agent_url}/pages/",
- {"path": "AGENTS.md", "content": "# Owned\n", "base_head": in_scope.json()["head_sha"]},
- format="json",
- HTTP_AUTHORIZATION=f"Bearer {token}",
- )
- assert out_of_scope.status_code == 403, out_of_scope.content
-
def test_agent_channel_page_proposes_a_create_path_when_channel_has_no_page(self, _flag) -> None:
self._enable()
with team_scope(self.team.id):
@@ -551,7 +503,7 @@ class TestContextLayerAPI(APIBaseTest):
# The org route keeps its 404 — the desktop hook relies on it.
assert self.client.get(f"{self.base_url}/channel-pages/{channel.id}/").status_code == 404
- token = self._loop_run_token(channel.id)
+ token = self._channel_task_token(channel.id)
self.client.logout()
proposed = self.client.get(
f"{self.agent_url}/channel-pages/{channel.id}/",
@@ -682,14 +634,12 @@ class TestContextLayerAPI(APIBaseTest):
apply_url = f"{self.base_url}/proposals/{proposal['id']}/apply/"
for scope in (
"organization:write internal_run:read context_layer_internal:write",
- "organization:write loop_context_internal:write",
"organization:read",
):
denied = self.client.post(apply_url, HTTP_AUTHORIZATION=f"Bearer {self._bearer(scope)}")
assert denied.status_code == 403, denied.content
for restricted_token in (
- self._loop_run_token(channel.id),
self._bearer("task:write internal_run:read", scoped_teams=[self.team.id], sandbox_task_id=task.id),
):
denied = self.client.post(
@@ -747,7 +697,6 @@ class TestContextLayerAPI(APIBaseTest):
assert stale.json()["current_head"] == applied.json()["head_sha"]
for restricted_token, restricted_content in (
- (self._loop_run_token(channel.id), content),
(
self._bearer(
"task:read task:write internal_run:read",
@@ -824,45 +773,20 @@ class TestContextLayerAPI(APIBaseTest):
)
assert updated.status_code == 403, updated.content
- def test_loop_token_creates_its_channels_missing_page_at_the_proposed_path(self, _flag) -> None:
- self._enable()
- with team_scope(self.team.id):
- channel = tasks_facade.resolve_channel(self.team.id, self.user.id, name="growth", star=False)
- assert channel is not None
- token = self._loop_run_token(channel.id)
- self.client.logout()
-
- created = self.client.put(
- f"{self.agent_url}/pages/",
- {
- "path": f"projects/{self.team.id}/spaces/growth.md",
- "content": f"---\nteam_id: {self.team.id}\nchannel_id: {channel.id}\nsummary: Growth channel context.\nstatus: active\n---\n\n# Growth (project {self.team.id})\n\nWritten by the loop.\n",
- },
- format="json",
- HTTP_AUTHORIZATION=f"Bearer {token}",
- )
- assert created.status_code == 200, created.content
-
- resolved = self.client.get(
- f"{self.agent_url}/channel-pages/{channel.id}/",
- HTTP_AUTHORIZATION=f"Bearer {token}",
- )
- assert resolved.json() == {"path": f"projects/{self.team.id}/spaces/growth.md", "exists": True}
-
@parameterized.expand(
[
("mismatched_frontmatter_channel", "projects/{team_id}/spaces/growth.md", False),
("non_proposed_path", "projects/{team_id}/spaces/somewhere-else.md", True),
]
)
- def test_loop_token_cannot_create_a_channel_page_off_its_proposal(
+ def test_task_token_cannot_create_a_channel_page_off_its_proposal(
self, _flag, _name, path, own_frontmatter
) -> None:
self._enable()
with team_scope(self.team.id):
channel = tasks_facade.resolve_channel(self.team.id, self.user.id, name="growth", star=False)
assert channel is not None
- token = self._loop_run_token(channel.id)
+ token = self._channel_task_token(channel.id)
self.client.logout()
frontmatter_channel_id = channel.id if own_frontmatter else uuid4()
@@ -940,23 +864,6 @@ class TestContextLayerAPI(APIBaseTest):
assert response.status_code == 403, response.content
assert store.get_config(self.organization.id).head_sha == head
- def test_loop_token_cannot_land_commit_bundles(self, _flag) -> None:
- # Bundles bypass the loop's page binding, so the bundle route must refuse them.
- self._enable()
- with team_scope(self.team.id):
- channel = tasks_facade.resolve_channel(self.team.id, self.user.id, name="growth", star=False)
- assert channel is not None
- bundle_bytes = self._bundle_with_edit("areas/from-agent.md", _page("From an agent"))
- token = self._loop_run_token(channel.id)
- self.client.logout()
- response = self.client.post(
- f"{self.agent_url}/commits/",
- {"bundle": SimpleUploadedFile("out.bundle", bundle_bytes)},
- format="multipart",
- HTTP_AUTHORIZATION=f"Bearer {token}",
- )
- assert response.status_code == 403, response.content
-
def test_run_page_writes_share_the_daily_landing_cap(self, _flag) -> None:
with team_scope(self.team.id):
channel = tasks_facade.resolve_channel(self.team.id, self.user.id, name="growth", star=False)
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.py
index e4c52ba67721..30724d6accc0 100644
--- a/products/tasks/backend/facade/api.py
+++ b/products/tasks/backend/facade/api.py
@@ -10446,41 +10446,9 @@ def list_channel_instruction_versions(
return [_instructions_to_dto(row) for row in versions]
-def task_can_publish_channel_instructions(task_id: str | UUID, team_id: int, channel_id: str | UUID) -> bool:
- task = Task.objects.filter(id=task_id, team_id=team_id).only("origin_product").first()
- if task is None:
- return False
- if task.origin_product != Task.OriginProduct.LOOP:
- return True
-
- run_state = (
- TaskRun.objects.filter(task_id=task.id, team_id=team_id)
- .order_by("-created_at")
- .values_list("state", flat=True)
- .first()
- )
- context_target = ((run_state or {}).get("config_snapshot") or {}).get("context_target") or {}
- outputs = context_target.get("outputs") or {}
- return bool(outputs.get("update_context")) and str(context_target.get("channel_id")) == str(channel_id)
-
-
-def loop_context_channel_id_for_task(task_id: str | UUID) -> str | None:
- """The channel a loop run was configured to keep current, or None.
-
- Scoped by task rather than by team, because the caller's authority here is a
- run token minted for exactly this task. Returns None for anything that is
- not a loop run configured to update its context, so callers fail closed.
- """
- task = Task.objects.filter(id=task_id).only("id", "origin_product").first()
- if task is None or task.origin_product != Task.OriginProduct.LOOP:
- return None
-
- run_state = TaskRun.objects.filter(task_id=task.id).order_by("-created_at").values_list("state", flat=True).first()
- context_target = ((run_state or {}).get("config_snapshot") or {}).get("context_target") or {}
- if not (context_target.get("outputs") or {}).get("update_context"):
- return None
- channel_id = context_target.get("channel_id")
- return str(channel_id) if channel_id else None
+def task_can_publish_channel_instructions(task_id: str | UUID, team_id: int) -> bool:
+ # Legacy loop runs could only publish to the channel their loop targeted, and that config is gone.
+ return Task.objects.filter(id=task_id, team_id=team_id).exclude(origin_product=Task.OriginProduct.LOOP).exists()
def capture_context_wiki_changed(
@@ -10489,7 +10457,7 @@ def capture_context_wiki_changed(
channel_id: str | UUID,
user_id: int | None,
*,
- actor_type: Literal["user_or_api", "task_agent", "loop_agent"],
+ actor_type: Literal["user_or_api", "task_agent"],
is_first_version: bool,
content_bytes: int,
base_version_provided: bool,
diff --git a/products/tasks/backend/facade/tasks.py b/products/tasks/backend/facade/tasks.py
index 5235e0527d24..f04e68060243 100644
--- a/products/tasks/backend/facade/tasks.py
+++ b/products/tasks/backend/facade/tasks.py
@@ -1,7 +1,7 @@
"""
Celery-task wiring for the tasks product.
-Re-exports the beat-scheduled sweeps that core's scheduler registers.
+Re-exports the beat-scheduled tasks that core's scheduler registers.
"""
from products.tasks.backend.task_auto_archive import sweep_inactive_tasks_task
diff --git a/products/tasks/backend/presentation/views/channels_api.py b/products/tasks/backend/presentation/views/channels_api.py
index 4993a3948c91..04685b759b7d 100644
--- a/products/tasks/backend/presentation/views/channels_api.py
+++ b/products/tasks/backend/presentation/views/channels_api.py
@@ -380,9 +380,9 @@ class ChannelViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
def publish_instructions(self, request, pk=None, **kwargs):
sandbox_task_id = self._sandbox_task_id(request)
if sandbox_task_id is not None and not tasks_facade.task_can_publish_channel_instructions(
- sandbox_task_id, self.team_id, pk
+ sandbox_task_id, self.team_id
):
- raise PermissionDenied("This loop can update only the CONTEXT.md configured for this run.")
+ raise PermissionDenied("This run can't update CONTEXT.md in this project.")
serializer = ChannelInstructionsWriteSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
@@ -393,7 +393,7 @@ class ChannelViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
self._user_id(),
content=serializer.validated_data["content"],
base_version=serializer.validated_data.get("base_version"),
- # The facade never sees the request, so the loop-vs-person split is set here.
+ # The facade never sees the request, so the agent-vs-person split is set here.
source="agent" if sandbox_task_id is not None else "user",
)
except tasks_facade.ChannelInstructionsVersionConflictError as err:
diff --git a/products/tasks/backend/repository_config_analytics.py b/products/tasks/backend/repository_config_analytics.py
index 185725cd8435..a6a7e429f142 100644
--- a/products/tasks/backend/repository_config_analytics.py
+++ b/products/tasks/backend/repository_config_analytics.py
@@ -128,8 +128,7 @@ def capture_space_context_changed(
) -> None:
"""Record a Space's CONTEXT.md being published or cleared.
- `source` separates people from loops: a loop configured with `update_context`
- republishes on every fire, which outnumbers human edits by orders of magnitude.
+ `source` separates people from agent runs, which republish far more often than people edit.
Carries byte counts only — CONTEXT.md is customer-authored free text.
"""
try:
diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.py
index 7fe8789032ef..31ae7d8c5706 100644
--- a/products/tasks/backend/tests/test_api.py
+++ b/products/tasks/backend/tests/test_api.py
@@ -7536,7 +7536,6 @@ class TestTaskRunAPI(BaseTaskAPITest):
"rtk_effective": True,
"benjamin_effective": True,
"usage_metrics_recorded": True,
- "loop_terminal_bookkeeping_complete": True,
"analysis_target_repository": "posthog/posthog",
"analysis_target_custom_image_id": "img-real",
"analysis_target_custom_image_name": "real-image",
@@ -7632,7 +7631,6 @@ class TestTaskRunAPI(BaseTaskAPITest):
"rtk_effective": False,
"benjamin_effective": False,
"usage_metrics_recorded": False,
- "loop_terminal_bookkeeping_complete": False,
# server-stamped analysis attribution; a forged value would
# misattribute the captured activity event to another repository / image
"analysis_target_repository": "attacker/attacker",
@@ -7707,7 +7705,6 @@ class TestTaskRunAPI(BaseTaskAPITest):
assert run.state["rtk_effective"] is True
assert run.state["benjamin_effective"] is True
assert run.state["usage_metrics_recorded"] is True
- assert run.state["loop_terminal_bookkeeping_complete"] is True
assert run.state["analysis_target_repository"] == "posthog/posthog" # cannot forge attribution
assert run.state["analysis_target_custom_image_id"] == "img-real"
assert run.state["analysis_target_custom_image_name"] == "real-image"
@@ -7776,7 +7773,6 @@ class TestTaskRunAPI(BaseTaskAPITest):
"rtk_effective",
"benjamin_effective",
"usage_metrics_recorded",
- "loop_terminal_bookkeeping_complete",
"analysis_target_repository",
"analysis_target_custom_image_id",
"analysis_target_custom_image_name",
@@ -7833,7 +7829,6 @@ class TestTaskRunAPI(BaseTaskAPITest):
assert run.state["rtk_effective"] is True # protected key survives removal
assert run.state["benjamin_effective"] is True # protected key survives removal
assert run.state["usage_metrics_recorded"] is True # protected key survives removal
- assert run.state["loop_terminal_bookkeeping_complete"] is True
assert run.state["analysis_target_repository"] == "posthog/posthog" # protected key survives removal
assert run.state["analysis_target_custom_image_id"] == "img-real"
assert run.state["analysis_target_custom_image_name"] == "real-image"
diff --git a/products/tasks/backend/tests/test_channel_extras.py b/products/tasks/backend/tests/test_channel_extras.py
index 6a74a7c8bd0b..3019853c6918 100644
--- a/products/tasks/backend/tests/test_channel_extras.py
+++ b/products/tasks/backend/tests/test_channel_extras.py
@@ -75,7 +75,7 @@ class TestChannelInstructions(ChannelExtrasBaseTest):
client.credentials(HTTP_AUTHORIZATION=f"Bearer {access_token.token}")
return client
- def test_loop_sandbox_can_publish_only_to_its_configured_context(self):
+ def test_legacy_loop_sandbox_cannot_publish_context(self):
with team_scope(self.team.id):
other_channel = Channel.objects.create(team=self.team, name="other", created_by=self.user)
task = Task.objects.create(
@@ -103,12 +103,12 @@ class TestChannelInstructions(ChannelExtrasBaseTest):
{"content": "wrong target", "base_version": 0},
format="json",
)
- allowed = client.put(
+ configured = client.put(
f"{self.base}/instructions/", {"content": "configured target", "base_version": 0}, format="json"
)
assert denied.status_code == status.HTTP_403_FORBIDDEN
- assert allowed.status_code == status.HTTP_200_OK
+ assert configured.status_code == status.HTTP_403_FORBIDDEN
def test_unpublished_reads_as_blank_version_zero(self):
response = self.client.get(f"{self.base}/instructions/")
diff --git a/products/tasks/docs/INSTRUMENTATION.md b/products/tasks/docs/INSTRUMENTATION.md
index 82d6eb2b7b4d..44a789c49a17 100644
--- a/products/tasks/docs/INSTRUMENTATION.md
+++ b/products/tasks/docs/INSTRUMENTATION.md
@@ -134,24 +134,23 @@ dialog fires both a task-level and a space-level change from a single click. Two
Fires when a Space's CONTEXT.md is published or cleared. Carries byte counts only; CONTEXT.md is
customer-authored free text.
-| Property | Type | Description |
-| ------------------------ | ------ | ------------------------------------------------------------------- |
-| `action` | `str` | `published` or `cleared` |
-| `source` | `str` | `user` or `agent` |
-| `storage` | `str` | `legacy_instructions` or `context_wiki` |
-| `actor_type` | `str?` | `user_or_api`, `task_agent`, or `loop_agent` for context-wiki edits |
-| `team_id` | `int` | |
-| `channel_id` | `str` | |
-| `previous_version` | `int?` | 0 when there was none; null for context-wiki commits |
-| `new_version` | `int?` | Null on `cleared` |
-| `is_first_version` | `bool` | |
-| `content_bytes` | `int` | Length only, never content |
-| `previous_content_bytes` | `int?` | Gives edit magnitude |
-| `base_version_provided` | `bool` | Whether the client used the optimistic-concurrency guard |
-| `versions_deleted` | `int?` | `cleared` only |
-
-`source` is load-bearing: a loop configured with `update_context` republishes on every fire, so
-an hourly loop produces hundreds of rows a month for one Space. Filter to `source=user` for any
+| Property | Type | Description |
+| ------------------------ | ------ | -------------------------------------------------------- |
+| `action` | `str` | `published` or `cleared` |
+| `source` | `str` | `user` or `agent` |
+| `storage` | `str` | `legacy_instructions` or `context_wiki` |
+| `actor_type` | `str?` | `user_or_api` or `task_agent` for context-wiki edits |
+| `team_id` | `int` | |
+| `channel_id` | `str` | |
+| `previous_version` | `int?` | 0 when there was none; null for context-wiki commits |
+| `new_version` | `int?` | Null on `cleared` |
+| `is_first_version` | `bool` | |
+| `content_bytes` | `int` | Length only, never content |
+| `previous_content_bytes` | `int?` | Gives edit magnitude |
+| `base_version_provided` | `bool` | Whether the client used the optimistic-concurrency guard |
+| `versions_deleted` | `int?` | `cleared` only |
+
+`source` is load-bearing: agent runs republish often, so filter to `source=user` for any
human-edit question.
## TaskRun Model Events
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_end_to_end.py b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_end_to_end.py
index 40f446d655a2..18d8bfef67da 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_end_to_end.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_end_to_end.py
@@ -3481,7 +3481,13 @@ async def test_postgres_deleting_schemas_with_pre_synced_data(team, postgres_con
@pytest.mark.django_db(transaction=True)
@pytest.mark.asyncio
-async def test_query_folder_slots_rotate(team, stripe_balance_transaction, mock_stripe_client, minio_client):
+async def test_query_folder_slots_rotate(
+ team, stripe_balance_transaction, mock_stripe_client, minio_client, monkeypatch
+):
+ monkeypatch.setattr(
+ "products.warehouse_sources.backend.temporal.data_imports.workflow_activities.create_job_model._start_to_close_deadline_passed",
+ lambda: False,
+ )
datetime_1 = datetime.now()
with time_machine.travel(datetime_1, tick=False):
workflow_id, inputs = await _run(
diff --git a/services/mcp/src/lib/api.ts b/services/mcp/src/lib/api.ts
index 166a0a2c4fcd..0670f18d0de6 100644
--- a/services/mcp/src/lib/api.ts
+++ b/services/mcp/src/lib/api.ts
@@ -1,7 +1,6 @@
const SERVER_MINT_ONLY_SCOPE_OBJECTS = new Set([
'context_layer_internal',
'internal_run',
- 'loop_context_internal',
'mcp_builtin_agent',
'signal_scout_internal',
'signal_scout_report',
diff --git a/services/mcp/src/lib/scope-preset.ts b/services/mcp/src/lib/scope-preset.ts
index 0d9247f3b550..951d1932faf7 100644
--- a/services/mcp/src/lib/scope-preset.ts
+++ b/services/mcp/src/lib/scope-preset.ts
@@ -33,7 +33,6 @@ const SERVER_MINTED_MARKER_SCOPE = 'internal_run:read'
const INTERNAL_WRITE_SCOPE_OBJECTS = new Set([
'context_layer_internal',
'internal_run',
- 'loop_context_internal',
'mcp_builtin_agent',
'signal_scout_internal',
'signal_scout_report',
diff --git a/services/mcp/tests/unit/tool-filtering.test.ts b/services/mcp/tests/unit/tool-filtering.test.ts
index 75a3b0c7d497..b685b98f6c6a 100644
--- a/services/mcp/tests/unit/tool-filtering.test.ts
+++ b/services/mcp/tests/unit/tool-filtering.test.ts
@@ -578,7 +578,6 @@ describe('OAUTH_SCOPES_SUPPORTED completeness', () => {
'context_layer_internal:write',
'hog_flow_proposal:write',
'internal_run:read',
- 'loop_context_internal:write',
'signal_scout_internal:read',
'signal_scout_internal:write',
'signal_scout_report:read',
@@ -617,8 +616,8 @@ describe('OAUTH_SCOPES_SUPPORTED completeness', () => {
describe('server-minted scope matching', () => {
it('requires literal internal scopes instead of accepting a wildcard', () => {
- expect(hasScope(['*'], 'loop_context_internal:write')).toBe(false)
- expect(hasScope(['loop_context_internal:write'], 'loop_context_internal:write')).toBe(true)
+ expect(hasScope(['*'], 'context_layer_internal:write')).toBe(false)
+ expect(hasScope(['context_layer_internal:write'], 'context_layer_internal:write')).toBe(true)
})
// The scratchpad write scope was split out of `signal_scout_internal`, which is on the
@@ -637,7 +636,6 @@ describe('server-minted scope matching', () => {
it.each([
'context_layer_internal',
'internal_run',
- 'loop_context_internal',
'mcp_builtin_agent',
'signal_scout_internal',
'signal_scout_report',