Skip to content

fix(service): roadmap-service exports its AI usage counters after every lane batch, under one series identity that survives a pod restart #1629

Closed

Description

@dan-petty

Friction

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) runs job_func in-process, records only GLOBAL_METRICS gauges and never flushes.
  • The service app's /metrics serves only GLOBAL_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 from src/devops_cli/main.py:209-212 and from the atexit hook (tracer.py:1634). Nothing in src/ or k8s/ uses a periodic metric reader.
  • Intake and refine reach track_request_spend in-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.id is the host name (tracer.py:979-983), which in a pod is the pod name. Prometheus holds 21 distinct roadmap-service-* instances.
  • k8s/devops/roadmap-service/deployment.yaml runs serve --service (:41-49) with replicas: 0 (:12), strategy: Recreate (:13-14) and OTEL_SERVICE_NAME=roadmap-service (:68-69).
  • k8s/devops/cronjob.yaml:48-55 sets no OTEL_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-service set, 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 a finally. The DELTA reader returns only what changed since the last collect. The export keeps the existing _send_payload path 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 standard OTEL_RESOURCE_ATTRIBUTES through Resource.create in the tracer, and set service.instance.id=roadmap-service in deployment.yaml. Recreate means two pods never send at once. Workstations keep the host name.
  • Set OTEL_SERVICE_NAME in k8s/devops/cronjob.yaml (for example devops-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's devops-background count.

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 in tests/test_server_service.py that 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 in tests/test_server_service.py that 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 in tests/test_server_service.py that verifies multiple batches with AI requests result in correct cumulative exports.
  • Criterion 4: With OTEL_RESOURCE_ATTRIBUTES=service.instance.id=roadmap-service set, 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 /metrics endpoint serve metrics from?: The service app's /metrics serves only GLOBAL_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 from main._delegate and 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.py and src/devops_cli/telemetry/tracer.py, along with deployment configuration in k8s/devops/roadmap-service/deployment.yaml and cronjob configuration in k8s/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

#1132

Activity

  1. added
    source/agent
    type/bug
    on Oct 18, 2026
  2. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    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.

    • Type: type/bug. The candidate describes a defect in the service's AI usage counter exports, which is a bug fix.
    • Priority: P1-High. The defect causes loss of AI spend telemetry data and affects monitoring of the roadmap service's usage.
    • Value: High. Fixing this ensures accurate tracking of AI resource consumption for billing and operational insights.
    • Effort: Medium. Requires changes to metric export logic, tracer integration, and deployment configurations with moderate complexity.
  3. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 25e2cda (see proposed design in issue body).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source/agenttype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions