feat(tasks): add runtime_adapter label to run token metrics#71447
Conversation
The tasks_run_total_tokens / tasks_run_tokens_total metrics carry an rtk_enabled cohort label but no adapter, so the rtk cohort comparison can't separate Claude runs (deterministic PreToolUse rewriting) from Codex runs (instruction-level adoption). Label terminal-run token metrics with the run's runtime adapter, bounded to claude/codex/other/unknown. Also corrects the sandbox Dockerfile comment that claimed rtk is auto-detected by "the agent" — that is true only for Claude. Generated-By: PostHog Code Task-Id: b005dede-2677-4364-94a2-c2a7e90e376a
|
Reviews (1): Last reviewed commit: "feat(tasks): add runtime_adapter label t..." | Re-trigger Greptile |
|
Note 🤖 stamphog reviewed Gate verdict is DENIED (deny-list hit on toolchain/infra plus T2-never tier), which forces routing to a human regardless of how contained the diff looks; the diff itself (metrics label + Dockerfile comment fix) appears low-risk and Greptile left a 👍 with no concerns.
Gate mechanics and policy version
|
🤖 CI report
|
| File | Patch | Uncovered changed lines |
|---|---|---|
products/tasks/backend/temporal/process_task/activities/tests/test_update_task_run_status.py |
0.0% | 120 |
products/tasks/backend/temporal/process_task/activities/update_task_run_status.py |
0.0% | 107 |
products/tasks/backend/temporal/metrics.py |
40.0% | 79–81 |
🤖 Agents: add a test covering the lines above, or note why under "How did you test this code?". Machine-readable gap list: the patch-coverage artifact on this run (gh run download 29490050673 -n patch-coverage), or the coverage-data block at the end of this comment.
Per-product line coverage (touched products)
| Product | Coverage | Lines |
|---|---|---|
tasks |
█████████████░░░░░░░ 67.4% |
25,787 / 38,257 |
Report-only. Patch coverage = changed backend lines covered vs origin/master. Sorted lowest first.
Known gaps: lines covered only by Temporal tests show as uncovered; core line numbers may drift if master changed the same file.
Problem
The terminal-run token metrics (
tasks_run_total_tokens,tasks_run_tokens_total) carry anrtk_enabledcohort label but no runtime adapter, so the rtk cohort panels on the cloud-background-agents-runs dashboard can't separate Claude runs (where rtk is applied deterministically via a PreToolUse rewrite hook) from Codex runs (where rtk adoption is instruction-level, added in PostHog/code#3491). Without the split there's no way to see whether the Codex integration actually moves tokens per run.Why: rtk command-output compression is being extended to cloud Codex runs, and the per-adapter cohort is the graph that validates (or falsifies) that change.
Changes
record_run_token_usagenow takes the run'sruntime_adapter(read fromTaskRun.state, where run creation already persists it) and labels both token metrics with it, bounded toclaude/codex/other/unknownto cap cardinality.Dockerfile.sandbox-basecomment that claimed "the agent" auto-detects rtk on PATH — that is true only for Claude; Codex has no command-rewrite channel and is instructed instead.Companion dashboard change (splitting the rtk cohort panels by this label) goes to the grafana-dashboards repo.