Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions products/tasks/backend/sandbox/images/Dockerfile.sandbox-base
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ENV GH_TELEMETRY=false

# Install system packages (expanded for coding environments)
RUN apt-get update && \

Check warning on line 13 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`

Check warning on line 13 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`

Check warning on line 13 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
apt-get install -y --no-install-recommends \
# Core tools
curl \
Expand Down Expand Up @@ -56,12 +56,12 @@
&& rm -rf /var/lib/apt/lists/*

# Install Node.js 24.x
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - && \

Check warning on line 59 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`

Check warning on line 59 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

Check warning on line 59 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`

Check warning on line 59 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

Check warning on line 59 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`

Check warning on line 59 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check
apt-get install -y --no-install-recommends nodejs && \
rm -rf /var/lib/apt/lists/*

# Install additional language package managers
RUN npm install -g yarn pnpm typescript ts-node nodemon

Check warning on line 64 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in npm. Instead of `npm install <package>` use `npm install <package>@<version>`

Check warning on line 64 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in npm. Instead of `npm install <package>` use `npm install <package>@<version>`

Check warning on line 64 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Pin versions in npm. Instead of `npm install <package>` use `npm install <package>@<version>`

# Install ruff and ty
# uv comes from its pinned, registry-verified official image (same pattern as the
Expand All @@ -85,7 +85,7 @@

# Install agentsh for runtime egress policy enforcement
ARG AGENTSH_TAG=v0.18.3
RUN set -eux; \

Check warning on line 88 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

Check warning on line 88 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

Check warning on line 88 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check
version="${AGENTSH_TAG#v}"; \
arch="$(dpkg --print-architecture)"; \
case "$arch" in \
Expand All @@ -105,11 +105,13 @@
ENV AGENTSH_SERVER=http://127.0.0.1:18080

# Install rtk (https://github.com/rtk-ai/rtk), a proxy that compresses the output of
# common dev commands before it reaches the model. The agent auto-detects it on PATH
# and routes eligible Bash commands through it; POSTHOG_RTK=0 (set per run from the
# task processing context) opts a run out.
# common dev commands before it reaches the model. Claude runs auto-detect it on PATH
# and route eligible Bash commands through it via a PreToolUse rewrite hook; Codex has
# no command-rewrite channel, so its runs are told to prefix eligible commands in the
# developer instructions instead. POSTHOG_RTK=0 (set per run from the task processing
# context) opts a run out of both.
ARG RTK_VERSION=0.43.0
RUN set -eux; \

Check warning on line 114 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

Check warning on line 114 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check

Check warning on line 114 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check
arch="$(dpkg --print-architecture)"; \
case "$arch" in \
amd64) rtk_asset="rtk-x86_64-unknown-linux-musl.tar.gz"; \
Expand All @@ -132,7 +134,7 @@
# Set up /scripts as a Node.js project and install @posthog/agent
# COMMIT_HASH changes every build, busting the cache so each build pulls @latest
ARG COMMIT_HASH
RUN mkdir -p /scripts && \

Check warning on line 137 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Use WORKDIR to switch to a directory

Check warning on line 137 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Use WORKDIR to switch to a directory

Check warning on line 137 in products/tasks/backend/sandbox/images/Dockerfile.sandbox-base

View workflow job for this annotation

GitHub Actions / Lint changed Dockerfiles

Use WORKDIR to switch to a directory
cd /scripts && \
npm init -y && \
CACHE_BUST=${COMMIT_HASH} npm install @posthog/agent@latest
Expand Down
12 changes: 12 additions & 0 deletions products/tasks/backend/temporal/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ def _bool_label(value: bool | None) -> str:
return "true" if value else "false"


_ALLOWED_RUNTIME_ADAPTERS = {"claude", "codex"}


def _runtime_adapter_label(value: str | None) -> str:
"""Bounded label: unexpected values collapse to "other" to cap cardinality."""
if not value:
return "unknown"
return value if value in _ALLOWED_RUNTIME_ADAPTERS else "other"


def increment_snapshot_usage(
used_snapshot: bool,
*,
Expand Down Expand Up @@ -139,6 +149,7 @@ def record_run_token_usage(
origin_product: str | None,
run_environment: str | None,
rtk_enabled: bool | None,
runtime_adapter: str | None,
status: str | None,
) -> None:
"""Record a terminal run's token expenditure (from ``TaskRun.state.token_usage``).
Expand All @@ -150,6 +161,7 @@ def record_run_token_usage(
"origin_product": origin_product or "unknown",
"run_environment": run_environment or "unknown",
"rtk_enabled": _bool_label(rtk_enabled),
"runtime_adapter": _runtime_adapter_label(runtime_adapter),
"status": status or "unknown",
}
for kind, key in _RUN_TOKEN_KINDS.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_terminal_transition_captures_analytics_with_usage(
**(test_task_run.state or {}),
"token_usage": dict(TOKEN_USAGE),
"rtk_effective": True,
"runtime_adapter": "codex",
}
test_task_run.save(update_fields=["state"])

Expand All @@ -116,6 +117,7 @@ def test_terminal_transition_captures_analytics_with_usage(
assert props["run_environment"] == test_task_run.environment
mock_record.assert_called_once()
assert mock_record.call_args.kwargs["rtk_enabled"] is True
assert mock_record.call_args.kwargs["runtime_adapter"] == "codex"
assert mock_record.call_args.kwargs["status"] == status

@pytest.mark.django_db(transaction=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ def _capture_terminal_analytics(task_run: TaskRun, input: UpdateTaskRunStatusInp
state = task_run.state if isinstance(task_run.state, dict) else {}
usage = state.get("token_usage")
if isinstance(usage, dict):
adapter = state.get("runtime_adapter")
record_run_token_usage(
usage,
origin_product=task_run.task.origin_product,
run_environment=task_run.environment,
rtk_enabled=task_run.effective_rtk(),
runtime_adapter=adapter if isinstance(adapter, str) else None,
status=input.status,
)
except Exception:
Expand Down
Loading