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
11 changes: 11 additions & 0 deletions changelog.d/1361.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Fixed
- The roadmap store writes a board field by the card's node id and reads only that card first, so a job-record mark costs about 3 GraphQL points instead of about 215, and filing and placing a critical fix a small constant (about 17 in the tests' fake GitHub, which leaves out the few queries gh makes to resolve an add) instead of about 1,500, whatever the board's size. It no longer sends `gh project field-list` or an `item-edit` that names a card by URL or a field by name, each of which reads the board's first 100 items with every field value, and no longer re-reads the whole board before each write (#1361).
- Intake writes to the card `gh project item-add` returns, so a placement no longer fails with "#N is not on the board after intake added it" while GitHub's board listing has not shown the new card yet (#1361).
- A store reads the board's fields once, and each filter's board listing once, for its life, one command or one Service round, and its own writes keep that listing current: a reprioritize run reads the board once instead of twice, and a Service round reads it once however many changes its triggers look up. Closing an issue drops the listing, because the board's own "Item closed" workflow then sets the card's Status, so a release cut rendered in the same round shows Done (#1361).
- A roadmap job's board write stops with `RoadmapCardChangedError` before any edit when someone changed that field after the job's store read the board, unless the card already holds the value the job writes, so a job never reverts a person's change it did not see; the job fails and the next round plans with the change (#1361).
- A Service round whose new events are all its own reads no board: the store drops them before it attaches job records (#1361).
- A board write still refuses before it starts while fewer than the 250 reserved GraphQL points are left, now read from its card read's `rateLimit` (#1361).

### Changed
- `RoadmapStore.add_item` returns the Item it added, `Item` and `BoardEntry` carry the card's node id (`card_id`), and `changes_since` takes `except_actor`, an empty one leaving out nothing. The run record card is written by the id `gh project item-create --format json` returns, with no board read after the create (#1361).
- The `--dry-run` request plans list each board write's card read and its `item-edit` by node ids, and the board's fields and each filter's listing once a run; intake's placement lists no board read after its add (#1361).
1 change: 1 addition & 0 deletions docs/ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ names the class each row describes. One code never maps to two exit statuses.
| `PoolLoadError` | `DEVOPS_CLI_ERROR` | `1` | Devops_cli.ai.pool_load | Prometheus could not answer a pool load query. |
| `QdrantClientError` | `DEVOPS_CLI_ERROR` | `1` | Devops_cli.ai.rag.qdrant | Raised when an interaction with Qdrant fails. |
| `ReviewPoolError` | `REVIEW_POOL_ERROR` | `1` | Ai | Raised when an error occurs during parallel review worker pool execution. |
| `RoadmapCardChangedError` | `ROADMAP_CARD_CHANGED` | `1` | Roadmap | Raised before a job's board write that would revert a change made since it read the card. |
| `RoadmapRunError` | `DEVOPS_CLI_ERROR` | `1` | Roadmap | Raised when one or more roadmap jobs fail during execution. |
| `RunCancelled` | `RUN_CANCELLED` | `26` | Ai | Raised when an agent run was cancelled by the application or timeout. |
| `RunIndexNotConfiguredError` | `DEVOPS_CLI_ERROR` | `1` | Devops_cli.ai.run_store | No shared run index is configured. |
Expand Down
72 changes: 72 additions & 0 deletions docs/agent/tasks/task-1361-board-writes-by-node-id.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/devops_cli/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@
CONST_ERROR_CODE_TELEMETRY = "TELEMETRY_ERROR"
CONST_ERROR_CODE_LOGFIRE = "LOGFIRE_CONFIG_ERROR"
CONST_ERROR_CODE_SERVICE_STATUS = "SERVICE_STATUS_ERROR"
CONST_ERROR_CODE_ROADMAP_CARD_CHANGED = "ROADMAP_CARD_CHANGED"
CONST_ERROR_CODE_LIBRARY_INGESTION = "LIBRARY_INGESTION_ERROR"
CONST_ERROR_CODE_LIBRARY_NOT_FOUND = "LIBRARY_NOT_FOUND_ERROR"
CONST_ERROR_CODE_DOCS_INGESTION = "DOCS_INGESTION_ERROR"
Expand Down
3 changes: 2 additions & 1 deletion src/devops_cli/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
KubernetesError,
KubernetesLoggingError,
)
from devops_cli.exceptions.roadmap import RoadmapRunError
from devops_cli.exceptions.roadmap import RoadmapCardChangedError, RoadmapRunError
from devops_cli.exceptions.sandbox import (
SandboxError,
SandboxNotFoundError,
Expand Down Expand Up @@ -123,6 +123,7 @@
"KubernetesError",
"KubernetesLoggingError",
"LogfireConfigurationError",
"RoadmapCardChangedError",
"RoadmapRunError",
"SSRFBlockedError",
"SandboxError",
Expand Down
24 changes: 24 additions & 0 deletions src/devops_cli/exceptions/roadmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from collections.abc import Sequence
from typing import Any

from devops_cli.config.constants import CONST_ERROR_CODE_ROADMAP_CARD_CHANGED
from devops_cli.exceptions.base import DevOpsCLIError
from devops_cli.exceptions.git import GitHubOperationError


class RoadmapRunError(DevOpsCLIError):
Expand All @@ -24,3 +26,25 @@ def __init__(
if failed_jobs and "failed_jobs" not in extra:
extra["failed_jobs"] = list(failed_jobs)
super().__init__(message, details=extra, **kwargs)


class RoadmapCardChangedError(GitHubOperationError):
"""Raised before a job's board write that would revert a change made since it read the card.

The job planned without that change, so writing would revert it (ADR 0002). Nothing is
written; the next run reads the board again and plans with the change.
"""

def __init__(
self,
message: str,
*,
operation: str = "roadmap.item.set_field",
details: dict[str, Any] | None = None,
) -> None:
super().__init__(
message,
operation=operation,
error_code=CONST_ERROR_CODE_ROADMAP_CARD_CHANGED,
details=details,
)
40 changes: 30 additions & 10 deletions src/devops_cli/lang/en/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,16 @@ class RoadmapMessages:
"GraphQL has {remaining} points left until {reset}, below the {floor} kept in reserve, "
"so the read of {what} stopped before page {page}. Run it again after {reset}."
)
graphql_budget_write_floor: str = (
"GraphQL has {remaining} points left until {reset}, below the {floor} kept in reserve, "
"so the run stopped before writing {what}. Run it again after {reset}."
)
card_changed: str = (
"{card}'s {field} is {now} on the board but was {read} when this run read it, so "
"someone changed it since and the run stopped before writing it. Nothing was written; "
"the next run reads the board again and plans with that change."
)
card_value_unset: str = "unset"
board_count_changed: str = (
"The {what} changed while they were read ({counts}), and again on a second read, so "
"the read is incomplete. Run it again once the board is still."
Expand Down Expand Up @@ -1366,8 +1376,12 @@ class RoadmapMessages:
),
"board_first": "the first page of board {board}'s items{matching}",
"board_page": "the next page of board {board}'s items{matching}",
"fields": "board {board}'s fields, with their options",
"field_options": "board {board}'s field options",
"fields": "board {board}'s node id and fields, with their options",
"card": (
"the card of {subject}: its fields, its job record and GraphQL's points left; a "
"write stops here when the points are below the reserve, or when someone changed "
"the field it writes since the run read it"
),
"workflows": "board {board}'s workflows",
"boards": "{owner}'s boards, to find board {board}",
"default_branch": "the default branch and its head",
Expand Down Expand Up @@ -1431,6 +1445,12 @@ class RoadmapMessages:
"posted": "the change posts a comment",
"record": "the run records its release or size",
"no_card": "the board has no run record card yet",
"run_card": "the board has the run record card",
"board_unread": (
"the run has not read these items of the board since it began or last closed an "
"issue"
),
"fields_unread": "the run has not read the board's fields yet",
"closing": "a shipped release's milestone is still open",
"release_named": "the value is a Release",
"board": "the configured board exists",
Expand Down Expand Up @@ -1703,20 +1723,20 @@ class RoadmapMessages:
"label {subject} with its type/* label when it has none, and budget/borrowed "
"when it borrows"
),
"add": "read {subject}, then add it to board {board}",
"item": "board {board} and {subject}, to find its item",
"add": "read {subject}, add it to board {board}, then read the card the add names",
"release": (
"set the milestone of {subject} to <the placement>: the board's fields and "
"items, every milestone, the job record (GraphQL), then the milestone (REST)"
"set the milestone of {subject} to <the placement>: the board's fields once a "
"run, every milestone, its card, the job record (GraphQL), then the milestone "
"(REST)"
),
"field": (
"set {field} on {subject}: the board's fields and items, the job record, then "
"the field"
"set {field} on {subject}: the board's fields once a run, its card, the job "
"record, then the field"
),
"comment": "the reason comment on {subject}",
"priority": (
"set Priority <the proposed Priority> on {subject}: the board's fields and "
"items, the job record, then the field"
"set Priority <the proposed Priority> on {subject}: the board's fields once a "
"run, its card, the job record, then the field"
),
"duplicate_read": "{subject} and <the original>",
"duplicate_comment": "the duplicate comment on {subject}",
Expand Down
92 changes: 83 additions & 9 deletions src/devops_cli/roadmap/board_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
Before the pages, one small query (`RoadmapBoardBudget`) reads the points left and the filter's
total; a read that would leave fewer than `DEFAULT_GH_GRAPHQL_BUDGET_FLOOR` points refuses there,
having spent nothing on pages, and a read stops before any page while fewer than the floor are
left. The documents are fixed templates, validated against GitHub's public schema in a test.
left.

A write reads only the card it writes (#1361): `RoadmapBoardCard` reads one item by its node id,
with the same item fields a page holds and `rateLimit`, for about one point whatever the board's
size, and a write refuses before it starts while fewer than the floor are left. The documents are
fixed templates, validated against GitHub's public schema in a test.

This module only builds `gh` arguments and reads payloads; the store runs them, so a request plan
can list the same argv the store sends.
Expand All @@ -36,6 +41,7 @@

BOARD_ITEMS_OPERATION = "RoadmapBoardItems"
BOARD_BUDGET_OPERATION = "RoadmapBoardBudget"
BOARD_CARD_OPERATION = "RoadmapBoardCard"
GRAPHQL_BUDGET_OPERATION = "RoadmapGraphQLBudget"

_RATE_LIMIT = "rateLimit { cost limit remaining used resetAt }"
Expand All @@ -46,26 +52,35 @@
)
_FIELD_NAME = "field { ... on ProjectV2FieldCommon { name } }"
_REPOSITORY_CONTENT = "number title url repository { nameWithOwner }"
# The item fields the store keeps, the same in a page and in a one-card read.
_ITEM_SELECTION = (
"id content { __typename ... on DraftIssue { title } "
f"... on Issue {{ {_REPOSITORY_CONTENT} }} "
f"... on PullRequest {{ {_REPOSITORY_CONTENT} }} }} "
"fieldValues(first: $fieldValues) { nodes { "
f"... on ProjectV2ItemFieldSingleSelectValue {{ name {_FIELD_NAME} }} "
f"... on ProjectV2ItemFieldTextValue {{ text {_FIELD_NAME} }} "
f"... on ProjectV2ItemFieldDateValue {{ date {_FIELD_NAME} }} }} }}"
)

BOARD_ITEMS_QUERY = (
f"query {BOARD_ITEMS_OPERATION}($owner: String!, $number: Int!, $filter: String!, "
"$first: Int!, $after: String, $fieldValues: Int!) { "
f"{_RATE_LIMIT} "
+ _OWNED_BOARD.format(
selection=_ITEMS.format(first="$first", after="after: $after, ")
+ " { totalCount pageInfo { hasNextPage endCursor } nodes { id "
"content { __typename ... on DraftIssue { title } "
f"... on Issue {{ {_REPOSITORY_CONTENT} }} "
f"... on PullRequest {{ {_REPOSITORY_CONTENT} }} }} "
"fieldValues(first: $fieldValues) { nodes { "
f"... on ProjectV2ItemFieldSingleSelectValue {{ name {_FIELD_NAME} }} "
f"... on ProjectV2ItemFieldTextValue {{ text {_FIELD_NAME} }} "
f"... on ProjectV2ItemFieldDateValue {{ date {_FIELD_NAME} }} }} }} }} }}"
+ f" {{ totalCount pageInfo {{ hasNextPage endCursor }} nodes {{ {_ITEM_SELECTION} }} }}"
)
+ " }"
)
"""One page of the board's items that `$filter` selects, archived ones left out."""

BOARD_CARD_QUERY = (
f"query {BOARD_CARD_OPERATION}($id: ID!, $fieldValues: Int!) {{ {_RATE_LIMIT} "
f"node(id: $id) {{ ... on ProjectV2Item {{ isArchived {_ITEM_SELECTION} }} }} }}"
)
"""One board item by its node id, archived or not, with the fields a page holds."""

BOARD_BUDGET_QUERY = (
f"query {BOARD_BUDGET_OPERATION}($owner: String!, $number: Int!, $filter: String!) {{ "
f"{_RATE_LIMIT} "
Expand Down Expand Up @@ -121,6 +136,15 @@ def board_budget_args(owner: str, number: int | str, board_filter: str) -> list[
)


def board_card_args(card_id: str) -> list[str]:
"""The `gh` arguments of the read of one board item by its node id."""
return _graphql_args(
BOARD_CARD_QUERY,
("id", card_id),
typed=("-F", f"fieldValues={DEFAULT_GH_PROJECT_FIELD_LIMIT}"),
)


def graphql_budget_args() -> list[str]:
"""The `gh` arguments of the query that reads the GraphQL points left."""
return _graphql_args(GRAPHQL_BUDGET_QUERY)
Expand Down Expand Up @@ -211,6 +235,35 @@ class GraphQLBudgetPayload(BaseModel):
rate_limit: GraphQLBudget = Field(validation_alias=AliasPath("data", "rateLimit"))


class _GraphQLError(BaseModel):
type: str | None = None


class BoardCardPayload(BaseModel):
"""The answer to `RoadmapBoardCard`. A node id that resolves to nothing comes back as a null
node with a `NOT_FOUND` error, which `gh` reports by exiting 1 with the answer on stdout."""

rate_limit: GraphQLBudget = Field(validation_alias=AliasPath("data", "rateLimit"))
node: dict[str, Any] | None = Field(default=None, validation_alias=AliasPath("data", "node"))
errors: list[_GraphQLError] = Field(default_factory=list)

def is_gone(self) -> bool:
"""Whether GitHub says the node does not exist, and says nothing else went wrong."""
return (
self.node is None
and bool(self.errors)
and all(error.type == "NOT_FOUND" for error in self.errors)
)

def listed(self) -> dict[str, Any] | None:
"""The item shaped as `gh project item-list` lists it, or None when it is archived, gone
or not a board item."""
node = self.node or {}
if "id" not in node or node.get("isArchived"):
return None
return listing_item(node)


def listing_item(node: dict[str, Any]) -> dict[str, Any]:
"""A board item node in the shape `gh project item-list` gives it: content keyed `type`,
`repository` as `owner/name`, and each field's value under its name, first letter
Expand Down Expand Up @@ -258,6 +311,22 @@ def require_budget(budget: GraphQLBudget, cost: int, what: str) -> None:
)


def require_write_floor(budget: GraphQLBudget, what: str) -> None:
"""Refuse a write, before it starts, while fewer points than the floor are left."""
if budget.remaining < DEFAULT_GH_GRAPHQL_BUDGET_FLOOR:
raise GitHubRateLimitError(
MESSAGES.roadmap.graphql_budget_write_floor.format(
remaining=budget.remaining,
reset=utc_clock(budget.reset_at),
floor=DEFAULT_GH_GRAPHQL_BUDGET_FLOOR,
what=what,
),
subcommand="graphql",
operation="roadmap.write",
details={"remaining": budget.remaining},
)


def require_floor(budget: GraphQLBudget, what: str, page: int) -> None:
"""Stop a read before page `page` while fewer points than the floor are left."""
if budget.remaining < DEFAULT_GH_GRAPHQL_BUDGET_FLOOR:
Expand All @@ -283,23 +352,28 @@ def utc_clock(moment: datetime) -> str:
__all__ = [
"BOARD_BUDGET_OPERATION",
"BOARD_BUDGET_QUERY",
"BOARD_CARD_OPERATION",
"BOARD_CARD_QUERY",
"BOARD_ITEMS_OPERATION",
"BOARD_ITEMS_QUERY",
"GRAPHQL_BUDGET_OPERATION",
"GRAPHQL_BUDGET_QUERY",
"BoardBudgetPayload",
"BoardCardPayload",
"BoardItemsPage",
"GraphQLBudget",
"GraphQLBudgetPayload",
"GraphQLSpend",
"board_budget_args",
"board_card_args",
"board_items_args",
"graphql_budget_args",
"item_list_key",
"listing_item",
"read_cost",
"require_budget",
"require_floor",
"require_write_floor",
"spend_between",
"utc_clock",
]
Loading
Loading