From 02889683e7f071483166031b271568a7cc1ff703 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 22:56:32 +0000 Subject: [PATCH 1/2] fix(roadmap): skip a failed alternatives item, not the round A failed check of one item (a failed model call, a stopped run or a refused reply) is recorded in the item's job record with alternatives.failed_at and alternatives.failed_error. A written check clears both keys. The selection leaves out the item until roadmap.alternatives.retry_days (3 by default) have passed. The row and the command fail only when the run tried items and checked none. The reason of a stopped run holds the masked message of the stop. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PeiMDokwZ2G38Cktk2JiKu --- README.md | 2 +- docs/CLI_REFERENCE.md | 2 +- docs/CONFIGURATION.md | 2 +- docs/ERRORS.md | 2 +- docs/ROADMAP_WORKFLOW.md | 2 +- docs/commands/roadmap.md | 2 +- k8s/README.md | 2 +- src/devops_cli/config/constants.py | 3 + src/devops_cli/config/defaults.py | 1 + src/devops_cli/config/settings.py | 7 + src/devops_cli/exceptions/roadmap.py | 7 +- src/devops_cli/lang/en/help.py | 6 +- src/devops_cli/lang/en/messages.py | 4 +- src/devops_cli/roadmap/alternatives.py | 88 ++++-- src/devops_cli/roadmap/run.py | 6 +- src/devops_cli/roadmap/store.py | 5 +- tests/roadmap/test_roadmap_alternatives.py | 330 +++++++++++++++++++-- 17 files changed, 409 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index b6b168c74c..f057e17762 100644 --- a/README.md +++ b/README.md @@ -375,7 +375,7 @@ and excessive permissions fail it, and every other finding is shown. | | [**roadmap**](docs/commands/roadmap.md) | `devops roadmap intake [OPTIONS]` | Turn candidates into items: every open issue with no priority/* label. The model compares each with the items and the issues closed as not planned, but not with an issue that has sub-issues, because its sub-issues deliver it. It names a possible duplicate for a person to close: intake never closes an issue and never drops a candidate. Each gets a type label and a scope label from the Conventional Commit title, a status/new label, Value and Effort labels and a reason comment, then its priority label last, and goes to the backlog. The model picks the type only for a title with no Conventional Commit type. A label a person set stays. Intake sets no milestone: a person plans the milestones, and a milestone an issue has stays. Close an issue as not planned to keep it off the roadmap: devops gh issues close \ --reason not-planned. A candidate an agent files with --title and --body-file is labeled source/agent, and intake files it, a possible duplicate too, unless a run that stopped after filing left an open issue with its title and body, which intake then places; a text that looks like it holds a secret is refused. --dry-run makes no request and prints the requests a run makes; --plan, the default, reads GitHub and calls the model, writes nothing and reports what it spent; --confirm makes the writes. | | | `devops roadmap intake-eval [OPTIONS]` | Run the intake duplicate evaluation set against the configured analysis model and print the score of each case. For each case intake plans the candidate in a roadmap that holds the case's item and nothing else, and writes nothing. The run makes one analysis call for each case, one at a time, and no embedding or GitHub request; it reads the type labels from .github/labels.yml of this checkout. It prints whether intake agrees with the person's verdict for each case, and the precision and the recall of the duplicate verdict. It exits 0 when every case ran, and 1 when a case could not run. | | | `devops roadmap refine [OPTIONS]` | Refine roadmap items to Ready with proposed design, tasks, and acceptance criteria, using code and documentation. When a fact or a decision has no verified source, or a key question of the body has no answer, refine investigates it with tools that read the code and, for a public repository with a Firecrawl key, search the web. A design question gets the best-practice option with the options it compared, and only a decision that a person must make waits on a person. The plan says when web search is off. Without --item, refine takes items nearest place first: each open milestone's New items, by due date and then by number, then the backlog's P0 and P1 items, then the backlog's other New items, each place by priority. Only --limit stops a run. The number of Ready items does not stop it. In each open milestone and among the backlog's P0 and P1 items it also takes Ready items it has no record of, and sets one back to New when it finds it not ready. An item that an account other than the owner, a member or a collaborator opened waits on a person, and only --item refines it. An item on which refine wrote 2 comments in the last 24 hours also waits on a person and takes no place under --limit, and only --item refines it until the older comment is 24 hours old. An item refine cannot set to Ready gets one comment with its next step. The step is the questions a person answers, the split a person makes, or the open items it waits on. Refine looks at the item again after a reply, a body edit or the close of those items, or after a commit on the default branch changes a file that the block cites. The report groups every item by its next step. An item whose model call fails is skipped and reported; the others are still refined, and refine then exits 1. | -| | `devops roadmap alternatives [OPTIONS]` | Check open items for an open, maintained tool or library that already covers their need, in whole or in part. For each item, one agent run searches the web with Firecrawl and reads the facts of each candidate from GitHub and PyPI: its license, its last activity and whether it is archived. The verdict is covers, partly, none or not-applicable. With --confirm, a check posts one comment, replaces the block `devops-roadmap-alternatives` in the item's body, and records the check in the job record. It changes no label and closes no issue. A person decides what a tool means for the item. The run takes open New and Ready items that a person with write access opened: first the items with no check, lowest number first, then the items whose check is older than roadmap.alternatives.recheck_days or whose text changed since. The check is off, and the plan says why, for a private repository or with no Firecrawl key. An item whose model call fails or whose reply cites a URL that no tool returned is skipped and reported; the others are written, and the command then exits 1. | +| | `devops roadmap alternatives [OPTIONS]` | Check open items for an open, maintained tool or library that already covers their need, in whole or in part. For each item, one agent run searches the web with Firecrawl and reads the facts of each candidate from GitHub and PyPI: its license, its last activity and whether it is archived. The verdict is covers, partly, none or not-applicable. With --confirm, a check posts one comment, replaces the block `devops-roadmap-alternatives` in the item's body, and records the check in the job record. It changes no label and closes no issue. A person decides what a tool means for the item. The run takes open New and Ready items that a person with write access opened: first the items with no check, lowest number first, then the items whose check is older than roadmap.alternatives.recheck_days or whose text changed since. The check is off, and the plan says why, for a private repository or with no Firecrawl key. An item whose model call fails, whose run stops or whose reply the job refuses is skipped, reported and recorded in its job record, and the others are written. The run takes that item again after roadmap.alternatives.retry_days. The command exits 1 only when it tried items and checked none. | | | `devops roadmap stage [OPTIONS]` | Make Ready items Staged: for each item that a label filter names, make the branch \/\-\ at the fetched default branch, write the OpenSpec change of the item in task groups that each fit the step budget, make one commit as the identity of the session, push it, and open a draft pull request whose title is `docs(openspec): plan # ` and whose body starts with `Plans #` and holds no closing keyword. The branch keeps the type of the issue. The Status of the item stays Ready, and the job does not mark the pull request ready: the Service does, in its row stage_ready, when all checks of the draft have passed. One comment on the issue names the branch, the pull request and the task groups with their measures. The default filter is status=ready: the job takes the Ready items of any type, priority and effort, the highest priority first. The job leaves out an item that is not Ready, an item with the label needs-split, an item that an account without write access opened, an item that depends on an open issue, an item that a pushed branch or a worktree holds, an item whose plan is on the default branch or whose change is archived there, and an item whose text looks like a secret; the plan says why. A task group over the budget goes back to the model once, and a group still over it stops the item. An item whose model call fails is skipped and reported, the others are still staged, and the command then exits 1. Each run also removes the draft and the branch of a closed item when only the identity of the session wrote to them. | | | `devops roadmap run [OPTIONS]` | Run the roadmap jobs that are due, in order: metrics, then intake, refine and the alternatives check, and record each one's last success. Intake is due on an issue reopened, and decides at most 5 candidates a run and keeps a record of those it left beside the schedule; refine is due every 31 minutes, on a first run, and after an intake that placed a critical fix or a P0 item; the alternatives check is due every 719 minutes and on a first run, and checks at most roadmap.alternatives.limit items. Without --confirm, or with --dry-run, prints the due list and runs nothing. | | | `devops roadmap implement [OPTIONS]` | Implement a Staged item, in bounded steps. With --group it runs one task group of the change of an item in the checkout --source: the agent is pydantic-ai's Coder on the model of ai.tasks.implement. Its inputs are the AGENTS.md of the checkout, the sections of the documents that it routes the group to (a test file brings docs/TESTING.md), the item's title, problem and acceptance criteria, the change's proposal, design and tasks, the group, and the files the group names. The command refuses to start when they do not fit the window of the task, or when the checkout has uncommitted changes. The shell of the agent runs only git, uv, ruff and mypy, with a scratch home. When the agent returns, the command runs the verification commands of the group, ruff on the changed Python files, and mypy on the changed files that the type check of devops ci covers (the files under src, with its options), and checks that the agent made no commit, removed or renamed no test that existed at the start of the step, and ticked every task of the group. Before these checks it deletes each new file that git does not ignore, that the group does not name, and that is outside src, tests, docs and openspec, and lists the files in the report. The command writes the tasks file back to its text before the run and keeps only the ticks of the group, so no edit of that file stops the step. An agent that forgets a tick gets one more turn that asks only for the ticks, and that may change only the tasks file. When every check passes, it commits the checkout as ' (#\)'. Otherwise it resets the checkout to the commit where the step started, reports the step as stopped with the reason and the masked diff of the work it discarded, and exits 1. It writes nothing to GitHub. Without --group it is the job. It takes each Staged or Planned item that a label filter names (default: status=ready, status=planned, effort=low). A Staged item has its staged branch and draft on origin. A Planned item has its change folder on the default branch and no branch: the job makes the branch \/\-\ there, with the slug of the folder, and opens the draft when the branch first holds a commit. The job rebases the branch, runs a step for each task group that has an unticked task, regenerates the documentation, archives the change, pushes, sets the title and the body of the pull request (the title of the issue, and a body that closes it), watches the checks, runs one fix step for a failed check, and marks the pull request ready. A step that fails stops the item: the job comments why and shows the masked diff of the discarded work, sets the Status to Blocked, and the Service runs the item again only after a comment 'implement: retry' or one time for each new runner image. The job leaves out an item that an agent or a person claimed with a label owner/agent or owner/human. When one claims an item that a running job works on, the job ends it at the next group boundary, with no push and no pull request. The job never merges. --confirm runs steps only when the setting roadmap.implement.in_runner is true, which only the pod of a runner Job sets: the shell of the agent is no security boundary. On a workstation, --item \ --confirm starts that runner Job for the item, with the code of devops k8s run-job --template runner, and follows its log (--no-wait prints the Job's name). It refuses an item that an agent or a person claimed, an item that is neither Ready nor Planned, and a repository that has a runner Job that has not ended. --dry-run --item \ prints the Job and makes no request. | diff --git a/docs/CLI_REFERENCE.md b/docs/CLI_REFERENCE.md index 92e089bc21..643da5c811 100644 --- a/docs/CLI_REFERENCE.md +++ b/docs/CLI_REFERENCE.md @@ -6542,7 +6542,7 @@ devops roadmap refine [OPTIONS] ### `devops roadmap alternatives` -**Check open items for an open, maintained tool or library that already covers their need, in whole or in part. For each item, one agent run searches the web with Firecrawl and reads the facts of each candidate from GitHub and PyPI: its license, its last activity and whether it is archived. The verdict is covers, partly, none or not-applicable. With --confirm, a check posts one comment, replaces the block `devops-roadmap-alternatives` in the item's body, and records the check in the job record. It changes no label and closes no issue. A person decides what a tool means for the item. The run takes open New and Ready items that a person with write access opened: first the items with no check, lowest number first, then the items whose check is older than roadmap.alternatives.recheck_days or whose text changed since. The check is off, and the plan says why, for a private repository or with no Firecrawl key. An item whose model call fails or whose reply cites a URL that no tool returned is skipped and reported; the others are written, and the command then exits 1.** +**Check open items for an open, maintained tool or library that already covers their need, in whole or in part. For each item, one agent run searches the web with Firecrawl and reads the facts of each candidate from GitHub and PyPI: its license, its last activity and whether it is archived. The verdict is covers, partly, none or not-applicable. With --confirm, a check posts one comment, replaces the block `devops-roadmap-alternatives` in the item's body, and records the check in the job record. It changes no label and closes no issue. A person decides what a tool means for the item. The run takes open New and Ready items that a person with write access opened: first the items with no check, lowest number first, then the items whose check is older than roadmap.alternatives.recheck_days or whose text changed since. The check is off, and the plan says why, for a private repository or with no Firecrawl key. An item whose model call fails, whose run stops or whose reply the job refuses is skipped, reported and recorded in its job record, and the others are written. The run takes that item again after roadmap.alternatives.retry_days. The command exits 1 only when it tried items and checked none.** ```bash devops roadmap alternatives [OPTIONS] diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 299670ab18..1599aedeaa 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -268,7 +268,7 @@ roadmap configuration settings. | Option | Type | Default | Environment Variable | Description | |---|---|---|---|---| -| `alternatives` | `AlternativesConfig` | `limit=5 recheck_days=30` | - | - | +| `alternatives` | `AlternativesConfig` | `limit=5 recheck_days=30 retry_days=3` | - | - | | `stage` | `RoadmapStageConfig` | `filter=['status=ready'] limit=3 step_tokens=40000` | - | - | | `implement` | `RoadmapImplementConfig` | `in_runner=False` | - | - | diff --git a/docs/ERRORS.md b/docs/ERRORS.md index 5152c36057..2f90cc8b8f 100644 --- a/docs/ERRORS.md +++ b/docs/ERRORS.md @@ -92,7 +92,7 @@ Each exception class declares its `error_code` and `exit_code`. A command that a | `ReviewPoolError` | `REVIEW_POOL_ERROR` | `1` | Ai | Raised when an error occurs during parallel review worker pool execution. | | `ReviewSessionExistsError` | `REVIEW_SESSION_EXISTS` | `1` | Ai | Raised when a review is published under the name of a session that is already published. | | `ReviewStateError` | `REVIEW_STATE_ERROR` | `1` | Devops_cli.review.state | Exception raised for invalid review finding state or state transition. | -| `RoadmapAlternativesError` | `ROADMAP_ALTERNATIVES_FAILED` | `1` | Roadmap | Raised after an alternatives run in which the check of one or more items failed. | +| `RoadmapAlternativesError` | `ROADMAP_ALTERNATIVES_FAILED` | `1` | Roadmap | Raised after an alternatives run that tried items and checked none of them. | | `RoadmapClaimError` | `ROADMAP_ITEM_CLAIMED` | `1` | Roadmap | Raised when a claim of a roadmap Item is refused, because another owner holds it or | | `RoadmapImplementError` | `ROADMAP_IMPLEMENT_REFUSED` | `1` | Roadmap | Raised when `devops roadmap implement` refuses to start a step, or cannot read its inputs. | | `RoadmapIntakeError` | `ROADMAP_INTAKE_FAILED` | `1` | Roadmap | Raised after an intake round in which the writes failed for one or more candidates. | diff --git a/docs/ROADMAP_WORKFLOW.md b/docs/ROADMAP_WORKFLOW.md index a15dd952ed..35e1c8a56f 100644 --- a/docs/ROADMAP_WORKFLOW.md +++ b/docs/ROADMAP_WORKFLOW.md @@ -97,7 +97,7 @@ These are all the keys of the job record, by the job that writes them: | Refine | `refine.body_hash`, `refine.section_hash`, `refine.failed_body_hash` | The hashes of the issue body and of the refine section, to see a change of text | | Refine | `refine.needs_split`, `refine.next_step`, `refine.blocked_by`, `refine.block_paths` | Whether the Item needs a split, who acts next, and the open items and paths that block it | | Refine | `refine.capped_after`, `refine.alternatives_asked` | The comment cap of refine, and the covering tool that refine asked a person about | -| Alternatives | `alternatives.checked_at`, `alternatives.body_hash`, `alternatives.verdict`, `alternatives.tool` | When the check ran, the text it read, its verdict and the tool it found | +| Alternatives | `alternatives.checked_at`, `alternatives.body_hash`, `alternatives.verdict`, `alternatives.tool`, `alternatives.failed_at`, `alternatives.failed_error` | When the check ran, the text it read, its verdict and the tool it found; when the last check failed and the class of its error, until a check is written | | Stage | `stage.branch`, `stage.pr`, `stage.sha` | The staged branch, its draft pull request and its last commit | | Stage | `stage.groups`, `stage.needs_split`, `stage.file_cap` | The task groups with their size, the group over the budget, and the cap of that measure | | Stage | `stage.ready` | The plan pull request that the Service has seen leave the draft state | diff --git a/docs/commands/roadmap.md b/docs/commands/roadmap.md index 579f89077d..3bc2427d04 100644 --- a/docs/commands/roadmap.md +++ b/docs/commands/roadmap.md @@ -69,7 +69,7 @@ devops roadmap refine [OPTIONS] ## `devops roadmap alternatives` -**Check open items for an open, maintained tool or library that already covers their need, in whole or in part. For each item, one agent run searches the web with Firecrawl and reads the facts of each candidate from GitHub and PyPI: its license, its last activity and whether it is archived. The verdict is covers, partly, none or not-applicable. With --confirm, a check posts one comment, replaces the block `devops-roadmap-alternatives` in the item's body, and records the check in the job record. It changes no label and closes no issue. A person decides what a tool means for the item. The run takes open New and Ready items that a person with write access opened: first the items with no check, lowest number first, then the items whose check is older than roadmap.alternatives.recheck_days or whose text changed since. The check is off, and the plan says why, for a private repository or with no Firecrawl key. An item whose model call fails or whose reply cites a URL that no tool returned is skipped and reported; the others are written, and the command then exits 1.** +**Check open items for an open, maintained tool or library that already covers their need, in whole or in part. For each item, one agent run searches the web with Firecrawl and reads the facts of each candidate from GitHub and PyPI: its license, its last activity and whether it is archived. The verdict is covers, partly, none or not-applicable. With --confirm, a check posts one comment, replaces the block `devops-roadmap-alternatives` in the item's body, and records the check in the job record. It changes no label and closes no issue. A person decides what a tool means for the item. The run takes open New and Ready items that a person with write access opened: first the items with no check, lowest number first, then the items whose check is older than roadmap.alternatives.recheck_days or whose text changed since. The check is off, and the plan says why, for a private repository or with no Firecrawl key. An item whose model call fails, whose run stops or whose reply the job refuses is skipped, reported and recorded in its job record, and the others are written. The run takes that item again after roadmap.alternatives.retry_days. The command exits 1 only when it tried items and checked none.** ```bash devops roadmap alternatives [OPTIONS] diff --git a/k8s/README.md b/k8s/README.md index 803f65b158..6b81621756 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -607,7 +607,7 @@ kubectl -n devops logs -f job/ 11. The Service keeps three files in `/home/devops/.data/roadmap/` on volume `roadmap-service-home`, beside the `schedule.json` of each repository: `service-halt.json` (GitHub refused the identity), `service-budget.json` (the GitHub requests of the last hour) and `service-failures.json` (the jobs that failed rounds in a row). A restart reads them back, so a restart does not clear a halt, the budget or a suspended job. A round that ends because the Service is stopping, for example in a rollout, does not count as a failed round: the count of its job stays as it was. The log line that suspends a job names the class of the error of each of its failed rounds in a row; the file keeps only the count, so a round that an earlier process counted reads as `unknown`. A rate limit that one request gets stops the requests of all workers until its wait ends. When GitHub refuses the identity, for example because the App's installation is suspended, the Service halts and logs `GitHub refused the identity`. To clear the halt after you fix the cause, remove the file and restart the Service: `kubectl -n devops exec deploy/roadmap-service -- rm /home/devops/.data/roadmap/service-halt.json`, then `kubectl -n devops delete pod -l app.kubernetes.io/name=roadmap-service`. 12. The Service's `/metrics` shows the budget and the suspended jobs (#2475): `devops_cli_service_budget_limit_requests` (the hourly budget), `devops_cli_service_budget_spent_requests` (the GitHub requests of the last hour), `devops_cli_service_budget_holds_total` (one count each time a hold begins) and `devops_cli_service_job_suspended` (1 while a job of a repository, by `repo` and `row`, waits for new input after it failed 3 rounds in a row). Each GitHub request counts in `devops_cli_github_requests_total` under its `method`, the `repo` of the worker that sent it and the job `row` (`metrics`, `intake`, `refine`, `stage`, `implement`, `stage_ready` or `alternatives`); a request outside a worker or a row counts as `other`. To find what spent the budget, run `sum by (repo, row, method) (increase(devops_cli_github_requests_total{job="roadmap-service"}[1h]))` in Grafana Explore. A delivery of the App bot's own write counts as outcome `self` in `devops_cli_service_webhook_deliveries_total`. 13. A refine round writes at most 2 comments on one item in 24 hours. A round that finds 2 refine comments of the last 24 hours on an item leaves the item alone, with no model call and no comment. The item waits on a person and takes no place under the round's limit, so the round refines the next item. For each newest comment on the item that the cap leaves with no answer, the round records the time of that comment in the item's job record (`refine.capped_after`), logs `Refine left # alone and wrote no comment`, and adds 1 to `devops_cli_roadmap_refine_comments_capped_total`. A later round that finds no newer comment does not log or count the item again. A person refines the item at the cap with `devops roadmap refine --item --confirm`. Each Firecrawl search counts in `devops_cli_firecrawl_searches_total` by `result`: `ok`, the HTTP status of a refused search, or `error`. A failed search logs `A Firecrawl web search failed` with the status or the error class, and never the key or the query. -14. The row `alternatives` of the model lane runs after `refine`: on a first run, and 719 minutes after its last success. It runs `devops roadmap alternatives --confirm` for the repository. A round checks at most `roadmap.alternatives.limit` items (5 by default): first the items with no check, then the items whose check is older than `roadmap.alternatives.recheck_days` (30 by default) or whose text changed. A webhook makes the row due at no other time. The row changes no label and closes no issue. It does nothing, and logs `The alternatives check of is off`, for a private repository and when no Firecrawl key is set. If the check of an item fails, the row writes the other checks and fails, naming the item. Each written check adds 1 to `devops_cli_roadmap_alternatives_total` by `verdict`: `covers`, `partly`, `none` or `not-applicable`. A `covers` verdict makes refine ask a person to adopt the tool or to keep the item with a reason. The item waits on a person until a reply answers the question, and Ready items with a new covering tool go back to New. Refine records the tool it asked about in the job record (`refine.alternatives_asked`). `devops roadmap run --dry-run` lists the row when it is due. +14. The row `alternatives` of the model lane runs after `refine`: on a first run, and 719 minutes after its last success. It runs `devops roadmap alternatives --confirm` for the repository. A round checks at most `roadmap.alternatives.limit` items (5 by default): first the items with no check, then the items whose check is older than `roadmap.alternatives.recheck_days` (30 by default) or whose text changed. A webhook makes the row due at no other time. The row changes no label and closes no issue. It does nothing, and logs `The alternatives check of is off`, for a private repository and when no Firecrawl key is set. If the check of an item fails, the row records the failure in the item's job record (`alternatives.failed_at` and `alternatives.failed_error`, the class of the error), writes the other checks and succeeds. The row fails, and counts toward the suspension after 3 failed rounds, only when it tried items and checked none. A round takes a failed item again after `roadmap.alternatives.retry_days` (3 by default). Each written check adds 1 to `devops_cli_roadmap_alternatives_total` by `verdict`: `covers`, `partly`, `none` or `not-applicable`. A `covers` verdict makes refine ask a person to adopt the tool or to keep the item with a reason. The item waits on a person until a reply answers the question, and Ready items with a new covering tool go back to New. Refine records the tool it asked about in the job record (`refine.alternatives_asked`). `devops roadmap run --dry-run` lists the row when it is due. 15. The row `stage` follows `refine` on the model lane (#2659). It runs `devops roadmap stage --confirm` in the model clone: it is due every 37 minutes, on a first run, and in a round where `refine` set an item Ready. It stages the Ready items that `roadmap.stage.filter` names, at most `roadmap.stage.limit` in a round, and splits a task group over `roadmap.stage.step_tokens`. Each task group has a kind (#3005): a `behavior` group has a failing test, and an `other` group has no test but a command or the steps of a manual check that prove it. The job sends a reply that breaks this rule back to the model once. It leaves out an item whose change folder is on the default branch or in its archive (#2714): a round reads that tree once with `git ls-tree`, so a merged staging pull request never makes a second one. The pull request it opens is a draft with the title `docs(openspec): plan # `. The job does not mark it ready: the row `stage_ready` does (step 18). Before it opens one, it checks each path of the plan (`reads`, `changes`, the code spans of the tasks and `verify`) against the tracked files of the commit it plans, read with one `git ls-files` for the round (#3010). A path that is no file there, and that no group up to its own creates, goes back to the model once with the files of the same name. A second reply with a missing path stops the item, so no draft opens and the implement Job never meets a wrong path. `k8s/devops/configmap.example.yaml` holds the three settings, and `devops k8s deploy-stack --stack devops` applies them; each also has a variable, `DEVOPS_CLI_ROADMAP_STAGE_FILTER`, `DEVOPS_CLI_ROADMAP_STAGE_LIMIT` and `DEVOPS_CLI_ROADMAP_STAGE_STEP_TOKENS`. Each item of a round counts once in `devops_cli_roadmap_stage_total` by its `result`: `staged`, `skipped`, `needs_split` or `failed`. The image carries the pinned OpenSpec and a Node runtime, so the job validates each change before it pushes: `kubectl -n devops exec deploy/roadmap-service -- openspec --version` prints the locked version. 16. The row `implement` follows `metrics` on the status lane (#2667, #2757). It calls no model, so a model-lane round that has not ended never delays it. It is due every 7 minutes and on a first run, in the clone of the status lane. The Service runs no step: a round only talks to the Kubernetes API, in three moves. It reports each Job that ended, with a comment on the item that holds the state and the last 40 lines of the log of the Job's pod, masked of secrets, and records `implement.job_state` as `succeeded`, `failed` or `gone`. It waits while a Job of the repository has not ended. Else it makes one Job from CronJob `devops-cli-runner` for the first Staged or Planned item that the default filter names (a Planned item has its change folder on the default branch and no branch: a person merged the staging pull request, and the job makes the branch and the draft itself), with the args `roadmap implement --repo --item --confirm` and the item's number as the only item text, and records the name of the Job in `implement.job`, and the digest of the runner image that the CronJob template names in `implement.job_digest`. The same write sets the label `owner/service` on the item (#2910), and the report of the Job removes it. The comment that reports the Job names the digest. The Service makes no Job for an item that an agent or a person claimed, and a claim of an agent or a person ends a running Job at its next group boundary, with no push and no pull request. A round also sets the Status label of the items from their record (`status_sync.py`): it reads the plans on the default branch once for the sweep and for the plan, writes `status/planned` once a plan is merged, and writes `status/in-progress` as soon as the record names a Job, and again after it makes one. It writes only an open item that holds Ready or Planned with the label that a job last recorded, so a label that a person set stays. The rows `stage` and `stage_ready` use the same function. The Jobs of a repository carry the label `implement-repo`, whose value is a digest of the repository name, so the API is the lock and a restart of the Service loses nothing. A Job that leaves its item In Progress, or Ready or Planned with no stop, is a stop that the runner could not write, such as a pod that the kernel killed for its memory, unless an agent or a person claimed the item. The round then sets the item Blocked (`status/blocked`) and records `implement.stopped` as `job`, so that no Job is made for it again. A stop that the runner writes sets Blocked in the same way, with the step in `implement.stopped`. After the report, the round clears the stop of each item that it set Blocked, by one of two rules, and a comment names the rule that ran. Rule `retry`: a comment `implement: retry`, made after the report by the owner, a member or a collaborator, clears the stop at once, whatever the image. Rule `digest`: the digest in the template of CronJob `devops-cli-runner` is not `implement.job_digest`, so a new runner image has rolled out since the stop, and the round clears the stop one time. A clear sets Ready or Planned and removes `implement.stopped`, and the same round can make a Job for the item. The new Job overwrites `implement.job_digest`, so a second stop on the same image waits for a retry, and the round makes no Job in a loop. A stop with no digest on record is cleared by a retry only. A Blocked stop that no rule clears costs one request in each round, the listing of its comments (6 an hour of `service.github_requests_per_hour`); the round reads the issue again only when a rule holds, and reads the template at most one time. The round clears no item that a Job holds, that an agent or a person claimed, or that a person labeled Blocked by hand. The failures ledger is unchanged: three failed rounds on the same input still suspend the row. If CronJob `devops-cli-runner` does not exist, the round fails with a message that names it: run `devops k8s deploy-stack --stack devops`, or wait for Argo CD. A Job that cannot pull its image (the package `runner` is not public, or no release published it) ends by its deadline after two hours, and the next round records the stop. Read the Jobs with `kubectl -n devops get jobs -l implement-repo`. 17. Each repository has three lanes, and each lane runs one round at a time in its own clone (#1532, #1534). The status lane runs the rows `metrics`, `implement` and `stage_ready` in the clone `clone`. The triage lane runs the row `intake` on the `devops-triage` model in the clone `triage-clone`. The model lane runs the rows `refine`, `stage` and `alternatives` on `devops-background` in the clone `model-clone`. A poll and a webhook go to all three lanes. The lanes share the file `schedule.json` of the repository, the ledger `service-failures.json` and the lock that each write of an item's job record takes (#2757). When intake places a critical fix or P0 item, it writes a `refine_due` timestamp to `schedule.json` so refinement becomes due in the next model-lane round. The label `lane` of `devops_cli_service_jobs_total`, `devops_cli_service_job_seconds_total` and `devops_cli_service_queue_depth` is `status`, `triage` or `model`. The label `row` of `devops_cli_github_requests_total` and `devops_cli_service_job_suspended` is the name of the row. A model-lane round that has not ended does not delay a status-lane or triage-lane round. diff --git a/src/devops_cli/config/constants.py b/src/devops_cli/config/constants.py index 3258d3c9ad..3161e6af05 100644 --- a/src/devops_cli/config/constants.py +++ b/src/devops_cli/config/constants.py @@ -2981,6 +2981,9 @@ class WebhookExposure(StrEnum): CONST_ROADMAP_ALTERNATIVES_CLASSIFIER_SEPARATOR: Final[str] = " :: " # The longest body, in tokens, that reaches the model with an item. CONST_ROADMAP_ALTERNATIVES_MAX_BODY_TOKENS: Final[int] = 4096 +# The class of error that the job records for a reply it refused (#2949): a refusal raises no +# exception, so it has no class of its own. +CONST_ROADMAP_ALTERNATIVES_REFUSED_ERROR: Final[str] = "RefusedReply" # The budget of one step of `devops roadmap implement` (#2664): the model requests and tool calls # of its run, the characters of one tool result, and the tokens of the window that the inputs # leave to the turns of the run. The window is `ai.tasks.implement.context_window`. diff --git a/src/devops_cli/config/defaults.py b/src/devops_cli/config/defaults.py index 101400e725..7c576e7227 100644 --- a/src/devops_cli/config/defaults.py +++ b/src/devops_cli/config/defaults.py @@ -722,6 +722,7 @@ # check is old. The Service's row is due twice a day, about (#2652). DEFAULT_ROADMAP_ALTERNATIVES_LIMIT: int = 5 DEFAULT_ROADMAP_ALTERNATIVES_RECHECK_DAYS: int = 30 +DEFAULT_ROADMAP_ALTERNATIVES_RETRY_DAYS: int = 3 DEFAULT_ROADMAP_ALTERNATIVES_INTERVAL_MINUTES: int = 719 # The PyPI JSON API reads of a package (`{name}` is one URL path segment) and its timeout. DEFAULT_PYPI_PACKAGE_URL: str = "https://pypi.org/pypi/{name}/json" diff --git a/src/devops_cli/config/settings.py b/src/devops_cli/config/settings.py index 2cd9681da9..049df986f6 100644 --- a/src/devops_cli/config/settings.py +++ b/src/devops_cli/config/settings.py @@ -89,6 +89,7 @@ DEFAULT_REVIEWS_DATA_DIR, DEFAULT_ROADMAP_ALTERNATIVES_LIMIT, DEFAULT_ROADMAP_ALTERNATIVES_RECHECK_DAYS, + DEFAULT_ROADMAP_ALTERNATIVES_RETRY_DAYS, DEFAULT_ROADMAP_STAGE_FILTER, DEFAULT_ROADMAP_STAGE_LIMIT, DEFAULT_ROADMAP_STAGE_STEP_TOKENS, @@ -953,6 +954,12 @@ class AlternativesConfig(BaseModel): ge=1, ) + retry_days: int = Field( + description="Days after a failed check of an item before the alternatives check takes the item again", + default=DEFAULT_ROADMAP_ALTERNATIVES_RETRY_DAYS, + ge=1, + ) + class RoadmapConfig(BaseModel): model_config = ConfigDict(extra="ignore", validate_assignment=True, hide_input_in_errors=True) diff --git a/src/devops_cli/exceptions/roadmap.py b/src/devops_cli/exceptions/roadmap.py index c883a3a556..ee095b038f 100644 --- a/src/devops_cli/exceptions/roadmap.py +++ b/src/devops_cli/exceptions/roadmap.py @@ -140,10 +140,11 @@ def __init__( class RoadmapAlternativesError(DevOpsCLIError): - """Raised after an alternatives run in which the check of one or more items failed. + """Raised after an alternatives run that tried items and checked none of them. - The job skipped each such item and wrote the others first (#2650). The message names each - skipped item with its reason, never the model's text. + The job recorded each failure in the job record of its item first (#2949). A run that checks + at least one item does not raise. The message names each skipped item with its reason, never + the model's text. """ error_code = "ROADMAP_ALTERNATIVES_FAILED" diff --git a/src/devops_cli/lang/en/help.py b/src/devops_cli/lang/en/help.py index a188752182..7334934bd8 100644 --- a/src/devops_cli/lang/en/help.py +++ b/src/devops_cli/lang/en/help.py @@ -1323,8 +1323,10 @@ class RoadmapCommandHelp: "opened: first the items with no check, lowest number first, then the items whose check " "is older than roadmap.alternatives.recheck_days or whose text changed since. " "The check is off, and the plan says why, for a private repository or with no Firecrawl " - "key. An item whose model call fails or whose reply cites a URL that no tool returned " - "is skipped and reported; the others are written, and the command then exits 1." + "key. An item whose model call fails, whose run stops or whose reply the job refuses is " + "skipped, reported and recorded in its job record, and the others are written. The run " + "takes that item again after roadmap.alternatives.retry_days. The command exits 1 only " + "when it tried items and checked none." ) alternatives_item: str = ( "Specific issue number to check instead of selecting. Alternatives checks it when it " diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index a7bd42d18d..18354953bb 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -1999,10 +1999,12 @@ class RoadmapMessages: alternatives_skipped_line: str = "- #{number} {title}: skipped, {reason}" alternatives_applied: str = "Checked {count} item(s) for open alternatives." alternatives_failed: str = ( - "the check failed for {count} item(s), and the others were written: {items}" + "the check failed for each of the {count} item(s) it tried, and no check was written: " + "{items}" ) alternatives_failed_item: str = "#{number} ({reason})" alternatives_reason_stopped: str = "the model's run stopped ({reason})" + alternatives_reason_stopped_message: str = "the model's run stopped ({reason}: {message})" alternatives_reason_error: str = "the model call failed ({error})" alternatives_reason_url: str = "the reply cites a URL that no tool returned: {url}" alternatives_reason_no_facts: str = "the reply names a tool whose facts no tool read: {url}" diff --git a/src/devops_cli/roadmap/alternatives.py b/src/devops_cli/roadmap/alternatives.py index 5382273749..0caeb616aa 100644 --- a/src/devops_cli/roadmap/alternatives.py +++ b/src/devops_cli/roadmap/alternatives.py @@ -4,20 +4,24 @@ **Selection.** An open Item with Status New or Ready, whose author has write access, is taken. Items with no check come first, lowest number first, then items whose last check is older than `roadmap.alternatives.recheck_days` or whose text changed since, oldest check first. `--limit` -caps a run. `--item` checks the one item it names whenever it is open. +caps a run. An item whose last check failed less than `roadmap.alternatives.retry_days` ago is +left out. `--item` checks the one item it names whenever it is open. **The run.** `investigate` of refine's investigation runs the agent with three tools: a Firecrawl web search, a GitHub repository read and a PyPI package read. The tools are the only sources. They keep the URLs they returned, the facts they read and the searches they ran, and the job writes those into the record: the model writes only the verdict, the URL of the tool, and what it covers and lacks. The job refuses a reply that cites a URL no tool returned, and sets `maintained` from -the facts. A model call that fails skips its item; the others are written, and the run then fails -naming each skipped item. Rejected credentials stop the run at the first item. +the facts. A failed model call, a stopped run or a refused reply skips its item, and the others are +written. The run fails, naming each skipped item, only when it tried items and checked none. +Rejected credentials stop the run at the first item. **Writes.** With `--confirm` a check replaces the job's block in the body, records `alternatives.*` in the job record, and posts one comment that carries `CONST_ROADMAP_ALTERNATIVES_COMMENT_MARKER`. It changes no label and closes no issue. A comment -after the job's last one reaches the next check as a reply. +after the job's last one reaches the next check as a reply. A skipped item gets only +`alternatives.failed_at` and `alternatives.failed_error` in its job record; a written check +clears both. The check is off when the repository is private, its visibility cannot be read, or no Firecrawl key is set: a verdict `none` would then say that no tool exists when none was looked for. @@ -51,6 +55,7 @@ CONST_ROADMAP_ALTERNATIVES_MAX_FACT_READS, CONST_ROADMAP_ALTERNATIVES_MAX_LICENSE_CHARS, CONST_ROADMAP_ALTERNATIVES_MAX_SEARCHES, + CONST_ROADMAP_ALTERNATIVES_REFUSED_ERROR, CONST_ROADMAP_ALTERNATIVES_SEARCH_RESULTS, CONST_ROADMAP_ALTERNATIVES_START_MARKER, CONST_ROADMAP_REFINE_MAX_REPLIES, @@ -387,10 +392,12 @@ class Check: @dataclass(frozen=True) class CheckFailure: """An item the job skipped, and why: a failed model call, a run that ended with no reply, or a - reply the job refused.""" + reply the job refused. `error_class` and `failed_at` go to the item's job record.""" item: Item reason: str + error_class: str + failed_at: datetime @dataclass(frozen=True) @@ -416,8 +423,8 @@ class AlternativesPlan: @property def has_writes(self) -> bool: - """Whether a run with `--confirm` writes anything.""" - return bool(self.checks) or bool(self.write_requests) + """Whether a run with `--confirm` writes anything: a check, or the record of a failure.""" + return bool(self.checks) or bool(self.failures) or bool(self.write_requests) def body_hash_of(body: str) -> str: @@ -429,21 +436,33 @@ def body_hash_of(body: str) -> str: return hash_text(extract_section_and_outside(outside)[0]) -def _checked_at(item: Item) -> datetime | None: - """When the job's last check of `item` ran, or None when it recorded none or the record is - not a time.""" - recorded = item.job_record.get(AlternativesRecordKey.CHECKED_AT) +def _recorded_time(item: Item, key: AlternativesRecordKey, name: str) -> datetime | None: + """The time that the job record of `item` holds at `key`, or None when it holds none or the + value is not a time.""" + recorded = item.job_record.get(key) if not recorded: return None try: return datetime.fromisoformat(recorded) except ValueError: logger.warning( - "The check time recorded on #%d is not a time; the item is checked.", item.number + "The %s time recorded on #%d is not a time; the item is checked.", name, item.number ) return None +def _checked_at(item: Item) -> datetime | None: + """When the job's last check of `item` ran, or None when it recorded none or the record is + not a time.""" + return _recorded_time(item, AlternativesRecordKey.CHECKED_AT, "check") + + +def _in_retry_delay(item: Item, retry_days: int, now: datetime) -> bool: + """Whether the last check of `item` failed less than `retry_days` days before `now`.""" + failed_at = _recorded_time(item, AlternativesRecordKey.FAILED_AT, "failure") + return failed_at is not None and now - failed_at < timedelta(days=retry_days) + + def _is_eligible(item: Item) -> bool: return ( item.state is GitHubState.OPEN @@ -464,10 +483,12 @@ def select_items( item_number: int | None, limit: int, recheck_days: int, + retry_days: int, now: datetime, ) -> Selection: """Up to `limit` items to check, in the order the module's docstring gives, and the eligible - items whose check is current. `item_number` names the one open item to check.""" + items whose check is current. An item whose check failed less than `retry_days` days ago is in + neither list. `item_number` names the one open item to check, whatever its failure.""" if item_number is not None: item = store.item(item_number) return Selection([item] if item and item.state is GitHubState.OPEN else [], []) @@ -475,6 +496,8 @@ def select_items( due: list[tuple[datetime, Item]] = [] current: list[Item] = [] for item in filter(_is_eligible, store.items()): + if _in_retry_delay(item, retry_days, now): + continue checked_at = _checked_at(item) if checked_at is None: unchecked.append(item) @@ -652,7 +675,7 @@ def validate_reply( """The check that `reply` makes, or the failure when the job refuses it.""" refusal = _refusal(reply, tools) or _marker_problem(item.body) if refusal is not None: - return CheckFailure(item, refusal) + return CheckFailure(item, refusal, CONST_ROADMAP_ALTERNATIVES_REFUSED_ERROR, now) allowed = tools.allowed_urls partial = Check( item=item, @@ -674,6 +697,17 @@ def validate_reply( ) +def _stopped_reason(stopped: InvestigationStopped) -> str: + """The reason of a run that stopped: the class of the error and, when it has one, its masked + message (#2562, #2922).""" + texts = MESSAGES.roadmap + if not stopped.message: + return texts.alternatives_reason_stopped.format(reason=stopped.reason) + return texts.alternatives_reason_stopped_message.format( + reason=stopped.reason, message=stopped.message + ) + + def _check_one( store: RoadmapStore, item: Item, *, key: str, model: Any, now: datetime ) -> Check | CheckFailure: @@ -692,14 +726,15 @@ def _check_one( item.number, type(exc).__name__, ) - return CheckFailure(item, texts.alternatives_reason_error.format(error=type(exc).__name__)) + error = type(exc).__name__ + return CheckFailure(item, texts.alternatives_reason_error.format(error=error), error, now) if isinstance(reply, InvestigationStopped): logger.warning( "The alternatives check of #%d was skipped: its run stopped (%s).", item.number, reply.reason, ) - return CheckFailure(item, texts.alternatives_reason_stopped.format(reason=reply.reason)) + return CheckFailure(item, _stopped_reason(reply), reply.reason, now) return validate_reply(item, reply, tools, now) @@ -728,6 +763,7 @@ def plan_alternatives( item_number=item_number, limit=config.limit if limit is None else limit, recheck_days=config.recheck_days, + retry_days=config.retry_days, now=moment, ) if not selection.selected: @@ -757,7 +793,8 @@ def _unchanged_since_read(store: RoadmapStore, check: Check) -> bool: def apply_alternatives(store: RoadmapStore, plan: AlternativesPlan) -> int: """Writes each check: the body block, the job record, then the comment, and counts it in - `devops_cli_roadmap_alternatives_total` by its verdict. Returns how many checks it wrote; a + `devops_cli_roadmap_alternatives_total` by its verdict. Then records each failure in the job + record of its item: the time and the class of the error. Returns how many checks it wrote; a check whose body a person changed since the read is left for the next run.""" written = 0 for check in plan.checks: @@ -772,18 +809,29 @@ def apply_alternatives(store: RoadmapStore, plan: AlternativesPlan) -> int: AlternativesRecordKey.BODY_HASH: check.body_hash, AlternativesRecordKey.VERDICT: check.verdict.value, AlternativesRecordKey.TOOL: check.tool.url if check.tool else None, + AlternativesRecordKey.FAILED_AT: None, + AlternativesRecordKey.FAILED_ERROR: None, }, ) store.comment(number, check.comment) emit(ROADMAP_ALTERNATIVES_TOTAL, 1, {"verdict": check.verdict.value}) written += 1 + for failure in plan.failures: + store.set_marks( + failure.item, + { + AlternativesRecordKey.FAILED_AT: failure.failed_at.isoformat(), + AlternativesRecordKey.FAILED_ERROR: failure.error_class, + }, + ) return written def raise_for_failed_checks(plan: AlternativesPlan) -> None: - """Fail a run in which the check of any item failed, once the others are written. The error - names each skipped item with its reason, and holds no text of the model.""" - if not plan.failures: + """Fail a run that tried items and checked none, once the failures are recorded (#2949). A run + that checked at least one item, or tried none, does not fail. The error names each skipped item + with its reason, and holds no text of the model.""" + if plan.checks or not plan.failures: return texts = MESSAGES.roadmap items = ", ".join( diff --git a/src/devops_cli/roadmap/run.py b/src/devops_cli/roadmap/run.py index bcf0d533b2..c3d6e7e43c 100644 --- a/src/devops_cli/roadmap/run.py +++ b/src/devops_cli/roadmap/run.py @@ -597,9 +597,9 @@ def _run_stage_ready_adapter(store: RoadmapStore, repo: str = "", **_: Any) -> J def _run_alternatives_adapter(store: RoadmapStore, repo: str = "", **_: Any) -> JobOutcome: """Check at most `roadmap.alternatives.limit` open items for an open tool that covers them - (#2652). The check writes the others when one fails, and then the job fails naming it. A - repository the check is off for, such as a private one, costs a visibility read and nothing - else.""" + (#2652). A failed check is recorded in its item's job record and the others are written; the + job fails, naming the items, only when it tried items and checked none (#2949). A repository + the check is off for, such as a private one, costs a visibility read and nothing else.""" plan = plan_alternatives(store, repo=repo, limit=load_settings().roadmap.alternatives.limit) if plan.off_reason: logger.info("The alternatives check of %s is off: %s", repo, plan.off_reason) diff --git a/src/devops_cli/roadmap/store.py b/src/devops_cli/roadmap/store.py index 70ac25b921..a43b7576e0 100644 --- a/src/devops_cli/roadmap/store.py +++ b/src/devops_cli/roadmap/store.py @@ -165,12 +165,15 @@ class Verdict(StrEnum): class AlternativesRecordKey(StrEnum): """What `devops roadmap alternatives` records in an Item's job record (#2650): when the check ran, the hash of the body it read outside its own block and the refine section, its verdict, - and the URL of the tool it found, if any.""" + and the URL of the tool it found, if any. When the last check failed, the record holds the + time of the failure and the class of its error (#2949) until a check is written.""" CHECKED_AT = "alternatives.checked_at" BODY_HASH = "alternatives.body_hash" VERDICT = "alternatives.verdict" TOOL = "alternatives.tool" + FAILED_AT = "alternatives.failed_at" + FAILED_ERROR = "alternatives.failed_error" class StageRecordKey(StrEnum): diff --git a/tests/roadmap/test_roadmap_alternatives.py b/tests/roadmap/test_roadmap_alternatives.py index 1fb6146578..555e0f56dc 100644 --- a/tests/roadmap/test_roadmap_alternatives.py +++ b/tests/roadmap/test_roadmap_alternatives.py @@ -136,6 +136,35 @@ def _mark_checked( ) +def _mark_failed( + store: InMemoryRoadmapStore, number: int, *, days: int, error: str = "AIClientError" +) -> None: + """Record a failed check of item `number` made `days` days before `NOW`.""" + item = store.item(number) + assert item is not None + store.set_marks( + item, + { + AlternativesRecordKey.FAILED_AT: _days_ago(days).isoformat(), + AlternativesRecordKey.FAILED_ERROR: error, + }, + ) + + +def _recorded(store: RoadmapStore, number: int, key: AlternativesRecordKey) -> str | None: + item = store.item(number) + assert item is not None + return item.job_record.get(key) + + +def _failure_record(store: RoadmapStore, number: int) -> tuple[str | None, str | None]: + """The time and the class of the error of the last failed check of item `number`.""" + return ( + _recorded(store, number, AlternativesRecordKey.FAILED_AT), + _recorded(store, number, AlternativesRecordKey.FAILED_ERROR), + ) + + def _covers(**changes: Any) -> AlternativesReply: reply = AlternativesReply( verdict=Verdict.COVERS, @@ -203,7 +232,9 @@ def test_unchecked_items_come_before_stale_items_and_the_limit_caps_the_run( _mark_checked(store, stale, days=40) _mark_checked(store, fresh, days=2) - selection = select_items(store, item_number=None, limit=3, recheck_days=30, now=NOW) + selection = select_items( + store, item_number=None, limit=3, recheck_days=30, retry_days=3, now=NOW + ) assert ( [item.number for item in selection.selected], @@ -217,7 +248,9 @@ def test_stale_items_are_taken_oldest_check_first(store: InMemoryRoadmapStore) - _mark_checked(store, newer, days=35) _mark_checked(store, older, days=90) - selection = select_items(store, item_number=None, limit=5, recheck_days=30, now=NOW) + selection = select_items( + store, item_number=None, limit=5, recheck_days=30, retry_days=3, now=NOW + ) assert [item.number for item in selection.selected] == [older, newer] @@ -232,7 +265,9 @@ def test_an_item_whose_text_changed_is_checked_again_and_the_jobs_own_text_chang marked = f"{CONST_ROADMAP_ALTERNATIVES_START_MARKER}\nVerdict: none.\n{CONST_ROADMAP_ALTERNATIVES_END_MARKER}" store.write_issue_body(own, f"The same text.\n\n{marked}") - selection = select_items(store, item_number=None, limit=5, recheck_days=30, now=NOW) + selection = select_items( + store, item_number=None, limit=5, recheck_days=30, retry_days=3, now=NOW + ) assert ( [item.number for item in selection.selected], @@ -249,7 +284,9 @@ def test_started_blocked_closed_and_untrusted_items_are_left_out( store.close(_item(store, "Closed"), CloseReason.COMPLETED) ready = _item(store, "Ready", status="Ready") - selection = select_items(store, item_number=None, limit=9, recheck_days=30, now=NOW) + selection = select_items( + store, item_number=None, limit=9, recheck_days=30, retry_days=3, now=NOW + ) assert [item.number for item in selection.selected] == [ready] @@ -259,8 +296,10 @@ def test_an_item_that_is_named_is_checked_whoever_opened_it(store: InMemoryRoadm other = _item(store, "Other") _mark_checked(store, untrusted, days=2) - selection = select_items(store, item_number=untrusted, limit=1, recheck_days=30, now=NOW) - missing = select_items(store, item_number=99, limit=1, recheck_days=30, now=NOW) + selection = select_items( + store, item_number=untrusted, limit=1, recheck_days=30, retry_days=3, now=NOW + ) + missing = select_items(store, item_number=99, limit=1, recheck_days=30, retry_days=3, now=NOW) assert ( [item.number for item in selection.selected], @@ -273,7 +312,12 @@ def test_a_closed_item_that_is_named_is_not_checked(store: InMemoryRoadmapStore) number = _item(store) store.close(number, CloseReason.NOT_PLANNED) - assert select_items(store, item_number=number, limit=1, recheck_days=30, now=NOW).selected == [] + assert ( + select_items( + store, item_number=number, limit=1, recheck_days=30, retry_days=3, now=NOW + ).selected + == [] + ) def test_the_recheck_window_is_a_setting( @@ -293,6 +337,52 @@ def test_the_recheck_window_is_a_setting( ) == ([], [number]) +def test_retry_delay_an_item_whose_check_failed_lately_is_left_out_until_the_delay_ends( + store: InMemoryRoadmapStore, caplog: pytest.LogCaptureFixture +) -> None: + first = _item(store, "First unchecked") + lately = _item(store, "Failed lately") + long_ago = _item(store, "Failed long ago") + garbled = _item(store, "Garbled failure time") + _mark_failed(store, lately, days=1) + _mark_failed(store, long_ago, days=4) + item = store.item(garbled) + assert item is not None + store.set_marks(item, {AlternativesRecordKey.FAILED_AT: "yesterday"}) + + with caplog.at_level(logging.WARNING, logger="devops_cli.roadmap.alternatives"): + selection = select_items( + store, item_number=None, limit=9, recheck_days=30, retry_days=3, now=NOW + ) + named = select_items(store, item_number=lately, limit=1, recheck_days=30, retry_days=3, now=NOW) + longer = select_items(store, item_number=None, limit=9, recheck_days=30, retry_days=7, now=NOW) + + assert ( + [i.number for i in selection.selected], + [i.number for i in selection.current], + [i.number for i in named.selected], + [i.number for i in longer.selected], + any(f"#{garbled} is not a time" in r.getMessage() for r in caplog.records), + ) == ([first, long_ago, garbled], [], [lately], [first, garbled], True) + + +def test_retry_delay_the_setting_defaults_to_three_and_is_at_least_one( + config: Callable[..., Any], +) -> None: + from pydantic import ValidationError + + from devops_cli.config.settings import AlternativesConfig, load_settings + + config() + with pytest.raises(ValidationError) as raised: + AlternativesConfig(retry_days=0) + assert [error["loc"] for error in raised.value.errors()] == [("retry_days",)] + assert (AlternativesConfig().retry_days, load_settings().roadmap.alternatives.retry_days) == ( + 3, + 3, + ) + + # ── The tools of the run ────────────────────────────────────────────────────── @@ -662,6 +752,8 @@ def test_a_covering_tool_makes_one_comment_one_block_and_the_record( { "alternatives.body_hash": body_hash_of("The job needs a scanner."), "alternatives.checked_at": NOW.isoformat(), + "alternatives.failed_at": None, + "alternatives.failed_error": None, "alternatives.tool": TOOL_URL, "alternatives.verdict": "covers", }, @@ -952,17 +1044,15 @@ def test_a_refused_reply_skips_its_item_and_the_others_are_written( plan = _plan(store, script) written = apply_alternatives(store, plan) + raise_for_failed_checks(plan) - with pytest.raises(RoadmapAlternativesError) as error: - raise_for_failed_checks(plan) assert ( [c.item.number for c in plan.checks], [(f.item.number, f.reason) for f in plan.failures], written, store.comments_on(refused), - error.value.failed_items, - f"#{refused} ({reason})" in str(error.value), - ) == ([kept], [(refused, reason)], 1, [], (refused,), True) + _failure_record(store, refused), + ) == ([kept], [(refused, reason)], 1, [], (NOW.isoformat(), "RefusedReply")) def test_a_failed_model_call_skips_its_item_and_names_the_error_class( @@ -977,12 +1067,12 @@ def test_a_failed_model_call_skips_its_item_and_names_the_error_class( ) plan = _plan(store, script) + raise_for_failed_checks(plan) - with pytest.raises( - RoadmapAlternativesError, match=rf"#{failing} \(the model call failed \(AIClientError\)\)" - ): - raise_for_failed_checks(plan) - assert [c.item.number for c in plan.checks] == [kept] + assert ( + [c.item.number for c in plan.checks], + [(f.item.number, f.reason, f.error_class) for f in plan.failures], + ) == ([kept], [(failing, "the model call failed (AIClientError)", "AIClientError")]) def test_a_run_that_spends_its_budget_skips_its_item( @@ -992,9 +1082,48 @@ def test_a_run_that_spends_its_budget_skips_its_item( number = _item(store) plan = _plan(store, Script(call("search_web", query="q"))) - assert [(f.item.number, f.reason) for f in plan.failures] == [ - (number, "the model's run stopped (UsageLimitExceeded)") - ] + ((failure),) = plan.failures + assert ( + failure.item.number, + failure.error_class, + failure.reason.startswith("the model's run stopped (UsageLimitExceeded: "), + len(failure.reason) > len("the model's run stopped (UsageLimitExceeded: )"), + ) == (number, "UsageLimitExceeded", True, True) + + +@pytest.mark.parametrize( + ("message", "reason"), + [ + pytest.param( + "The next request would exceed the limit.", + "the model's run stopped (UsageLimitExceeded: The next request would exceed the limit.)", + id="with-message", + ), + pytest.param("", "the model's run stopped (UsageLimitExceeded)", id="no-message"), + ], +) +def test_failure_record_the_reason_of_a_stopped_run_holds_its_message( + store: InMemoryRoadmapStore, + web_key: None, + monkeypatch: pytest.MonkeyPatch, + message: str, + reason: str, +) -> None: + from devops_cli.roadmap.refine_investigation import InvestigationStopped + + number = _item(store) + monkeypatch.setattr( + "devops_cli.roadmap.alternatives.investigate", + lambda *_args, **_kwargs: InvestigationStopped("UsageLimitExceeded", message), + ) + + plan = _plan(store, Script(AlternativesReply(verdict=Verdict.NONE))) + apply_alternatives(store, plan) + + assert ( + [(f.item.number, f.reason) for f in plan.failures], + _failure_record(store, number), + ) == ([(number, reason)], (NOW.isoformat(), "UsageLimitExceeded")) def test_rejected_credentials_stop_the_run_at_the_first_item( @@ -1138,7 +1267,7 @@ def test_the_command_previews_a_check_and_writes_it_with_confirm( ) == (0, True, [], 0, 1) -def test_the_command_exits_1_after_it_reports_a_skipped_item( +def test_total_failure_the_command_exits_1_when_its_only_item_fails( roadmap_store: InMemoryRoadmapStore, web_key: None, monkeypatch: pytest.MonkeyPatch ) -> None: number = _item(roadmap_store) @@ -1149,7 +1278,40 @@ def test_the_command_exits_1_after_it_reports_a_skipped_item( result = CliRunner().invoke(roadmap_app, ["alternatives", "--repo", REPO, "--confirm"]) - assert (result.exit_code, f"#{number}" in result.output) == (1, True) + assert ( + result.exit_code, + f"#{number}" in result.output, + _failure_record(roadmap_store, number), + ) == ( + 1, + True, + (_recorded(roadmap_store, number, AlternativesRecordKey.FAILED_AT), "RefusedReply"), + ) + + +def test_total_failure_the_command_exits_0_when_one_item_fails_and_one_is_checked( + roadmap_store: InMemoryRoadmapStore, web_key: None, monkeypatch: pytest.MonkeyPatch +) -> None: + failing = _item(roadmap_store, "Failing") + kept = _item(roadmap_store, "Kept") + script = _by_item( + { + failing: [_READ_THE_TOOL, _covers(sources=["https://example.com/invented"])], + kept: AlternativesReply(verdict=Verdict.NONE), + } + ) + monkeypatch.setattr( + "devops_cli.roadmap.alternatives.get_task_model", lambda _task: script.model() + ) + + result = CliRunner().invoke(roadmap_app, ["alternatives", "--repo", REPO, "--confirm"]) + + assert ( + result.exit_code, + f"#{failing} Failing: skipped" in result.output, + len(roadmap_store.comments_on(kept)), + _failure_record(roadmap_store, failing)[1], + ) == (0, True, 1, "RefusedReply") @pytest.mark.parametrize( @@ -1234,7 +1396,7 @@ def test_the_limit_setting_defaults_to_five_and_is_at_least_one( assert load_settings().roadmap.alternatives.limit == 5 -def test_a_failed_check_fails_the_row_once_the_others_are_written( +def test_total_failure_a_failed_check_records_its_item_and_the_row_succeeds( store: InMemoryRoadmapStore, web_key: None, monkeypatch: pytest.MonkeyPatch ) -> None: from pydantic_ai.exceptions import ModelHTTPError @@ -1248,10 +1410,55 @@ def test_a_failed_check_fails_the_row_once_the_others_are_written( ), ) - with pytest.raises(RoadmapAlternativesError, match=rf"#{failing} "): + _alternatives_row().runner(store=store, repo=REPO) + + assert ( + store.comments_on(failing), + len(store.comments_on(kept)), + _failure_record(store, failing)[1], + _failure_record(store, kept), + ) == ([], 1, "AIClientError", (None, None)) + + +def test_total_failure_a_round_in_which_every_check_fails_fails_the_row_and_records_each( + store: InMemoryRoadmapStore, web_key: None, monkeypatch: pytest.MonkeyPatch +) -> None: + from pydantic_ai.exceptions import ModelHTTPError + + first = _item(store, "First") + second = _item(store, "Second") + script = _by_item({first: ModelHTTPError(500, "m"), second: ModelHTTPError(503, "m")}) + _answer_with(monkeypatch, script) + + plan = _plan(store, script) + with pytest.raises(RoadmapAlternativesError) as direct: + raise_for_failed_checks(plan) + with pytest.raises(RoadmapAlternativesError) as row: _alternatives_row().runner(store=store, repo=REPO) - assert (store.comments_on(failing), len(store.comments_on(kept))) == ([], 1) + assert ( + direct.value.failed_items, + row.value.failed_items, + "the check failed for each of the 2 item(s) it tried" in str(row.value), + _failure_record(store, first)[1], + _failure_record(store, second)[1], + ) == ((first, second), (first, second), True, "AIClientError", "AIClientError") + + +def test_total_failure_a_round_with_no_item_to_check_makes_no_model_call_and_succeeds( + store: InMemoryRoadmapStore, web_key: None, monkeypatch: pytest.MonkeyPatch +) -> None: + current = _item(store, "Current") + delayed = _item(store, "Delayed") + _mark_checked(store, current, days=2) + _mark_failed(store, delayed, days=1) + script = Script(AlternativesReply(verdict=Verdict.NONE)) + _answer_with(monkeypatch, script) + + plan = plan_alternatives(store, repo=REPO, now=NOW) + raise_for_failed_checks(plan) + + assert (script.seen, plan.checks, plan.failures, plan.has_writes) == ([], [], [], False) def test_a_round_off_for_want_of_a_key_runs_the_row_and_checks_nothing( @@ -1309,6 +1516,79 @@ def test_the_commands_limit_option_has_no_default_of_its_own( ) +def test_failure_record_one_of_five_checks_fails_and_the_round_records_it_and_succeeds( + store: InMemoryRoadmapStore, web_key: None, monkeypatch: pytest.MonkeyPatch +) -> None: + from pydantic_ai.exceptions import ModelHTTPError + + numbers = [_item(store, f"Item {n}") for n in range(5)] + failing = numbers[2] + before = store.read_issue_body(failing) + script = _by_item( + { + n: ModelHTTPError(500, "m") if n == failing else AlternativesReply(verdict=Verdict.NONE) + for n in numbers + } + ) + _answer_with(monkeypatch, script) + monkeypatch.setattr( + "devops_cli.roadmap.alternatives.datetime", + type("_FixedClock", (datetime,), {"now": classmethod(lambda cls, tz=None: NOW)}), + ) + + _alternatives_row().runner(store=store, repo=REPO) + + assert ( + [n for n in numbers if store.comments_on(n)], + _failure_record(store, failing), + store.read_issue_body(failing), + _recorded(store, failing, AlternativesRecordKey.CHECKED_AT), + ) == ([n for n in numbers if n != failing], (NOW.isoformat(), "AIClientError"), before, None) + + +def test_failure_record_a_plan_that_is_not_applied_changes_no_job_record( + store: InMemoryRoadmapStore, web_key: None +) -> None: + from pydantic_ai.exceptions import ModelHTTPError + + number = _item(store) + + plan = _plan(store, Script(ModelHTTPError(500, "m"))) + + assert (plan.has_writes, store.job_writes(), _failure_record(store, number)) == ( + True, + [], + (None, None), + ) + + +def test_failure_record_a_failed_item_is_tried_again_after_the_delay_and_its_check_clears_it( + store: InMemoryRoadmapStore, web_key: None +) -> None: + from pydantic_ai.exceptions import ModelHTTPError + + number = _item(store) + apply_alternatives(store, _plan(store, Script(ModelHTTPError(500, "m")))) + soon = Script(AlternativesReply(verdict=Verdict.NONE)) + later = Script(AlternativesReply(verdict=Verdict.NONE)) + + early = _plan(store, soon, now=NOW + timedelta(days=1)) + apply_alternatives(store, early) + recorded_early = _failure_record(store, number) + written = apply_alternatives(store, _plan(store, later, now=NOW + timedelta(days=4))) + + assert ( + soon.seen, + early.checks, + early.failures, + recorded_early, + written, + len(later.seen), + _failure_record(store, number), + _recorded(store, number, AlternativesRecordKey.VERDICT), + ) == ([], [], [], (NOW.isoformat(), "AIClientError"), 1, 1, (None, None), "none") + + # ── The metric ──────────────────────────────────────────────────────────────── From 3af761540e41e6b0af17158d1acf7a7e1cc3c05e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 22:56:35 +0000 Subject: [PATCH 2/2] docs(openspec): archive #2949 failed alternatives item change Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PeiMDokwZ2G38Cktk2JiKu --- .../.openspec.yaml | 0 .../design.md | 0 .../proposal.md | 0 .../specs/roadmap-alternatives/spec.md | 6 +- .../tasks.md | 20 +++--- openspec/specs/roadmap-alternatives/spec.md | 70 ++++++++++++++++--- 6 files changed, 75 insertions(+), 21 deletions(-) rename openspec/changes/{2949-a-failed-alternatives-check-skips-its => archive/2026-11-01-2949-a-failed-alternatives-check-skips-its}/.openspec.yaml (100%) rename openspec/changes/{2949-a-failed-alternatives-check-skips-its => archive/2026-11-01-2949-a-failed-alternatives-check-skips-its}/design.md (100%) rename openspec/changes/{2949-a-failed-alternatives-check-skips-its => archive/2026-11-01-2949-a-failed-alternatives-check-skips-its}/proposal.md (100%) rename openspec/changes/{2949-a-failed-alternatives-check-skips-its => archive/2026-11-01-2949-a-failed-alternatives-check-skips-its}/specs/roadmap-alternatives/spec.md (93%) rename openspec/changes/{2949-a-failed-alternatives-check-skips-its => archive/2026-11-01-2949-a-failed-alternatives-check-skips-its}/tasks.md (93%) diff --git a/openspec/changes/2949-a-failed-alternatives-check-skips-its/.openspec.yaml b/openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/.openspec.yaml similarity index 100% rename from openspec/changes/2949-a-failed-alternatives-check-skips-its/.openspec.yaml rename to openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/.openspec.yaml diff --git a/openspec/changes/2949-a-failed-alternatives-check-skips-its/design.md b/openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/design.md similarity index 100% rename from openspec/changes/2949-a-failed-alternatives-check-skips-its/design.md rename to openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/design.md diff --git a/openspec/changes/2949-a-failed-alternatives-check-skips-its/proposal.md b/openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/proposal.md similarity index 100% rename from openspec/changes/2949-a-failed-alternatives-check-skips-its/proposal.md rename to openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/proposal.md diff --git a/openspec/changes/2949-a-failed-alternatives-check-skips-its/specs/roadmap-alternatives/spec.md b/openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/specs/roadmap-alternatives/spec.md similarity index 93% rename from openspec/changes/2949-a-failed-alternatives-check-skips-its/specs/roadmap-alternatives/spec.md rename to openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/specs/roadmap-alternatives/spec.md index 816ede8140..3827360221 100644 --- a/openspec/changes/2949-a-failed-alternatives-check-skips-its/specs/roadmap-alternatives/spec.md +++ b/openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/specs/roadmap-alternatives/spec.md @@ -1,7 +1,7 @@ ## MODIFIED Requirements ### Requirement: The check takes the items that need one, in order -`devops roadmap alternatives` SHALL take an open Item whose Status is New or Ready and whose author has write access to the repository (`CONST_ROADMAP_TRUSTED_AUTHORS`), and SHALL take no other item. It SHALL take the items with no check first, lowest number first, then the items whose last check is older than `roadmap.alternatives.recheck_days` (default 30) or whose body changed since the check, the oldest check first. It SHALL NOT take an item whose last check failed less than `roadmap.alternatives.retry_days` (default 3) days ago, and `--limit` (default 5) SHALL cap the run. +`devops roadmap alternatives` SHALL take an open Item whose Status is New or Ready and whose author has write access to the repository (`CONST_ROADMAP_TRUSTED_AUTHORS`), and SHALL take no other item. It SHALL take the items with no check first, lowest number first, then the items whose last check is older than `roadmap.alternatives.recheck_days` (default 30) or whose body changed since the check, the oldest check first. `--limit` (default 5) SHALL cap the run. #### Scenario: Unchecked items come before stale items - **WHEN** item 4 was checked 40 days ago, items 7 and 9 have no check, item 6 was checked 2 days ago with an unchanged body, and the run has `--limit 3` @@ -66,7 +66,7 @@ With `--confirm`, a check SHALL post one comment with the marker `devops roadmap - **THEN** the issue has one comment with the marker, its body has one block with the verdict and the tool, its job record has the four keys, its labels are unchanged and it is open ### Requirement: The Service runs the check twice a day -The due table of the roadmap SHALL hold the row `alternatives` in `MODEL_LANE_ROWS`, after `refine`. The row SHALL be due on a first run and every `DEFAULT_ROADMAP_ALTERNATIVES_INTERVAL_MINUTES` (719) after its last success, and SHALL be due by no webhook hint. It SHALL check at most `roadmap.alternatives.limit` items in a round, and SHALL fail the round, once the failures are recorded, only when it tried at least one item and checked none. A round that selects no item SHALL NOT fail. `devops roadmap run --dry-run` SHALL list the row when it is due. +The due table of the roadmap SHALL hold the row `alternatives` in `MODEL_LANE_ROWS`, after `refine`. The row SHALL be due on a first run and every `DEFAULT_ROADMAP_ALTERNATIVES_INTERVAL_MINUTES` (719) after its last success, and SHALL be due by no webhook hint. It SHALL check at most `roadmap.alternatives.limit` items in a round, and SHALL fail the round only when it tried items and checked none. `devops roadmap run --dry-run` SHALL list the row when it is due. #### Scenario: A first run - **WHEN** a round runs on a roadmap whose `schedule.json` holds no success of the row @@ -126,7 +126,7 @@ The due table of the roadmap SHALL hold the row `alternatives` in `MODEL_LANE_RO - **THEN** the job record of the item is unchanged ### Requirement: The retry delay is a setting -The setting `roadmap.alternatives.retry_days` SHALL be an integer of at least 1, default 3, and SHALL decide how long after a failed check the item is left out of the selection. +The setting `roadmap.alternatives.retry_days` SHALL be an integer of at least 1, default 3, and and the selection SHALL NOT take an item whose last check failed less than that many days ago, unless `--item` names it. #### Scenario: The default - **WHEN** the setting is not set diff --git a/openspec/changes/2949-a-failed-alternatives-check-skips-its/tasks.md b/openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/tasks.md similarity index 93% rename from openspec/changes/2949-a-failed-alternatives-check-skips-its/tasks.md rename to openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/tasks.md index 927a9264fb..de65864f76 100644 --- a/openspec/changes/2949-a-failed-alternatives-check-skips-its/tasks.md +++ b/openspec/changes/archive/2026-11-01-2949-a-failed-alternatives-check-skips-its/tasks.md @@ -4,23 +4,23 @@ Reads: `src/devops_cli/roadmap/alternatives.py` (lines 423 to 490 and 709 to 745), `src/devops_cli/roadmap/store.py` (lines 160 to 175), `src/devops_cli/config/settings.py` (lines 945 to 965), `src/devops_cli/config/defaults.py` (lines 720 to 726), `docs/ROADMAP_WORKFLOW.md` (lines 90 to 106), `tests/roadmap/test_roadmap_alternatives.py` (lines 100 to 290 and 1215 to 1236). Changes: `src/devops_cli/roadmap/alternatives.py`, `src/devops_cli/roadmap/store.py`, `src/devops_cli/config/settings.py`, `src/devops_cli/config/defaults.py`, `docs/ROADMAP_WORKFLOW.md`, `tests/roadmap/test_roadmap_alternatives.py`, and the generated `docs/CONFIGURATION.md`. -- [ ] 1.1 In `tests/roadmap/test_roadmap_alternatives.py`, write the failing tests. A setting test next to the existing limit test: `AlternativesConfig().retry_days` is 3 and `AlternativesConfig(retry_days=0)` raises `ValidationError`. A selection test that marks items with `AlternativesRecordKey.FAILED_AT` (as `_mark_checked` marks `CHECKED_AT`): an item that failed 1 day ago with `retry_days=3` is not selected, an item that failed 4 days ago is selected in the order of the items with no check, `item_number` selects the item whatever its failure, and a failure time that is not a time is ignored. Name each test with `retry_delay`. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py -k retry_delay` fails on the base because `AlternativesRecordKey` has no `FAILED_AT` and `AlternativesConfig` has no `retry_days` -- [ ] 1.2 Add `FAILED_AT = "alternatives.failed_at"` and `FAILED_ERROR = "alternatives.failed_error"` to `AlternativesRecordKey` and name them in its docstring. Add `DEFAULT_ROADMAP_ALTERNATIVES_RETRY_DAYS: int = 3` after the recheck default in `src/devops_cli/config/defaults.py`, and the field `retry_days` (`ge=1`) to `AlternativesConfig`. Add the required keyword `retry_days` to `select_items`, read the failure time with a helper that is built like `_checked_at` (log a warning and ignore a value that is not a time), leave out an eligible item whose failure is younger than `retry_days` days when `item_number` is None, and pass `config.retry_days` from `plan_alternatives`. Add `retry_days=3` to the 7 direct calls of `select_items` in the test file. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py` passes -- [ ] 1.3 In `docs/ROADMAP_WORKFLOW.md`, add `alternatives.failed_at` and `alternatives.failed_error` to the Alternatives row of the table of job record keys, with what they hold (when the last check failed, and the class of the error). Run `uv run devops docs generate --sync-readme`. Verify that `uv run devops ci test tests/invariants/test_roadmap_workflow_doc.py` passes and that `uv run devops ci docs` passes +- [x] 1.1 In `tests/roadmap/test_roadmap_alternatives.py`, write the failing tests. A setting test next to the existing limit test: `AlternativesConfig().retry_days` is 3 and `AlternativesConfig(retry_days=0)` raises `ValidationError`. A selection test that marks items with `AlternativesRecordKey.FAILED_AT` (as `_mark_checked` marks `CHECKED_AT`): an item that failed 1 day ago with `retry_days=3` is not selected, an item that failed 4 days ago is selected in the order of the items with no check, `item_number` selects the item whatever its failure, and a failure time that is not a time is ignored. Name each test with `retry_delay`. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py -k retry_delay` fails on the base because `AlternativesRecordKey` has no `FAILED_AT` and `AlternativesConfig` has no `retry_days` +- [x] 1.2 Add `FAILED_AT = "alternatives.failed_at"` and `FAILED_ERROR = "alternatives.failed_error"` to `AlternativesRecordKey` and name them in its docstring. Add `DEFAULT_ROADMAP_ALTERNATIVES_RETRY_DAYS: int = 3` after the recheck default in `src/devops_cli/config/defaults.py`, and the field `retry_days` (`ge=1`) to `AlternativesConfig`. Add the required keyword `retry_days` to `select_items`, read the failure time with a helper that is built like `_checked_at` (log a warning and ignore a value that is not a time), leave out an eligible item whose failure is younger than `retry_days` days when `item_number` is None, and pass `config.retry_days` from `plan_alternatives`. Add `retry_days=3` to the 7 direct calls of `select_items` in the test file. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py` passes +- [x] 1.3 In `docs/ROADMAP_WORKFLOW.md`, add `alternatives.failed_at` and `alternatives.failed_error` to the Alternatives row of the table of job record keys, with what they hold (when the last check failed, and the class of the error). Run `uv run devops docs generate --sync-readme`. Verify that `uv run devops ci test tests/invariants/test_roadmap_workflow_doc.py` passes and that `uv run devops ci docs` passes ## 2. Record each failed check Reads: `src/devops_cli/roadmap/alternatives.py` (lines 385 to 420, 640 to 800), `src/devops_cli/roadmap/refine_investigation.py` (lines 100 to 110), `src/devops_cli/lang/en/messages.py` (lines 1996 to 2014), `tests/roadmap/test_roadmap_alternatives.py` (lines 100 to 200, 900 to 1010 and 1335 to 1380). Changes: `src/devops_cli/roadmap/alternatives.py`, `src/devops_cli/config/constants.py`, `src/devops_cli/lang/en/messages.py`, `tests/roadmap/test_roadmap_alternatives.py`. -- [ ] 2.1 In `tests/roadmap/test_roadmap_alternatives.py`, write the failing tests with the helpers `_item`, `_by_item`, `_plan` and `apply_alternatives`. Name each test with `failure_record`. (a) Five items, the model call of one raises `ModelHTTPError(500, "m")`: after `apply_alternatives`, four items have a check and the failed item has `FAILED_AT` equal to the time of the plan, `FAILED_ERROR` equal to `AIClientError`, no comment, and a body unchanged outside the record block. (b) A run that stops with `UsageLimitExceeded` records that class, and its `reason` holds the class and the message of the stop. (c) A refused reply (a URL that no tool returned) and a body with a marker that has no partner are recorded with the fixed refusal name, and the marker case leaves the person's text unchanged. (d) A plan that is not applied changes no job record, and `plan.has_writes` is true for a plan that holds only failures. (e) Two rounds on one store: after a failed round, a round 1 day later makes no model call for the item, and a round 4 days later writes its check and clears both keys. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py -k failure_record` fails on the base because the job record of the failed item holds no failure keys -- [ ] 2.2 Add a constant for the fixed refusal name to `src/devops_cli/config/constants.py`. Give `CheckFailure` the fields `error_class` and `failed_at`. Fill them in `_check_one` (`type(exc).__name__` for `AIClientError`, `InvestigationStopped.reason` for a stopped run) and in `validate_reply` (the constant, with the `now` it already takes). Add the `message` of `InvestigationStopped` to `alternatives_reason_stopped` in `src/devops_cli/lang/en/messages.py` when it is not empty. Make `AlternativesPlan.has_writes` true when `failures` is not empty. In `apply_alternatives`, after the checks, call `store.set_marks` for each failure with the two keys, and clear both keys in the `set_marks` call of a written check (value `None`). Change the one existing test that pins the stopped reason (the text "the model's run stopped (UsageLimitExceeded)") so that it asserts the reason with the message. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py` passes -- [ ] 2.3 Verify that `uv run devops ci test tests/roadmap/test_roadmap_dry_runs.py tests/roadmap/test_roadmap_refine.py tests/roadmap/test_roadmap_run.py` passes, which shows that the dry run, refine and the Service rows keep their behavior +- [x] 2.1 In `tests/roadmap/test_roadmap_alternatives.py`, write the failing tests with the helpers `_item`, `_by_item`, `_plan` and `apply_alternatives`. Name each test with `failure_record`. (a) Five items, the model call of one raises `ModelHTTPError(500, "m")`: after `apply_alternatives`, four items have a check and the failed item has `FAILED_AT` equal to the time of the plan, `FAILED_ERROR` equal to `AIClientError`, no comment, and a body unchanged outside the record block. (b) A run that stops with `UsageLimitExceeded` records that class, and its `reason` holds the class and the message of the stop. (c) A refused reply (a URL that no tool returned) and a body with a marker that has no partner are recorded with the fixed refusal name, and the marker case leaves the person's text unchanged. (d) A plan that is not applied changes no job record, and `plan.has_writes` is true for a plan that holds only failures. (e) Two rounds on one store: after a failed round, a round 1 day later makes no model call for the item, and a round 4 days later writes its check and clears both keys. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py -k failure_record` fails on the base because the job record of the failed item holds no failure keys +- [x] 2.2 Add a constant for the fixed refusal name to `src/devops_cli/config/constants.py`. Give `CheckFailure` the fields `error_class` and `failed_at`. Fill them in `_check_one` (`type(exc).__name__` for `AIClientError`, `InvestigationStopped.reason` for a stopped run) and in `validate_reply` (the constant, with the `now` it already takes). Add the `message` of `InvestigationStopped` to `alternatives_reason_stopped` in `src/devops_cli/lang/en/messages.py` when it is not empty. Make `AlternativesPlan.has_writes` true when `failures` is not empty. In `apply_alternatives`, after the checks, call `store.set_marks` for each failure with the two keys, and clear both keys in the `set_marks` call of a written check (value `None`). Change the one existing test that pins the stopped reason (the text "the model's run stopped (UsageLimitExceeded)") so that it asserts the reason with the message. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py` passes +- [x] 2.3 Verify that `uv run devops ci test tests/roadmap/test_roadmap_dry_runs.py tests/roadmap/test_roadmap_refine.py tests/roadmap/test_roadmap_run.py` passes, which shows that the dry run, refine and the Service rows keep their behavior ## 3. Fail the row only when no item could be checked Reads: `src/devops_cli/roadmap/alternatives.py` (lines 1 to 30 and 780 to 800), `src/devops_cli/roadmap/run.py` (lines 595 to 610), `src/devops_cli/exceptions/roadmap.py` (lines 130 to 153), `src/devops_cli/lang/en/help.py` (lines 1283 to 1298), `tests/roadmap/test_roadmap_alternatives.py` (lines 100 to 200, 930 to 1010, 1140 to 1160 and 1235 to 1260). Changes: `src/devops_cli/roadmap/alternatives.py`, `src/devops_cli/roadmap/run.py` (docstring only), `src/devops_cli/exceptions/roadmap.py` (docstring only), `src/devops_cli/lang/en/help.py`, `k8s/README.md` (line 610), `tests/roadmap/test_roadmap_alternatives.py`, and the generated `README.md`, `docs/CLI_REFERENCE.md`, `docs/commands/roadmap.md`, `docs/MCP_TOOLS.md`, `docs/ERRORS.md`. -- [ ] 3.1 In `tests/roadmap/test_roadmap_alternatives.py`, write the failing tests and change the tests that pin the old rule. Name each new test with `total_failure`. (a) Two items, the model call of each fails: `raise_for_failed_checks` raises `RoadmapAlternativesError` that names both, the row (`_alternatives_row().runner`) raises, and both items hold a failure record afterwards. (b) One item fails and one succeeds: the row returns, the second item has its check, and the first has a record. (c) Every eligible item has a current check or a failure inside its delay: the row makes no model call and returns. (d) The command `devops roadmap alternatives --confirm` exits 0 with one failed and one good item, and exits 1 when its only item fails. Change the tests `test_a_refused_reply_skips_its_item_and_the_others_are_written`, `test_a_failed_model_call_skips_its_item_and_names_the_error_class`, `test_the_command_exits_1_after_it_reports_a_skipped_item` and `test_a_failed_check_fails_the_row_once_the_others_are_written` to the new rule (rename the last, since the row no longer fails there). Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py -k total_failure` fails on the base because the row and the command raise after a partial failure -- [ ] 3.2 In `raise_for_failed_checks`, return when `plan.checks` is not empty or `plan.failures` is empty, and update its docstring, the module docstring of `src/devops_cli/roadmap/alternatives.py` (the paragraphs "The run" and "Writes"), the docstring of `_run_alternatives_adapter` in `src/devops_cli/roadmap/run.py`, and the docstring of `RoadmapAlternativesError`. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py` passes -- [ ] 3.3 In `src/devops_cli/lang/en/help.py`, change the last sentence of the help of `alternatives`: an item whose check fails is skipped, reported and recorded, the others are written, and the command exits 1 only when no item was checked; name `roadmap.alternatives.retry_days`. In `k8s/README.md` line 610, replace the sentence "If the check of an item fails, the row writes the other checks and fails, naming the item." with the new rule: a failed item is recorded in its job record with the class of the error and the time, the round succeeds, the row fails (and counts toward the 3-round suspension) only when it tried an item and checked none, and the item returns after `roadmap.alternatives.retry_days` (3 by default). Run `uv run devops docs generate --sync-readme`. Verify that `uv run devops ci docs` passes -- [ ] 3.4 Verify that `uv run devops ci` passes +- [x] 3.1 In `tests/roadmap/test_roadmap_alternatives.py`, write the failing tests and change the tests that pin the old rule. Name each new test with `total_failure`. (a) Two items, the model call of each fails: `raise_for_failed_checks` raises `RoadmapAlternativesError` that names both, the row (`_alternatives_row().runner`) raises, and both items hold a failure record afterwards. (b) One item fails and one succeeds: the row returns, the second item has its check, and the first has a record. (c) Every eligible item has a current check or a failure inside its delay: the row makes no model call and returns. (d) The command `devops roadmap alternatives --confirm` exits 0 with one failed and one good item, and exits 1 when its only item fails. Change the tests `test_a_refused_reply_skips_its_item_and_the_others_are_written`, `test_a_failed_model_call_skips_its_item_and_names_the_error_class`, `test_the_command_exits_1_after_it_reports_a_skipped_item` and `test_a_failed_check_fails_the_row_once_the_others_are_written` to the new rule (rename the last, since the row no longer fails there). Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py -k total_failure` fails on the base because the row and the command raise after a partial failure +- [x] 3.2 In `raise_for_failed_checks`, return when `plan.checks` is not empty or `plan.failures` is empty, and update its docstring, the module docstring of `src/devops_cli/roadmap/alternatives.py` (the paragraphs "The run" and "Writes"), the docstring of `_run_alternatives_adapter` in `src/devops_cli/roadmap/run.py`, and the docstring of `RoadmapAlternativesError`. Verify that `uv run devops ci test tests/roadmap/test_roadmap_alternatives.py` passes +- [x] 3.3 In `src/devops_cli/lang/en/help.py`, change the last sentence of the help of `alternatives`: an item whose check fails is skipped, reported and recorded, the others are written, and the command exits 1 only when no item was checked; name `roadmap.alternatives.retry_days`. In `k8s/README.md` line 610, replace the sentence "If the check of an item fails, the row writes the other checks and fails, naming the item." with the new rule: a failed item is recorded in its job record with the class of the error and the time, the round succeeds, the row fails (and counts toward the 3-round suspension) only when it tried an item and checked none, and the item returns after `roadmap.alternatives.retry_days` (3 by default). Run `uv run devops docs generate --sync-readme`. Verify that `uv run devops ci docs` passes +- [x] 3.4 Verify that `uv run devops ci` passes diff --git a/openspec/specs/roadmap-alternatives/spec.md b/openspec/specs/roadmap-alternatives/spec.md index e4b9503369..52899889cd 100644 --- a/openspec/specs/roadmap-alternatives/spec.md +++ b/openspec/specs/roadmap-alternatives/spec.md @@ -24,6 +24,14 @@ The check of `devops roadmap alternatives`: which open items it takes and in wha - **WHEN** one item is In Progress, one is Blocked, and one was opened by an account with no write access - **THEN** the run checks none of them +#### Scenario: An item whose check failed lately +- **WHEN** item 5 has no check, its last check failed 1 day ago, and `roadmap.alternatives.retry_days` is 3 +- **THEN** the run does not check item 5 + +#### Scenario: An item whose check failed long ago +- **WHEN** item 5 has no check, its last check failed 4 days ago, and `roadmap.alternatives.retry_days` is 3 +- **THEN** the run checks item 5 in the order of an item with no check + ### Requirement: One item can be named `--item` SHALL check the one item it names whenever it is open, whoever opened it and whatever its Status, and SHALL check no other item. @@ -65,30 +73,34 @@ The job SHALL set `maintained` from the facts that a tool read, and the model SH - **THEN** the check records the tool as not maintained ### Requirement: The job refuses a reply with a source no tool returned -The job SHALL refuse a reply whose `sources` or `tool_url` cite a URL that no tool returned in this run, and a `covers` or `partly` verdict with no tool, or with a tool whose facts no tool read. It SHALL skip that item and write nothing for it, write the checks of the other items, and then fail with an error that names each skipped item and its reason. +The job SHALL refuse a reply whose `sources` or `tool_url` cite a URL that no tool returned in this run, and a `covers` or `partly` verdict with no tool, or with a tool whose facts no tool read. It SHALL skip that item and write no check for it, write the checks of the other items, record the failure of the skipped item, and then fail with an error that names each skipped item and its reason only when it wrote no check. #### Scenario: A made-up URL -- **WHEN** a reply cites `https://example.com/invented` and no tool returned that URL -- **THEN** the item is skipped, nothing is written for it, the other items are written, and the error names the item +- **WHEN** a reply cites `https://example.com/invented` and no tool returned that URL, and the check of another item succeeds +- **THEN** the item is skipped, no check is written for it, the other item is written, and the run does not fail #### Scenario: Not-applicable after a tool ran - **WHEN** a reply gives the verdict `not-applicable` and the run made a search or a fact read -- **THEN** the item is skipped with a named reason and nothing is written for it +- **THEN** the item is skipped with a named reason and no check is written for it #### Scenario: A model call fails - **WHEN** the model call of one item fails and the call of another item succeeds -- **THEN** the run writes the second item, then fails with an error that names the first +- **THEN** the run writes the second item and does not fail #### Scenario: Rejected credentials - **WHEN** the model refuses the key on the first item - **THEN** the run stops at that item and writes nothing +#### Scenario: Every check fails +- **WHEN** the model call of each item fails +- **THEN** the run writes no check, and then fails with an error that names each item and its reason + ### Requirement: A check writes a comment, a block and a record With `--confirm`, a check SHALL post one comment with the marker `devops roadmap alternatives`, replace the block `devops-roadmap-alternatives:start` to `:end` in the body, or add it at the end, and record `alternatives.checked_at`, `alternatives.body_hash`, `alternatives.verdict` and `alternatives.tool` in the job record. The check SHALL NOT change a label and SHALL NOT close the issue. #### Scenario: A marker with no partner - **WHEN** the body holds the start marker of the block with no end marker, or the end marker with no start marker before it -- **THEN** the item is skipped with a named reason, nothing is written for it, and the person's text is not changed +- **THEN** the item is skipped with a named reason, no comment and no block is written for it, and the person's text is not changed #### Scenario: Refine ignores the job's writes - **WHEN** the job has written its block and its comment on an item that refine left waiting on a person @@ -172,7 +184,7 @@ The job SHALL add 1 to the counter `devops_cli_roadmap_alternatives_total` with - **THEN** the job writes no check and counts none ### Requirement: The Service runs the check twice a day -The due table of the roadmap SHALL hold the row `alternatives` in `MODEL_LANE_ROWS`, after `refine`. The row SHALL be due on a first run and every `DEFAULT_ROADMAP_ALTERNATIVES_INTERVAL_MINUTES` (719) after its last success, and SHALL be due by no webhook hint. It SHALL check at most `roadmap.alternatives.limit` items in a round, and SHALL fail the round, once the other checks are written, when the check of any item failed. `devops roadmap run --dry-run` SHALL list the row when it is due. +The due table of the roadmap SHALL hold the row `alternatives` in `MODEL_LANE_ROWS`, after `refine`. The row SHALL be due on a first run and every `DEFAULT_ROADMAP_ALTERNATIVES_INTERVAL_MINUTES` (719) after its last success, and SHALL be due by no webhook hint. It SHALL check at most `roadmap.alternatives.limit` items in a round, and SHALL fail the round only when it tried items and checked none. `devops roadmap run --dry-run` SHALL list the row when it is due. #### Scenario: A first run - **WHEN** a round runs on a roadmap whose `schedule.json` holds no success of the row @@ -192,8 +204,50 @@ The due table of the roadmap SHALL hold the row `alternatives` in `MODEL_LANE_RO #### Scenario: A failed check - **WHEN** the model call for one item fails and the call for another succeeds -- **THEN** the check of the second item is written and the row fails, naming the first +- **THEN** the check of the second item is written, the failure of the first is recorded, and the row succeeds + +#### Scenario: Every check fails +- **WHEN** the model call for each of 2 items fails +- **THEN** the failure of each item is recorded and the row fails, naming both + +#### Scenario: A round with no item to check +- **WHEN** every eligible item has a current check or a failure inside its delay +- **THEN** the row makes no model call and succeeds #### Scenario: A dry run lists the row - **WHEN** `devops roadmap run --dry-run` runs on a roadmap whose rows are all due - **THEN** its `Due:` line ends with `alternatives`, after `refine` + +### Requirement: A failed check is recorded and tried again later +`devops roadmap alternatives --confirm` and the row SHALL record each failed check, whether a failed model call, a stopped run or a refused reply, in the job record of its item with `alternatives.failed_at` (the time of the failure) and `alternatives.failed_error` (the class of the error). A written check SHALL clear both keys. The reason of a stopped run SHALL hold the class of the error and its masked message, and the job record SHALL hold no text of the model. + +#### Scenario: One of five checks fails +- **WHEN** the row runs on 5 items without a check and the model call of one item fails +- **THEN** the round succeeds, 4 checks are written, and the job record of the failed item holds the time of the round and the class `AIClientError`, and the item has no comment and no block + +#### Scenario: A stopped run +- **WHEN** the run of an item stops with `UsageLimitExceeded` +- **THEN** the job record holds the class `UsageLimitExceeded`, and the reason in the report names the class and the message of the stop + +#### Scenario: A retry after the delay +- **WHEN** the check of an item failed 4 days ago with `roadmap.alternatives.retry_days` at 3, and the next round checks it successfully +- **THEN** a check is written for the item and `alternatives.failed_at` and `alternatives.failed_error` are cleared + +#### Scenario: A retry before the delay +- **WHEN** the check of an item failed 1 day ago with `roadmap.alternatives.retry_days` at 3, and a round runs +- **THEN** the round makes no model call for the item and its job record is unchanged + +#### Scenario: A plan that is not applied +- **WHEN** a run only plans the checks and one check fails +- **THEN** the job record of the item is unchanged + +### Requirement: The retry delay is a setting +The setting `roadmap.alternatives.retry_days` SHALL be an integer of at least 1, default 3, and and the selection SHALL NOT take an item whose last check failed less than that many days ago, unless `--item` names it. + +#### Scenario: The default +- **WHEN** the setting is not set +- **THEN** it is 3, and a value of 0 is refused + +#### Scenario: A longer delay +- **WHEN** the setting is 7 and the check of an item failed 4 days ago +- **THEN** the run does not check the item