Repository navigation
Closed
Labels
Description
Friction
- Since fix(telemetry): delta metrics from one process can reach the collector out of order #792 (v0.2.36) devops-cli keeps its counters in an in-memory DELTA reader and exports them only when
flush()runs: at the end of eachmain._delegatecall and at exit. devops serve --serviceruns every roadmap job, including the intake and refine model calls, inside one long_delegatecall.- So roadmap-service would export its AI requests, tokens and savings once, at pod shutdown, and lose them on SIGKILL or an OOM kill.
- Each pod reports as
instance=<pod name>, so that single late sample opens a new series thatincrease()andrate()never count. The Service's model traffic would read as zero on the ai-spend-telemetry panels, with no spike. - Before suspension the Service sent about 490-680 model requests a week (gateway
devops-background: about 683 in the 7 days to 2026-10-10 23:00 UTC). - The defect is latent while the Service is held at 0 replicas (chore(service): the roadmap service stays at 0 replicas, and its development is blocked, while its machine account is suspended #1562). It starts the day chore(service): the roadmap service stays at 0 replicas, and its development is blocked, while its machine account is suspended #1562's revert merges.
- Cluster Jobs from
k8s/devops/cronjob.yamlset noOTEL_SERVICE_NAME, so they report asjob="devops-cli", mixed with workstation runs.
Evidence
Checked at main 3dd7fa6 (v0.2.36) on 2026-10-17, read-only.
ServiceLaneWorker._execute_batch(src/devops_cli/server/service.py:235-279) runsjob_funcin-process, records onlyGLOBAL_METRICSgauges and never flushes.- The service app's
/metricsserves onlyGLOBAL_METRICS(service.py:560-565), so AI counters leave the pod only through OTLP. flush()(src/devops_cli/telemetry/tracer.py:1377-1401) is called fromsrc/devops_cli/main.py:209-212and from the atexit hook (tracer.py:1634). Nothing insrc/ork8s/uses a periodic metric reader.- Intake and refine reach
track_request_spendin-process:src/devops_cli/roadmap/run.py:683-702,:1017-1043;src/devops_cli/roadmap/refine.py:951;src/devops_cli/roadmap/intake_model.py:166-189. service.instance.idis the host name (tracer.py:979-983), which in a pod is the pod name. Prometheus holds 21 distinctroadmap-service-*instances.k8s/devops/roadmap-service/deployment.yamlrunsserve --service(:41-49) withreplicas: 0(:12),strategy: Recreate(:13-14) andOTEL_SERVICE_NAME=roadmap-service(:68-69).k8s/devops/cronjob.yaml:48-55sets noOTEL_SERVICE_NAME.- MCP tools are not affected: each dispatch runs through
main._delegate(src/devops_cli/ai/mcp/dispatcher.py:335-367) and flushes when it ends.
Remedy
Tests first, in tests/test_server_service.py, with the tracer's export path replaced by the test fake. No network or cluster:
- A batch that records one AI request triggers one metrics export before the next batch starts.
- A batch whose job raises still exports.
- Two batches export two deltas whose sum equals the requests recorded, so repeated collects do not double-count.
- With
OTEL_RESOURCE_ATTRIBUTES=service.instance.id=roadmap-serviceset, the exported resource carries that id instead of the host name. Without it, the host name stays.
Code:
- Call
get_tracer().flush()after each job in_execute_batch, in afinally. The DELTA reader returns only what changed since the last collect. The export keeps the existing_send_payloadpath with its dry-run gate and export-failure counters. - Give the single-replica Service one series identity across pods, so a new pod's first export continues the series instead of opening one that
increase()never counts. Proposed: merge the SDK's standardOTEL_RESOURCE_ATTRIBUTESthroughResource.createin the tracer, and setservice.instance.id=roadmap-serviceindeployment.yaml.Recreatemeans two pods never send at once. Workstations keep the host name. - Set
OTEL_SERVICE_NAMEink8s/devops/cronjob.yaml(for exampledevops-cli-job) so cluster Jobs are told apart from workstation runs. - Pending a person, after chore(service): the roadmap service stays at 0 replicas, and its development is blocked, while its machine account is suspended #1562's revert:
sum(increase(devops_cli_ai_requests_total{job="roadmap-service"}[24h]))is within a few percent of the gateway'sdevops-backgroundcount.
Depends on: #1132 as amended (streams that survive idle gaps). Lands any time; it matters from #1562's revert on.
Proposed: type/bug, P2-Medium. Latent until #1562 reverts, and no P1 waits on it.
Proposed design
Problem statement
The roadmap-service exports its AI usage counters only once at pod shutdown, losing data on SIGKILL or OOM kill. This results in zero AI spend telemetry as Prometheus's increase() and rate() functions never count the series that opens with a late sample.
Acceptance criteria
- Criterion 1: A batch that records one AI request triggers one metrics export before the next batch starts.
Verification: Write a test intests/test_server_service.pythat verifies a single AI request in a batch results in one export. - Criterion 2: A batch whose job raises still exports AI counters.
Verification: Write a test intests/test_server_service.pythat verifies an exception in the job function still causes metrics to be exported. - Criterion 3: Two batches export two deltas whose sum equals the requests recorded, so repeated collects do not double-count.
Verification: Write a test intests/test_server_service.pythat verifies multiple batches with AI requests result in correct cumulative exports. - Criterion 4: With
OTEL_RESOURCE_ATTRIBUTES=service.instance.id=roadmap-serviceset, the exported resource carries that id instead of the host name.
Verification: Verify that when the environment variable is set, the service instance ID in the OTLP payload matches the value provided.
Key questions
- Where does the service app's
/metricsendpoint serve metrics from?: The service app's/metricsserves onlyGLOBAL_METRICS. [sources: src/devops_cli/server/service.py:560-565] - How does the roadmap-service export AI usage counters?: AI counters are exported via OTLP through the
flush()function called frommain._delegateand atexit hook. [sources: src/devops_cli/telemetry/tracer.py:1377-1401, src/devops_cli/main.py:209-212] - Which files are affected by the changes needed to fix this issue?: The changes affect
src/devops_cli/server/service.pyandsrc/devops_cli/telemetry/tracer.py, along with deployment configuration ink8s/devops/roadmap-service/deployment.yamland cronjob configuration ink8s/devops/cronjob.yaml. [sources: src/devops_cli/server/service.py:235-279, src/devops_cli/telemetry/tracer.py:1377-1401, k8s/devops/roadmap-service/deployment.yaml, k8s/devops/cronjob.yaml] - Should the Service's instance ID be changed to ensure continuity of AI spend telemetry?: Yes, to ensure that a new pod's first export continues the series instead of opening one that
increase()never counts, the service.instance.id should be set to 'roadmap-service' in the deployment. (proposed) [sources: src/devops_cli/telemetry/tracer.py:979-983, k8s/devops/roadmap-service/deployment.yaml]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 18, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
The candidate describes a defect in the service's AI usage counter exports, which is a bug fix.The defect causes loss of AI spend telemetry data and affects monitoring of the roadmap service's usage.Fixing this ensures accurate tracking of AI resource consumption for billing and operational insights.Requires changes to metric export logic, tracer integration, and deployment configurations with moderate complexity.dan-petty commentedon Oct 18, 2026
Status set to Ready at 25e2cda (see proposed design in issue body).