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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog.d/1358.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Fixed
- The roadmap Service's `metrics` job now clones its repository, as `close` and `refine` do, and walks the release tags of that clone. It used to run `git tag` in the pod's working directory, which is not a git repository, so every run logged `Failed to inspect git tags` and `devops_cli_project_releases_total` read 0 for every repository. A clone that can't be prepared now fails the job, as it fails `close` and `refine` (#1358).
- The `metrics` and `refine` jobs fail, naming the job and `needs_clone`, when they are run without their repository's clone, instead of reading the working directory (#1358).
- `collect_project_metrics_report(root=...)` walks the tags of the repository at `root` as given, so a clone kept under `.data/` inside a workspace checkout reports its own releases, not the checkout's. Without `root`, as in `devops gh metrics`, it still uses the working tree around the current directory (#1358).
- Intake reads `.github/labels.yml` at a run's first candidate, before any timeline read, embedding call or proposal, and a run with no candidate does not read it. A missing file, or one that declares no `type/*` label other than `type/epic`, now stops intake with a configuration error that names the repository and the file and says the file must declare the `type/*` labels intake may assign; a file that is no label specs names the repository too. Any other failed read of the file is still reported as GitHub's error (#1358).

### Changed
- `plan_intake` and `intake_candidate` take the repository they run on (`repo`), which `devops roadmap intake` and the Service's intake job pass (#1358).
- The intake `--dry-run` request plan lists the `.github/labels.yml` read first among the candidate reads, before the timeline reads and the embedding call, with the condition that the run has a candidate; for a `--title` candidate it has no condition (#1358).
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Task: The metrics job walks its own clone's release tags, and intake stops on an unusable labels.yml before any model call (#1358)

**Issue**: [#1358](https://github.com/dan-petty/devops-cli/issues/1358)
**Status**: Done
**Milestone**: v0.2.29
**Priority**: priority/p2-medium
**Scope**: type/bug, scope/telemetry, scope/github

## Description

Two defects in the roadmap Service (`devops serve --service`).

- **The metrics job read the pod's working directory.** The `metrics` row of `DEFAULT_DUE_TABLE` did not set `needs_clone`, and `_run_metrics_adapter` dropped the `clone_path` the executor passes, calling `collect_project_metrics_report` with no `root`. The report then walked the tags of `find_worktree_root()` from the current directory, which in the pod is `WORKDIR /home/devops`, no git repository. Every run logged `Failed to inspect git tags` (71 lines in the 3 hours before 2026-10-08 ~12:35 UTC) and `devops_cli_project_releases_total` read 0 for every repository. Locally, `find_worktree_root` climbs past a clone kept under `.data/` inside a workspace checkout and returns the outer checkout (the known limit tracked in #617), so passing the clone was not enough on its own.
- **Intake read `.github/labels.yml` late and reported a missing file as GitHub's error.** `_Run.types` turned only YAML and label-spec errors into a `ConfigurationError`; a missing file raised the store's `GitHubFileNotFoundError`, and a file with no `type/*` label passed, after which every proposal was rejected. The file was first read inside `_decide`, after the candidates' timeline reads and the embedding call.

The change:

- **Metrics.** The `metrics` row has `needs_clone=True`, so the job runs in the repository's clone under `<data dir>/roadmap/<owner>/<name>/clone`, as `close` and `refine` do; `build_stub_table`'s `metrics` row follows its `needs_clone` argument. `_run_metrics_adapter` passes its clone to `collect_project_metrics_report` as `root`. That function walks `root` as given and calls `find_worktree_root()` only when `root` is None, which keeps `devops gh metrics` unchanged. A clone that can't be prepared fails the job, as it fails `close` and `refine`.
- **No fallback to the working directory.** `_run_metrics_adapter` and `_run_refine_adapter` take their clone through `_job_clone`, which raises `GitOperationError` naming the job and `needs_clone` when the executor gives none, so a table row that runs either without a clone fails the job instead of reading the working directory. Refine's `clone_path or Path.cwd()` was the same one-line fallback in the same file.
- **Intake.** `plan_intake` and `intake_candidate` take the repository (`repo`), which `_Run` holds; the CLI passes its resolved `--repo` and the Service's intake adapter the repository the executor runs. `_Planner.decide_all` reads `self.run.types` first when the run has a candidate, before `_checked` (timeline reads) and `_embed`; a run with no candidate reads nothing more. `_Run.types` raises `ConfigurationError(details={"path": ".github/labels.yml"})` naming the repository, the file and the ref for a missing file (chained to the store's `GitHubFileNotFoundError`), for a file that declares no `type/*` label other than `type/epic`, and for a file that is no label specs. The first two say the file must declare the `type/*` labels intake may assign. Any other failed read propagates as the store raised it (`GitHubOperationError`). The texts live in `lang/en/messages.py`.
- **Dry run.** `_Steps.decisions` lists the `labels` read first, before the timeline reads and the embedding call. Over the open issues it carries the condition "the run has a candidate"; for a `--title` candidate, which always is one, it carries none.

## Acceptance Criteria

- [x] The `metrics` row of `DEFAULT_DUE_TABLE` has `needs_clone=True`, and `_run_metrics_adapter` passes its clone to `collect_project_metrics_report` as `root`: `test_the_metrics_job_walks_the_release_tags_of_its_own_clone` runs `run_due_jobs` with that row over the bare remote `_make_bare_remote` builds in `tmp_path`, with two `v*` tags added to it, with `gh` faked at the process edge (`GitHubFake.process` in place of `subprocess.run`, `git` passed through) and the GitHub and Cloudflare status pages through `stub_web`. The registry's `devops_cli_project_releases_total` reads 2 and the job logs no WARNING record at all, so no `Failed to inspect git tags`, no `Project metrics collection failed` and no `Failed to query`. No devops-cli name is patched. It replaces `test_metrics_job_registered_in_default_due_table_and_adapter`.
- [x] `collect_project_metrics_report(root=<path>)` walks the tags of `<path>` itself; only `root=None` goes through `find_worktree_root` (`test_a_given_root_is_walked_as_it_is_even_inside_another_checkout`: a clone with two tags under `.data/` inside a checkout with two other tags reports the clone's, with no warning). `test_collect_project_metrics_report` patches no reader: its releases are three dated tags in `tmp_path`, its milestones and open issues' labels `GitHubFake`'s answers.
- [x] `build_stub_table`'s `metrics` row follows `needs_clone`, and a clone that can't be prepared fails `metrics` as it fails `close` and `refine` while the stub `intake` and `reprioritize` still run (`test_checkouts_git_management` expects `failed_jobs == ("close", "refine", "metrics")`).
- [x] Given no clone, the metrics and refine adapters raise `GitOperationError` naming the job and `needs_clone`, and read nothing (`test_a_job_that_reads_the_clone_fails_without_one_rather_than_reading_the_cwd`, both jobs).
- [x] A failed collection and failed status reads stay warnings that skip that part of the run: GitHub answering a milestone the report can't count and both status pages answering 404 give the job's three WARNING records, and the job returns its `JobOutcome` (`test_a_failed_metrics_collection_or_status_read_is_logged_and_the_job_goes_on`).
- [x] `plan_intake` reads `.github/labels.yml` once, at the run's first candidate, before the timeline reads and the embedding call; a run with no candidate does not read it (`test_a_run_with_no_candidate_needs_no_labels_file`; `test_a_labels_file_it_cant_use_stops_intake_before_any_read_or_model_call` records no `closures` call and leaves `FakeModel.embedded` and `FakeModel.requests` empty).
- [x] A missing file and one with only `type/epic` raise `ConfigurationError` with `details={"path": ".github/labels.yml"}`, and the message names the repository (`example/roadmap`), the file and the rule; a file that is no label specs names the repository and the file (same test, three cases). Through the command, the error names the `--repo` repository (`test_intake_names_the_repository_whose_labels_file_declares_no_type`).
- [x] A 502 on the read raises `GitHubOperationError`, neither a `ConfigurationError` nor a `GitHubFileNotFoundError`, before any model call (`test_a_labels_read_github_fails_stays_a_github_error`, a `GitHubRoadmapStore` over `GitHubFake` whose `files` entry answers `(1, "gh: Server Error (HTTP 502)")`).
- [x] The dry run lists the `labels` read before the timeline read (`test_dry_run_makes_no_request_and_prints_the_requests_a_run_makes_in_order`), with the candidate condition over the open issues and none for a `--title` candidate (`test_a_dry_runs_labels_read_waits_for_a_candidate_unless_it_has_a_title`), and `test_a_dry_runs_requests_follow_the_order_a_run_makes_them` passes for both of its cases.
- [x] No new test reaches the network or runs helm, and each new test's call phase is under 1 s (`uv run pytest tests/test_github_metrics.py tests/test_roadmap_run.py tests/test_roadmap_intake.py --durations=0`).
- [x] `uv run devops ci` passes within its 5-minute budget.
- [x] `changelog.d/1358.md` records the change; `CHANGELOG.md` and `docs/ROADMAP.md` are untouched.
- Pending a person: ship v0.2.29 so the Service runs a release image with this fix (merge the release PR; Argo CD deploys the new `service` tag). Both checks below wait on it.
- Pending a person, for the hour after the rollout: the Loki query `sum(count_over_time({namespace="devops"} |= "Failed to inspect git tags" [1h]))` returns nothing (baseline: 71 lines in the 3 hours before 2026-10-08 ~12:35 UTC).
- Pending a person, after the rollout: `kubectl -n devops exec deploy/roadmap-service -- sh -c 'ls -d /home/devops/.data/roadmap/*/*/clone'` prints one line for each repository in `service.repos`.

## Decisions and deviations

- **One pull request closes #1358**, carrying both the metrics and the intake criteria. The issue's option of two pull requests, the first without a closing keyword, is dropped: each item PR closes exactly one issue and changes its task file.
- **The run carries its repository.** `plan_intake` and `intake_candidate` take `repo` as a required keyword, as `plan_migration` does, rather than reading it from the store; the `RoadmapStore` protocol is unchanged. Every error `.github/labels.yml` causes names it, in the Service as on the command line.
- **Live check (c) is skipped:** all eight repositories the Service manages have `.github/labels.yml` with nine `type/*` labels (contents API, 2026-10-08), so none can show the error. Defect 2 is latent there; the fix keeps intake failing closed for the next repository onboarded without the file.
- **Failing closed on the reads stays with #974.** A clone that can't be prepared, or a row that gives none, now fails the metrics job, while a failed tag read, a REST read that warns and drops, a failed collection and a failed status read keep their warnings; the status probes' try blocks are unchanged. Making those reads fail closed, and a `repo` label on every project instrument, are the extensions the issue proposes for #974.
- **The clone check reuses `test_checkouts_git_management`** rather than a near-duplicate test: its failure half already sends the milestones webhook that makes `reprioritize` due, so a `metrics` stub there is the whole check.
- **The metrics run test asserts no WARNING record at all**, which also shows the process-edge fake answered every `gh` read the adapter makes; the adapter and the REST readers would otherwise swallow a missed one. The warning test drives a collection failure from the edge: a milestone whose `open_issues` is null fails the count outside the reader's own `try`.
- **The metrics run test reuses `_make_bare_remote`** and tags the commit it pushes. With only the `metrics` row in the table and no change in the round, the run looks up no current release, so `ensure_checkout` clones the default branch and checks out no release branch, before or after #1366's default-branch rule; tags don't depend on the branch.
- **`GitHubFake` is the shared `gh` fake at the process edge (#1307):** it now answers `gh api user`, `gh api rate_limit` (a full quota resetting in a minute), the repository, its Actions runs and its traffic, takes an `(exit code, output)` for a file, and `GitHubFake.process` stands in for `subprocess.run`: it answers a `gh` argv given as a list or a tuple, raises `CalledProcessError` for a failed answer under `check=True`, and passes every other program to the real one. `test_collect_project_metrics_report` used it too: it had been starting the real `gh` (five `gh api rate_limit` calls to GitHub with the test token).
- **The existing label-spec error text moved to `lang/en/messages.py`** with the two new ones, as all three are raised by the same property, and now names the repository as well.

## Deliverables

- [x] `src/devops_cli/roadmap/run.py`: the `metrics` rows need a clone; the metrics and refine adapters fail without one; the intake adapter passes its repository.
- [x] `src/devops_cli/github/metrics.py`: `collect_project_metrics_report` walks `root` as given.
- [x] `src/devops_cli/roadmap/intake.py`, `src/devops_cli/roadmap/intake_requests.py`, `src/devops_cli/commands/roadmap.py`, `src/devops_cli/lang/en/messages.py`: the run's repository, the early labels read, its configuration errors, and the dry-run step order and condition.
- [x] Tests: `tests/roadmap_board_fake.py`, `tests/test_roadmap_run.py`, `tests/test_github_metrics.py`, `tests/test_roadmap_intake.py`.
- [x] Changelog fragment: `changelog.d/1358.md`.
1 change: 1 addition & 0 deletions src/devops_cli/commands/roadmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def _intake(
opened.append(store)
plan = plan_intake(
store,
repo=target,
config=config,
model=meter.model(build_intake_model()),
ref=ref,
Expand Down
10 changes: 8 additions & 2 deletions src/devops_cli/github/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,14 @@ def collect_project_metrics_report(
ci_limit: int = 50,
milestone_filter: str | None = None,
) -> ProjectMetricsReport:
"""Aggregate complete project metrics across releases, CI checks, and milestones."""
project_root = find_worktree_root(root)
"""Aggregate complete project metrics across releases, CI checks, and milestones.

The releases are the `v*` tags of the git repository at `root`, taken as it is, so a clone
nested in another checkout, as the roadmap jobs keep under the data directory, reports its
own tags (#1358). Without `root` they are the tags of the working tree around the current
directory (`find_worktree_root`).
"""
project_root = root if root is not None else find_worktree_root()
target_repo = repo or get_repo_origin_name(project_root) or "repository"
now_str = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%d %H:%M:%S UTC")

Expand Down
14 changes: 14 additions & 0 deletions src/devops_cli/lang/en/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,7 @@ class RoadmapMessages:
)
intake_request_conditions: dict[str, str] = field(
default_factory=lambda: {
"candidate": "the run has a candidate",
"closures": "{subject} is not on the board",
"embed": "a candidate is off the board",
"evidence": "the model cites any",
Expand Down Expand Up @@ -1793,6 +1794,19 @@ class RoadmapMessages:
"The candidate's {part} holds what looks like a secret, so intake sent it to no model "
"and filed nothing. Remove it and run again."
)
intake_labels_unreadable: str = "{repo}'s {path} can't be read as label specs: {error}"
intake_labels_missing: str = (
"{repo} has no {path} at {ref}. Intake decides no candidate without it: the file must "
"declare the type/* labels intake may assign."
)
intake_labels_untyped: str = (
"{repo}'s {path} at {ref} declares no type/* label other than type/epic. Intake decides "
"no candidate without one: the file must declare the type/* labels intake may assign."
)
run_job_needs_clone: str = (
"The roadmap {job} job reads its repository's clone and was given none: its row in the "
"due table must set needs_clone."
)
intake_borrow_needs_title: str = (
"--borrow-reason applies to a new candidate; pass it with --title and --body-file."
)
Expand Down
Loading
Loading