Skip to content

feat(server): count a closed roadmap item once across router replicas #4895

Open

Description

@devops-cli-service

Split from #4580.

Problem: devops_cli_service_roadmap_items_closed_total counts a delivery after the in-memory DeliveryLRUCache check (src/devops_cli/server/routes/webhooks.py:567), and each router process holds its own cache, so a redelivery that reaches a second replica adds a second count. Why deferred: the exact count needs the shared delivery state of the change feat(service): share the GitHub budget and holds in Valkey, whose key form roadmap:v1:delivery:<id> is not in the repository and which has no issue number. Issue #4580 delivers the counter with the in-memory check and leaves this part to that change. Acceptance criteria: With the shared SET NX of roadmap:v1:delivery:<id>, the router counts a closed delivery only when its SET NX succeeds. Two router instances that share the delivery store count one delivery once. A test with a fake delivery store asserts one count for two deliveries with the same id on two router instances.

Proposed design

Problem statement

Do not build this issue until the shared Valkey delivery store exists. The metric devops_cli_service_roadmap_items_closed_total counts a closed delivery after the in-memory DeliveryLRUCache check. Each router process holds its own cache. A redelivery that reaches a second replica adds a second count. The fix needs the shared Valkey delivery store and the key roadmap:v1:delivery:<id>. That store is not in the repository.

Acceptance criteria

Requirement: count-on-claimed-delivery

The router SHALL increment devops_cli_service_roadmap_items_closed_total for a closed delivery only after its SET NX on roadmap:v1:delivery:<id> returns OK.

Scenario: first-delivery-claims-the-key

  • WHEN A router instance receives a delivery with action closed and id d1, and the fake delivery store returns OK to its SET NX on roadmap:v1:delivery:d1.
  • THEN devops_cli_service_roadmap_items_closed_total increased by exactly one.

Requirement: no-count-on-existing-claim

The router MUST NOT increment devops_cli_service_roadmap_items_closed_total when its SET NX on roadmap:v1:delivery:<id> returns nil.

Scenario: redelivery-to-a-second-replica

  • WHEN A second router instance receives a delivery with id d1, and the fake delivery store returns nil to its SET NX on roadmap:v1:delivery:d1.
  • THEN devops_cli_service_roadmap_items_closed_total does not change.

Requirement: one-count-for-two-replicas

Two router instances that share one delivery store SHALL count one delivery exactly once.

Scenario: two-instances-one-shared-store

  • WHEN Two router instances with one shared fake delivery store each receive a delivery with id d1.
  • THEN devops_cli_service_roadmap_items_closed_total increased by exactly one in total.

Requirement: no-count-and-no-cache-on-store-error

The router SHALL NOT increment the metric and SHALL NOT cache the delivery id when the delivery store raises an error on the SET NX call.

Scenario: store-unavailable

  • WHEN The fake delivery store raises a connection error on the SET NX call for delivery d1.
  • THEN devops_cli_service_roadmap_items_closed_total does not change, and the in-memory cache holds no entry for d1.

Requirement: delivery-key-has-a-ttl

The router SHALL set the key roadmap:v1:delivery:<id> with a positive expiry in the same SET NX call.

Scenario: claim-sets-an-expiry

  • WHEN The router claims delivery d1, and the fake delivery store records the arguments of the SET NX call.
  • THEN The recorded call carries a positive expiry.

Existing Tool Considered

No alternatives check has run. Valkey 9.1.3 is the open, maintained store that ADR 0021 section 3 selects. It gives one atomic SET NX on roadmap:v1:delivery:<id>. The first router instance claims a delivery and counts it. Valkey lacks the delivery store itself: the key roadmap:v1:delivery:<id> and its client path are not in the repository. The change feat(service): share the GitHub budget and holds in Valkey adds them.

This proposal builds no lock of its own. It adds one claim call and a fake store in the test.

