Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/ROADMAP_WORKFLOW.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Notes on the table:

## The transitions

Each row is one change of the Status label of an Item. A job never reverts a label that a person set ([ADR 0016](adr/0016-labels-hold-the-roadmap-items-fields.md)). Every job and command writes the label through one writer, `write_status` in `src/devops_cli/roadmap/status_sync.py` (#5018). It writes the label only when it differs, and reads the issue again after the write. When another writer changed the label in between, the write fails with `ROADMAP_STATUS_LOST`, and the next round derives the Status again. When the label is equal, the writer writes only the marks and the body of its caller. When someone changed the Status since its caller read the item, the writer writes nothing and fails with `ROADMAP_ITEM_CHANGED`, also when the label is equal (#5114).
Each row is one change of the Status label of an Item. A job never reverts a label that a person set ([ADR 0016](adr/0016-labels-hold-the-roadmap-items-fields.md)). Every job and command writes the label through one writer, `write_status` in `src/devops_cli/roadmap/status_sync.py` (#5018). It writes the label only when it differs, and reads the issue again after the write. When another writer changed the label in between, the write fails with `ROADMAP_STATUS_LOST`, and the next round derives the Status again. When the label is equal, the writer writes only the marks and the body of its caller. When someone changed the Status since its caller read the item, the writer writes nothing and fails with `ROADMAP_ITEM_CHANGED`, also when the label is equal (#5114). A refine round in the Service skips such an item and does not fail for it, and its next round reads the item again (#5299).

| From state | Event | To state | Actor |
| :--- | :--- | :--- | :--- |
Expand Down
1 change: 1 addition & 0 deletions docs/roadmap/job-success.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Some attempts write no line:

- A stop of the Service ends the round, and the attempt in progress writes no line.
- An alternatives check whose body a person changed since the read writes no line. The next round checks the item again.
- A refine item that a person or another job changed since the read writes no line. Refine does not write the item, the round does not fail, and the next round reads the item again.

A change that adds a cap extension to a job adds the count `extensions` to the line of that job.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-11-13
skip_specs: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Design

## Decisions

- **Catch the change in the writer of the Service round.** `RefineWriter.settle` catches `RoadmapItemChangedError` in its own `except` clause, before the clause of `DevOpsCLIError`. The error class is the one fact that tells a race from a failed write, and the store raises it before it changes anything. So the item needs no record, and the next round reads it again. The selection takes the item again, because refine wrote no mark.
- **One result for both checks of the race.** The store guard and the body check of `_apply_refined` find the same event: the item changed between the read and the write. Both give `RefineApplied(changed_count=1)`, and `settle` writes no result line and counts no write for both. The body check keeps its WARNING line, which its test reads (#1539).
- **A changed item writes no result line.** `docs/roadmap/job-success.md` already says that an alternatives check whose body a person changed since the read writes no line, and #5166 plans the same for intake. The race is no attempt of the job: refine did not revert a change that it did not see (ADR 0002), and no fix of refine can prevent the race. So the grade counts it neither as a success nor as a failure. The INFO line keeps each race visible in Loki.
- **A failed model call stays a failure.** When the record write of a `RefineFailure` meets a changed item, the failure stays in the failures of the round, and its line stays `error` with the class of the model call. Only the INFO line replaces the WARNING of a failed write.
- **The CLI path does not change.** `apply_refine`, which `devops roadmap refine --confirm` runs, still lets `RoadmapItemChangedError` go to the person (#5114). The issue is about the Service round.

## Rejected alternatives

- **Log `skipped` with `success=true`, as the acceptance of the issue says.** The issue builds this on the claim that intake counts `skipped` as an intended result, and that claim is false. A `success=true` line also counts an attempt that wrote nothing as a success, which lifts the grade of refine with no work, and it gives a third rule for the same race next to the rule of alternatives and the plan of #5166.
- **Log `skipped` with `success=false`, as intake does today.** The grade would still count a race that no fix can prevent as a fault of refine.
- **Make the body check raise `RoadmapItemChangedError`.** `apply_refine` would then stop the CLI round at the first changed body, which is a change of the CLI that the issue does not ask for.
- **Catch the error in `_apply_result`.** That also changes `apply_refine`, and the test of #5114 expects the CLI to raise.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Proposal: #5299

## Why

A refine round in the Service reads its items, calls a model for minutes, and then writes each item. When a person, a merged pull request or another job changes an item in that time, the store refuses the write with `RoadmapItemChangedError` before it changes anything (ADR 0002). `RefineWriter.settle` catches that error as a failed write: it logs a WARNING, adds the item to the unwritten items, and logs `result=error class=head_moved`. At the end of the round, `raise_for_failures` raises `RoadmapRefineError`, and the Service logs an ERROR with a full traceback for a normal event. The refine grade counts the item as a failure, but no fix can prevent the race. Refine also has a second check of the same race: when the body outside the refine section changed since the read, `_apply_refined` writes nothing, but the round logs the next step of the item as its result and counts the item as written. Closes #5299.

## What Changes

- The change fits one pull request.
- `RefineWriter.settle` catches `RoadmapItemChangedError` before the other write errors. It logs one INFO line that names the item, and does not add the item to the unwritten items. So the round does not fail for the item, and the next round reads it again.
- A changed item writes no `roadmap job result` line, as an alternatives check whose body a person changed writes none (`docs/roadmap/job-success.md`). So the job grade counts the race neither as a success nor as a failure.
- `_apply_refined` returns `RefineApplied(changed_count=1)` when the body changed since the read. The writer then writes no result line for that item and does not count it as written. Before, it logged the next step of a body that refine did not write.
- `RefineApplied` gets the count `changed_count`.
- A write that fails for another reason stays a failure: the item is unwritten, its line is `error`, and the round raises `RoadmapRefineError`.
- `devops roadmap refine --confirm` (`apply_refine`) does not change: a person who runs it still sees `ROADMAP_ITEM_CHANGED` (#5114).

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `roadmap-refine/writes`: a refine round skips an item that changed since the read, does not count it as a failed write, and writes no result line for it.

## Impact

- Code: `src/devops_cli/roadmap/refine/refine.py`, `src/devops_cli/lang/en/messages.py`.
- Tests: `tests/roadmap/refine/test_roadmap_refine_round.py`.
- Documents: `docs/roadmap/job-success.md`, `docs/ROADMAP_WORKFLOW.md`.
- Metrics: refine writes fewer result lines, one less for each race. The dashboard and the grade report count the lines, so no query changes. The INFO line `Refine did not write #N ...: the item changed since the read.` shows each race in Loki.
- Release: the Service runs this code, so the fix reaches the Service only with a release and a new image.
- Cost: no new request.

## Feasibility

- Loki, `{namespace="devops", service_name="roadmap-service"}`, last 48 hours: the race happened for #5213 (0.124.0, 2026-11-12T23:58:53Z), #5100 (0.120.0) and for item #34 of another repository (0.126.0, 2026-11-13T05:01:31Z). Each time the round logged `Refine wrote nothing more for #N ...: the write failed (RoadmapItemChangedError).`, then `roadmap job result: job=refine ... result=error success=false class=head_moved infra=false`, then an ERROR `Service job execution failed ... RoadmapRunError ... refine could not write 1 item(s), and went on: #N` with the traceback through `RefineWriter.raise_for_failures`. In the last 7 days, refine logged 3 `error` lines with the class `head_moved` and 1 with the class `provider`.
- Loki, last 7 days: the pre-check `Skipping #23: the body changed between the read and the write.` happened one time. The round logged the next step of that item as its result.
- Source on `main` at 4ef7c6f11: `RefineWriter.settle` (`refine.py:3381`) catches every `DevOpsCLIError` after the credentials and the stop, appends a `RefinedItem` to `_unwritten`, and `raise_for_failures` gives `_unwritten` to `raise_for_failed_items`, which raises. `_apply_refined` (`refine.py:3266`) returns `RefineApplied()` when `_outside_unchanged_since_read` is false, and `settle` then counts the item as written and logs its next step.
- The new tests ran on `main` before the fix (`devops ci fail-to-pass --base origin/main`). The item-changed case and the case of a person who moves the item during the round raised `RoadmapRefineError: refine could not write 1 item(s), and went on: #2`. The case of a body edit during the round logged `result=ready class=none` and `written=3`.
- The issue asks for the line `result=skipped class=head_moved success=true` and says that intake counts `skipped` as an intended result. That premise is not correct: `SUCCESS_RESULTS` of `intake` (`roadmap/job_result.py`) holds only `placed` and `duplicate`, and intake logs `skipped` with `success=false`. The rule of the project for this race is in `docs/roadmap/job-success.md`: an alternatives check whose body a person changed since the read writes no line. The open issue #5166, a child of the job grade issue #5164, plans the same rule for intake. The effect that #5299 gives, 12 of 15 in place of 12 of 16, is the count with no line. So this change writes no line, and does not add `skipped` to the intended results of refine. TypeSafe Jev, asked to pick between the two rules on this evidence, picked "no line" with a probability of 0.99.

## Existing Tool Considered

No open tool runs the refine job of this roadmap. The change reuses the store guard of ADR 0002, the class table of `roadmap/failure.py` and the result line of `roadmap/job_result.py`. It costs about 0.15M tokens to build and test, about 500 tokens to keep, and about 1 hour elapsed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## ADDED Requirements

### Requirement: A refine round skips an item that changed since the read
A refine round in the Service SHALL NOT write the body, the marks or the Status of an item that a person or another job changed between the read and the write, and SHALL NOT fail for it. The next round SHALL read the item again. The change is a write that the store refuses with `RoadmapItemChangedError`, or a body outside the refine section that changed.

#### Scenario: The Status of an item changes during the round
- **WHEN** a person moves item 2 of 3 to Blocked while the model works on it
- **THEN** items 1 and 3 are written, item 2 gets no write and one INFO line, the round ends with `taken=3`, `written=2` and `failed=0` and raises no error, and the next round takes item 2 again

#### Scenario: Another write failure
- **WHEN** the write of item 2 fails with another `GitHubOperationError`
- **THEN** the round raises `RoadmapRefineError` that names item 2

### Requirement: A skipped item writes no result line
A refine round SHALL write no `roadmap job result` line for an item that changed since the read, as an alternatives check whose body changed writes none, and SHALL NOT count the item as written or as failed.

#### Scenario: The store refuses the write of a changed item
- **WHEN** the store refuses the write of item 2 with `RoadmapItemChangedError`
- **THEN** the round logs no result line for item 2

#### Scenario: The body of an item changes during the round
- **WHEN** a person edits the body of item 2 while the model works on it
- **THEN** item 2 stays New, the round logs no result line for item 2, and the round ends with `written=2`

#### Scenario: A write that fails for another reason
- **WHEN** the write of item 2 fails with another `GitHubOperationError`
- **THEN** the result line of item 2 holds `result=error` and `success=false`
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Tasks

## 1. The skip of a changed item (behavior)

- [x] 1.1 Write failing tests: a write that the change of the item refuses gives no result line and no `RoadmapRefineError`; another failure of the write still raises and logs `error`; a person who moves the item during the round gets no write, one INFO line and a new read in the next round; a body edit during the round logs no result line and counts the item as not written
- Verification: `$ uv run devops ci test tests/roadmap/refine/test_roadmap_refine_round.py`
- [x] 1.2 Catch `RoadmapItemChangedError` in `RefineWriter.settle`, give `RefineApplied` the count `changed_count`, return it from the body check of `_apply_refined`, and write no result line for a changed item
- Verification: `$ uv run devops ci test tests/roadmap/refine/test_roadmap_refine_round.py tests/roadmap/refine/test_roadmap_refine_one_write.py`

## 2. Documents

- [x] 2.1 Say in `docs/roadmap/job-success.md` that a changed refine item writes no line, and in `docs/ROADMAP_WORKFLOW.md` that refine skips it
- Verification: `$ uv run devops ci docs`
26 changes: 26 additions & 0 deletions openspec/specs/roadmap-refine/writes/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,29 @@ A round whose model call worked SHALL clear `refine.failed_at`, `refine.failed_s
#### Scenario: A form check fails after a timeout
- **WHEN** a round gets a proposal that fails a form check for an item whose record holds the three keys
- **THEN** the record holds `refine.tries` and none of the three keys

### Requirement: A refine round skips an item that changed since the read
A refine round in the Service SHALL NOT write the body, the marks or the Status of an item that a person or another job changed between the read and the write, and SHALL NOT fail for it. The next round SHALL read the item again. The change is a write that the store refuses with `RoadmapItemChangedError`, or a body outside the refine section that changed.

#### Scenario: The Status of an item changes during the round
- **WHEN** a person moves item 2 of 3 to Blocked while the model works on it
- **THEN** items 1 and 3 are written, item 2 gets no write and one INFO line, the round ends with `taken=3`, `written=2` and `failed=0` and raises no error, and the next round takes item 2 again

#### Scenario: Another write failure
- **WHEN** the write of item 2 fails with another `GitHubOperationError`
- **THEN** the round raises `RoadmapRefineError` that names item 2

### Requirement: A skipped item writes no result line
A refine round SHALL write no `roadmap job result` line for an item that changed since the read, as an alternatives check whose body changed writes none, and SHALL NOT count the item as written or as failed.

#### Scenario: The store refuses the write of a changed item
- **WHEN** the store refuses the write of item 2 with `RoadmapItemChangedError`
- **THEN** the round logs no result line for item 2

#### Scenario: The body of an item changes during the round
- **WHEN** a person edits the body of item 2 while the model works on it
- **THEN** item 2 stays New, the round logs no result line for item 2, and the round ends with `written=2`

#### Scenario: A write that fails for another reason
- **WHEN** the write of item 2 fails with another `GitHubOperationError`
- **THEN** the result line of item 2 holds `result=error` and `success=false`
5 changes: 5 additions & 0 deletions src/devops_cli/lang/en/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,11 @@ class RoadmapMessages:
refine_write_failed_warning: str = (
"Refine wrote nothing more for #{number} in {repo}: the write failed ({error})."
)
# An item that changed since the read, which the next round reads again (#5299).
refine_item_changed: str = (
"Refine did not write #{number} in {repo}: the item changed since the read. The next round "
"reads it again."
)
refine_write_failed: str = "refine could not write {count} item(s), and went on: {items}"
# `devops roadmap alternatives` (#2650).
alternatives_title: str = "# Alternatives check for {repo}"
Expand Down
Loading