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.

fix(tasks): route hogland agent through the LLM gateway, not direct Bedrock (#95658)

Tom Owersaea48fc49beb
diff --git a/products/tasks/backend/logic/services/agent_server_launcher.py b/products/tasks/backend/logic/services/agent_server_launcher.py
index fcf0f7485c08..cd29e5de4821 100644
--- a/products/tasks/backend/logic/services/agent_server_launcher.py
+++ b/products/tasks/backend/logic/services/agent_server_launcher.py
@@ -169,6 +169,7 @@ class AgentServerLaunchMixin(SandboxBase):
rtk_enabled=rtk_enabled,
benjamin_enabled=benjamin_enabled,
peer_messaging=peer_messaging,
+ unset_bedrock=self.disable_direct_bedrock,
)
create_pr_flag = f" --createPr {shlex.quote('true' if create_pr else 'false')}"
# Only append when opted in: agent-server builds without the option reject unknown
diff --git a/products/tasks/backend/logic/services/hogland_sandbox.py b/products/tasks/backend/logic/services/hogland_sandbox.py
index 27fb9db011a1..402a9eac46e6 100644
--- a/products/tasks/backend/logic/services/hogland_sandbox.py
+++ b/products/tasks/backend/logic/services/hogland_sandbox.py
@@ -191,6 +191,13 @@ class HoglandSandbox(AgentServerLaunchMixin):
_box: Hogbox
_sandbox_url: str | None
+ # hogland boxes boot with the `bedrock` feature, which puts the Claude CLI in
+ # direct-Bedrock mode. Unset those vars at agent launch so the CLI routes
+ # through the PostHog LLM gateway instead — avoids AWS Bedrock Marketplace
+ # model-access and SigV4 header-signing issues, and keeps gateway-based AI
+ # observability attribution (matching the Modal backend).
+ disable_direct_bedrock = True
+
def __init__(self, box: Hogbox, config: SandboxConfig, sandbox_url: str | None = None):
self.id = box.id
self.config = config
diff --git a/products/tasks/backend/logic/services/sandbox.py b/products/tasks/backend/logic/services/sandbox.py
index 6759d593712c..78e9c9db574d 100644
--- a/products/tasks/backend/logic/services/sandbox.py
+++ b/products/tasks/backend/logic/services/sandbox.py
@@ -282,6 +282,7 @@ def build_agent_runtime_env_prefix(
rtk_enabled: bool = True,
benjamin_enabled: bool = False,
peer_messaging: bool = False,
+ unset_bedrock: bool = False,
) -> str:
env_vars = {
"POSTHOG_CODE_INTERACTION_ORIGIN": interaction_origin,
@@ -311,7 +312,15 @@ def build_agent_runtime_env_prefix(
assignments = " ".join(
f"{name}={shlex.quote(value)}" for name, value in env_vars.items() if value is not None and value != ""
)
- return f"env {assignments} " if assignments else ""
+ # Route the agent through the PostHog LLM gateway instead of direct Bedrock:
+ # unset the box profile's Bedrock vars so the Claude CLI falls back to the
+ # gateway (ANTHROPIC_BASE_URL/ANTHROPIC_AUTH_TOKEN). Direct Bedrock from the
+ # box needs AWS Marketplace model access plus SigV4-signing the
+ # x-posthog-property-* headers (which AWS strips), so the gateway path avoids
+ # both and matches the Modal backend.
+ unset_flags = "-u CLAUDE_CODE_USE_BEDROCK -u AWS_CONTAINER_CREDENTIALS_FULL_URI" if unset_bedrock else ""
+ body = f"{unset_flags} {assignments}".strip()
+ return f"env {body} " if body else ""
class SandboxBase(ABC):
@@ -319,6 +328,11 @@ class SandboxBase(ABC):
config: SandboxConfig
supports_creation_cancellation = False
creation_timeout_seconds = 300
+ # When True, the agent runtime is launched with the box's Bedrock env unset,
+ # so the Claude CLI routes through the PostHog LLM gateway instead of direct
+ # Bedrock. hogland opts in (see HoglandSandbox); Modal/Docker already use the
+ # gateway.
+ disable_direct_bedrock = False
@staticmethod
def creation_cancellation_scope(cancel_event: threading.Event) -> AbstractContextManager[None]:
diff --git a/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py b/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py
index dcc89645b261..d339c5b666e9 100644
--- a/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py
+++ b/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py
@@ -24,6 +24,7 @@ from products.tasks.backend.logic.services.sandbox import (
SandboxConfig,
SandboxStatus,
SandboxTemplate,
+ build_agent_runtime_env_prefix,
get_sandbox_class_for_sandbox_id,
)
@@ -330,3 +331,20 @@ class TestHoglandAuthPrecedence:
with override_settings(HOGLAND_API_TOKEN_FILE=file_setting, HOGLAND_API_TOKEN=static_token):
assert get_hogland_api_token() == expected
+
+
+class TestHoglandBedrockDisabled:
+ def test_hogland_opts_out_of_direct_bedrock(self):
+ # hogland boxes boot with the bedrock feature (CLAUDE_CODE_USE_BEDROCK=1);
+ # the sandbox opts in to unsetting it so the agent uses the LLM gateway.
+ assert HoglandSandbox.disable_direct_bedrock is True
+
+ def test_env_prefix_unsets_bedrock_vars_when_requested(self):
+ prefix = build_agent_runtime_env_prefix(unset_bedrock=True)
+ assert "-u CLAUDE_CODE_USE_BEDROCK" in prefix
+ assert "-u AWS_CONTAINER_CREDENTIALS_FULL_URI" in prefix
+
+ def test_env_prefix_keeps_bedrock_vars_by_default(self):
+ prefix = build_agent_runtime_env_prefix()
+ assert "CLAUDE_CODE_USE_BEDROCK" not in prefix
+ assert "AWS_CONTAINER_CREDENTIALS_FULL_URI" not in prefix