Key questions

  • Which mechanism gates the count across router replicas?: One atomic SET NX in the shared Valkey store on the key roadmap:v1:delivery:<id>. The first router instance that sets the key counts the delivery. A second instance gets a nil answer and counts nothing. (best practice) [sources: docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, src/devops_cli/server/routes/webhooks.py:554]
    • Chosen: Valkey SET NX on roadmap:v1:delivery:<id>. ADR 0021 section 3 moves the delivery ids to valkey-roadmap. SET NX is one atomic command. The first instance claims the delivery and counts it.
    • Rejected: In-memory DeliveryLRUCache in each replica. Each router process holds its own cache. A redelivery on a second replica is not detected and adds a second count.
  • What does the router do when the delivery store does not answer the SET NX call?: It fails closed. It counts nothing and does not cache the delivery id. (best practice) [sources: docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
    • Chosen: Fail closed and count nothing. ADR 0021 section 3 rule 9 says each caller fails closed when the store does not keep its data.
    • Rejected: Fail open and count the delivery. A count with no SET NX result breaks the once-only rule across replicas.
  • Where does the metric increment occur relative to the SET NX call?: After the SET NX call returns OK. Only the instance that claims the delivery counts it. (best practice) [sources: src/devops_cli/server/routes/webhooks.py:567, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
    • Chosen: Increment after the SET NX call returns OK. Only the instance that claims the delivery counts it. Two replicas count one delivery once.
    • Rejected: Increment before the SET NX call. A failed or duplicate SET NX then leaves a count for a delivery that the router did not claim.
  • Does the in-memory DeliveryLRUCache stay beside the shared claim?: It stays as a fast filter only. The Valkey claim decides the count. The router caches the delivery id only after the SET NX returns OK. (best practice) [sources: src/devops_cli/server/routes/webhooks.py:554, src/devops_cli/server/service.py, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
    • Chosen: Claim in Valkey first, then cache the id in memory. The store decides the count. A store error leaves no cache entry, so a redelivery can still claim the key and count once.
    • Rejected: Remove DeliveryLRUCache in this change. The cache also serves the Service path in src/devops_cli/server/service.py. Its removal belongs to the change that moves the delivery state.
    • Rejected: Count from the in-memory cache only. That is the current defect. Each replica holds its own cache and counts a redelivery again.
  • Does the delivery key carry a TTL?: Yes. The SET NX call sets a positive expiry on the key. (best practice) [sources: docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
    • Chosen: Set a TTL on the claim. ADR 0021 section 3 rule 6 requires a TTL or one owner that deletes the key. No job deletes a delivery key, so the TTL is the choice.
    • Rejected: Keep the key until an owner deletes it. No job deletes a delivery key, so the store grows without limit.

Fit

Fits in one pull request.

Suspected block

The shared Valkey delivery store and the key roadmap:v1:delivery:<id> from the change feat(service): share the GitHub budget and holds in Valkey, which is not in the repository and has no issue number.

Dependencies

None.

Activity

  1. added
    type/feature
    source/agent
    status/new
    value/medium
    effort/medium
    on Nov 12, 2026
  2. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    ContributorAuthor

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

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: none. The title has the scope server, and .github/labels.yml declares no scope/server label. Add the label to the file to give the scope to this item.
    • Priority: P2-Medium. The metric overcounts only when a redelivery reaches a second replica, and the shared store is not in the repository.
    • Value: Medium. Accurate closed-item counts help the pipeline dashboard, but a double count affects only redeliveries across replicas.
    • Effort: Medium. The change needs integration with a shared delivery store and a new two-replica test with a fake store.
    • Related: feat(roadmap): count closed items per repository and reason #4580, which asks for a different change. Both items count closed roadmap deliveries, but #4580 uses an in-memory check and the candidate deduplicates across replicas with a shared SET NX.
  3. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    ContributorAuthor

    Owner question: The shared Valkey delivery store (key roadmap:v1:delivery:<id>) from the change 'feat(service): share the GitHub budget and holds in Valkey' is not in the repository and has no issue number.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: src/devops_cli/server/routes/webhooks.py, src/devops_cli/server/service.py.

  4. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    ContributorAuthor

    Owner question: The shared Valkey delivery store with the key roadmap:v1:delivery:<id>, from the change feat(service): share the GitHub budget and holds in Valkey, is not in the repository and has no issue number.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: src/devops_cli/server/routes/webhooks.py, src/devops_cli/server/service.py.

  5. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    ContributorAuthor

    Owner question: The shared Valkey delivery store with the key roadmap:v1:delivery:<id>, from the change feat(service): share the GitHub budget and holds in Valkey, is not in the repository and has no issue number.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  6. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    ContributorAuthor

    Owner question: See Suspected block and Watched files in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  7. devops-cli-service commented on Nov 21, 2026

    @devops-cli-service
    ContributorAuthor

    Owner question: See Suspected block in the section Proposed design of the body.

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

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-mediumsource/agentstatus/newtype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions