Skip to content

fix(service): show a state record that the Service could not write #4048

Description

@dan-petty

Problem

keep_state_record (server/service.py) logs one error line and goes on with memory only when a record cannot be written. This is a documented design (#2474). RequestBudget.admit calls it for every admitted request, so it must not raise there.

The Service writes three records:

  • the request budget (RequestBudget, service.py);
  • the halt file (service.py, line 386);
  • the failure ledger (FailureLedger._keep_locked, run.py).

After a write error, nothing shows the fault except one log line. A restart loses the state.

Expected

Keep the log line in the request path. Keep keep_state_record from raising.

Add a kind argument to keep_state_record: budget, halt or ledger. Each of the three call sites passes its own value.

Add the gauge devops_cli_service_state_unkept with the label record (the kind). keep_state_record sets it with GLOBAL_METRICS.set_gauge:

  • 1 after a write error;
  • 0 after the next write that works.

The gauge has 3 series. The next round start does not fail.

Add the alert RoadmapServiceStateUnkept (warning, for 15 minutes) to k8s/monitoring/prometheus-values.yaml. Add a promtool case in tests/fixtures/prometheus_rules/roadmap_service_tests.yaml. Add a row in the alert tables of k8s/README.md.

Acceptance criteria

  • uv run pytest tests/server/test_service_state_unkept.py -k budget_write_error - a write error of the budget file logs, sets the gauge to 1 for budget, and raises nothing in admit. The next good write sets 0.
  • uv run pytest tests/server/test_service_state_unkept.py -k 'halt_write_error or ledger_write_error' - a write error of the halt file and of the ledger file each set the gauge for their record.
  • grep -q 'RoadmapServiceStateUnkept' k8s/monitoring/prometheus-values.yaml && grep -q 'RoadmapServiceStateUnkept' tests/fixtures/prometheus_rules/roadmap_service_tests.yaml && uv run pytest tests/prometheus/test_k8s_monitoring_alerting.py - the alert and its promtool case exist and pass.

Every command above fails on the unchanged code. The pull request cites the fail-to-pass run (devops ci fail-to-pass --base <ref>).

Feasibility

I read these files at origin/main: server/service.py (read_state_record, keep_state_record, RequestBudget.admit, the halt write), run.py (FailureLedger._keep_locked, _report_locked) and k8s/README.md. I checked that GLOBAL_METRICS.set_gauge takes labels (the gauge devops_cli_service_job_suspended uses them). I did not run the Service.

A first plan made the halt and ledger faults fail the next round start. That is dropped. A disk fault should not stop all work. The gauge and the alert give the signal.

Existing tool considered

The gauge helpers of GLOBAL_METRICS, read_state_record and the existing alert group. No library is needed.

Cost

Build: about 40k tokens and 2 h (gauge, alert, 3 call sites, 4 tests). Keep: about 2k tokens per quarter. Fix: about 10k tokens and 0.5 h.

Related

Part of #3027. #3666, #3655. Order: this issue changes run.py after the issue #4042.

Activity

  1. added
    source/agent
    type/bug
    scope/service
    status/new
    value/medium
    effort/medium
    on Nov 7, 2026
  2. dan-petty commented on Nov 7, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/service. The (service) scope of the title gives the scope.
    • Priority: P2-Medium. A state write failure is silent except for one log line, but it does not stop the Service, so it is important yet not urgent.
    • Value: Medium. Operators gain a Prometheus signal and an alert for state write failures that today are invisible in dashboards.
    • Effort: Medium. The change touches three call sites, adds one gauge, one alert, one promtool case, and four tests in about 2 hours.
    • Related: fix(service): a restart keeps the halt, the budget window and the failure ledger, and a secondary limit or a suspended installation stops every worker #2474, which asks for a different change. Both concern keep_state_record in service.py; #2474 made the state persist across restarts, the candidate adds a gauge and alert for when a write fails.
  3. added
    priority/p2-medium
    on Nov 7, 2026
  4. added
    owner/agent
    status/in-review
    and removed
    status/new
    on Nov 8, 2026
  5. removed
    status/in-review
    owner/agent
    on Nov 8, 2026
  6. added a commit that references this issue on Nov 8, 2026
  7. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-08 05:08 UTC

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

    effort/mediumpriority/p2-mediumscope/servicesource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions