Skip to content

fix(roadmap): repair a job record mark that a parallel write lost #4555

Closed

Description

@dan-petty

Problem or Motivation

A job record write joins the record that the issue holds at its GET (src/devops_cli/roadmap/stores/github_store.py:20-27). GitHub has no conditional write of an issue (github_store.py:24-25). The ADR 0002 guard compares field labels only (github_store.py:799-805); set_marks and write_issue_body have no guard (github_store.py:810-818,871-880).

The lock _JOB_RECORD_LOCK is per process (github_store.py:97). The runner Job and claims (src/devops_cli/roadmap/claim.py:120) write records outside it. So two writers can lose each other's marks today, and a lost mark raises nothing. More writers come when stage leaves the Service pod.

Proposed Solution & Architectural Design

  • After each record PATCH, read the record back. If a mark that this writer set is missing, write again, up to 2 times. Log and count each repair.
  • A third miss raises an error that names the item and the mark.
  • A Valkey lock comes later ("feat(roadmap): keep plan records and record locks in Valkey"). It narrows the window, but this read-back repair stays the guard.

Target Subsystem

SDLC, Git & PR Governance (roadmap job records: src/devops_cli/roadmap/stores/github_store.py).

Existing Tool Considered

None covers it: GitHub gives no fence and no conditional write for an issue. A lock narrows the window but cannot close it. Cost: about 90,000 tokens and 4 hours to build, about 5,000 tokens a month to keep, about 10,000 tokens to fix. One more GET for each record write.

Acceptance Criteria

  • A fail-to-pass test with two stores on one GitHub fake: each does its GET before either PATCH; after both writes, the issue holds the marks of both (docs/TESTING.md; the fault mode of InMemoryRoadmapStore).
  • A third miss raises with the item and the mark.
  • The repair counter is in /metrics and in the runner Job's OTLP export.
  • The pull request cites the devops ci fail-to-pass --base <ref> output.

Dependencies

None.

Source: #4517

Proposed design

Problem statement

A job record write reads the issue, then sends one PATCH. GitHub has no conditional write of an issue. Two writers that read before either writes lose each other's marks, and the loss raises nothing. The change reads the record back after each PATCH, writes again when a mark is missing, and raises when the loss repeats.

Acceptance criteria

Requirement: A lost mark is repaired

A record write SHALL read the record back after its PATCH and write again when a mark that it set is missing.

Scenario: Two stores interleave one write

  • WHEN Two stores on one GitHub fake each read the issue before either sends its PATCH.
  • THEN The issue holds the marks of both writers after both writes.

Requirement: The repair stops after two rewrites

A record write SHALL send at most 2 rewrites after its first PATCH.

Scenario: A third miss

  • WHEN The read-back shows the mark missing after the second rewrite.
  • THEN The write raises an error that names the item and the missing mark.

Requirement: Each repair is logged and counted

Each repair SHALL write one log line and increment one counter.

Scenario: One repaired write

  • WHEN One write repairs one missing mark.
  • THEN The log holds one line for the repair and the counter rises by one.

Requirement: The repair counter is exported

The repair counter SHALL appear in /metrics and in the OTLP export of the runner Job.

Scenario: A repair in the runner Job

  • WHEN The runner Job repairs one missing mark and exports its metrics.
  • THEN /metrics and the OTLP export each hold the counter with the value 1.

Requirement: A person's field change still raises

A field that a person changed since the read SHALL still raise RoadmapItemChangedError before any write.

Scenario: A person changes a field between the read and the write

  • WHEN A person changes a field after the store reads the issue and before its PATCH.
  • THEN The store raises RoadmapItemChangedError and sends no PATCH.

Requirement: The repair test fails on the base

The new test SHALL fail on the base commit and pass on the head commit.

Scenario: Fail-to-pass replay

  • WHEN The pull request runs devops ci fail-to-pass --base <ref>.
  • THEN The output reports the new test as failed on the base and passed on the head.

Existing Tool Considered

No alternatives check has run. No open, maintained tool or library covers the need: GitHub offers no conditional write and no fence for an issue PATCH, and no library can add one. A lock narrows the window but cannot close it. The written cost is about 90,000 tokens and 4 hours to build, about 5,000 tokens a month to keep, and about 10,000 tokens to fix. It adds one GET for each record write.

Key questions

  • Which guard keeps a parallel write from losing a mark?: Read the record back after each PATCH and write again when a mark that the writer set is missing. The write fails after 2 rewrites. (best practice) [sources: src/devops_cli/roadmap/stores/github_store.py, openspec/changes/archive/2026-10-30-2757-implement-status-lane/design.md]
    • Chosen: Read-back repair. It needs no change at GitHub and it catches every loss that the next read sees.
    • Rejected: A Valkey lock only. A lock narrows the window between two requests. It cannot close the window, so a lost mark stays possible.
    • Rejected: A conditional write with an ETag. GitHub gives no conditional write for an issue PATCH.
  • How many rewrites does a write make before it fails?: Two rewrites. The third miss raises. (best practice) [sources: src/devops_cli/roadmap/stores/github_store.py]
    • Chosen: 2 rewrites. Two writers lose one mark per round at most. Two rewrites settle that case, and a third miss shows a defect.
    • Rejected: 1 rewrite. Three writers can lose the mark twice in a row.
    • Rejected: No limit. A loop with no limit hides a mark that a writer can never set.
  • Where does the repair live in the GitHub store?: One private helper sends the PATCH and reads the record back. set_field, set_marks and write_issue_body each call it inside _JOB_RECORD_LOCK. (best practice) [sources: src/devops_cli/roadmap/stores/github_store.py]
    • Chosen: One shared helper. The three write paths then take one guard, and a later path cannot skip it.
    • Rejected: A guard in each of the three methods. Three copies of the loop drift, and a new write path gets no guard.
  • Which marks does the read-back compare?: The record keys that this writer set in its changes. A mark that another writer adds is no loss. (best practice) [sources: src/devops_cli/roadmap/stores/github_store.py]
    • Chosen: The keys of this writer. The writer can only report a mark that it set, and another writer's new mark is no loss.
    • Rejected: The whole record. A parallel writer adds keys. The whole-record compare then reports a loss that did not occur.
  • Which error does a third miss raise?: A new DevOpsCLIError subclass with its own exit code and error code, and a message that names the item and the mark. (best practice) [sources: docs/ERRORS.md, docs/TESTING.md, src/devops_cli/roadmap/stores/github_store.py]
    • Chosen: A new error subclass. A lost mark is no field change. A distinct class lets a caller tell the two cases apart.
    • Rejected: Reuse RoadmapItemChangedError. That error means a person changed a field. A retry of the same write cannot fix it, and a lost mark needs a different answer.
  • Which test interleaves the two writers?: A test with two GitHubRoadmapStore instances on GitHubFake. Each store reads the issue before either store sends its PATCH. [sources: tests/support/fakes/github_repository.py, tests/roadmap/stores/test_roadmap_github_store_record_writes.py, docs/TESTING.md]
  • Which metric carries the repair count?: One counter roadmap_record_repairs_total with the store method and the mark as labels. It joins the Service's Prometheus registry and the OTLP export of the runner Job. (best practice) [sources: docs/TELEMETRY.md]
    • Chosen: One counter with labels. The mark and the method are a closed set, so the label count stays small.
    • Rejected: One counter for each mark. A new record key then needs a new metric, and a dashboard edit.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-12: none.
Tool: none found.

Owner decision 2026-11-13

D5 (approved) keeps the record as the hidden block in the issue body. The approved pipeline split (tracker #5482, Phase 0) adds these rules to the read-back repair:

  • One writer for each item at a time: the unit that holds the item, or the sweep when no unit holds it.

  • Before the end write, read the issue again. Stop when an actor other than the App changed updated_at since the last read.

  • After the PATCH, compare the text outside the record with the text that was read. Restore a lost edit of a person, and count it in devops_cli_roadmap_record_lost_edit_total.

  • One end write for each unit, with all its keys.

  • A test: a person edit between the read and the PATCH is restored and counted.

  • Live proof: after the merge and the release, the Service and the Jobs write records as the App for 7 days. A comment gives the repair count and the lost-edit count. If the lost-edit count is above 0 after Phase 3, the owner looks again at D5 option (b): an App comment holds the record.

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 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/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. A silent mark loss corrupts job records, but it needs two writers in a narrow race window.
    • Value: Medium. Prevents silent data loss of marks that would mislead later jobs, but the trigger is a specific race.
    • Effort: Medium. Requires a read-back loop, retry limit, error path, metrics counter, and a two-store fail-to-pass test.
    • Related: fix(roadmap): write the item body and its marks in one request #4049, which asks for a different change. Both protect roadmap marks in github_store.py, but #4049 merges two sequential writes into one request while the candidate adds a read-back retry after a parallel write.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 5f75d25 (see proposed design in issue body).

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

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: The searches returned only general HTTP documentation on conditional requests and unrelated Python/Git pages; no open, maintained library provides a conditional or fenced write for a GitHub issue body, which is the need here. Preventing a lost mark therefore stays custom code in the GitHub store: read the record back after each PATCH, rewrite up to 2 times, and raise on a third miss.

    Tool: none found

    Lacks:

    • No tool offers a conditional write or fence for an issue PATCH on GitHub; conditional requests only work where the server honours If-Match/ETag.
    • No tool reads the record back and compares the marks that this writer set.
    • No tool raises a distinct error naming the item and the missing mark after a repeated miss.
    • No tool exports a repair counter for /metrics and the runner Job's OTLP export.

    Searches run:

    • GitHub REST API conditional write update issue ETag If-Match lost update, results: 5
    • Python library optimistic concurrency read-modify-write retry verify write GitHub issues, results: 5
    • tenacity retry library python exponential backoff, results: 5
    • GitHub API issue PATCH does not support If-Match ETag conditional update, results: 5
    • gidgethub async GitHub API client library, results: 5
    • docs.github.com REST API issues update endpoint, results: 5
    • githubkit python GitHub API library conditional request, results: 5
    • optimistic locking library python merge concurrent JSON document updates, results: 5

    Sources:

    Checked on 2026-11-12. A person decides what this means for the item. The check changes no label and closes no issue.

  8. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 14, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 14, 2026
  10. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor
  11. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-14 22:29 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/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions