Repository navigation
Description
What to build
Every change thirdshift makes to an issue's labels goes through one label-edit module in the labels module. Today four concepts stitch the edit together by hand: making and releasing a Claim, removing it once the Self-merge has closed the issue, the Sweep, marking an Architect plan ready, and labelling an Architect idea. Each one reads the issue's labels, adds new labels to the repository, swaps labels case-insensitively and writes the result, and each does those steps in its own order. The rule "a label thirdshift puts on is first added to the repository with its description" is applied at some sites and skipped at others. A plan's labels are read before its checks and written back only after an interrupt check and a progress line, so a label added in that gap is lost.
After this change, a caller names the labels to take off and the labels to put on, and the module decides the rest:
- the read;
- which labels actually change;
- whether a request is needed, and which one;
- adding missing labels to the repository;
- the by-hand commands to print when the edit fails.
A caller can still see what an edit will change before applying it, so every progress line and warning reads and is ordered as it does today. The only change users see is that ready-for-agent and needs-triage are now added to a repository that lacks them, with their descriptions, the same way in-progress, architect-plan and architect-idea already are.
Acceptance criteria
- One label-edit module in the labels module is the only code that changes an issue's labels. Its interface:
- built for an issue from the labels to take off and the labels to put on. It reads the issue's labels itself, or takes labels the caller has just read, as the Sweep and the Claim's removal after a Self-merge have;
- asked whether it takes a given label off, whether it puts a given label on, and what the issue's labels were;
- applied, which makes no request when nothing changes;
- a separate function giving the by-hand commands for taking given labels off an issue and putting others on, which doesn't need the issue's labels.
- Applying an edit:
- makes no request when no label changes, ignoring case;
- when exactly one label comes off and none goes on, takes it off with a single DELETE of the label as the issue spells it, so labels added since the read stay;
- otherwise first adds to the repository, each with its description, every label it puts on that the issue lacks and the repository doesn't have, then writes all the issue's labels in one PUT.
- The places that make or remove a Claim, run the Sweep, mark an Architect plan ready or label an Architect idea all use the module. None of them reads, adds or writes labels through the GitHub adapter directly any more.
- Marking an Architect plan ready still checks the plan first and fails without changing any label if it fails a check. The labels it writes now come from a read made after the interrupt check, so a label added while the checks ran is kept.
- Every progress line, warning and by-hand command reads as it does today and comes in the same order.
- Unit tests in the labels module cover, through an internal seam that turns read labels plus off and on into the request to make:
- no request;
- a single DELETE, as the issue spells the label;
- a PUT, with the labels to add to the repository first;
- case-insensitive matching on both off and on;
- the by-hand commands.
- Scenario tests:
- marking a plan ready adds
ready-for-agentto a repository that lacks it, with its description; - labelling an Architect idea adds
needs-triageto a repository that lacks it; - the existing repository-label assertions are updated where they now expect those labels to be added.
- marking a plan ready adds
-
cargo test,cargo clippyandcargo fmt --checkpass.
No change to CONTEXT.md or an ADR: the label-edit module is code structure, not a domain term.
Blocked by
None (can start immediately).
Decisions
- The deepened module lives in the labels module, not the GitHub adapter. The labels module already holds every rule about labels, including case-insensitivity. The label-edit module is that rule applied to an issue. The GitHub adapter keeps the transport operations: read labels, PUT, DELETE, list and create repository labels, and the by-hand command strings. After the change the label-edit module is their only caller, apart from opening an issue, which still adds its own labels to the repository.
- Two steps, describe then apply, rather than one call. A Claim's progress lines depend on what the edit will change ("in place of ready-for-agent", "again"). Its record of what the Claim changed also comes from the edit. Answering those questions before applying keeps every progress line where it is today. A single call that printed its own lines would rewrite user-visible output and pull each concept's wording into the labels module.
- The module reads labels itself, or takes labels the caller has just read. The Sweep already has the labels of each closed issue from its listing, and the Claim's removal after a Self-merge has them from the issue read that tells it whether the issue is closed. Reading again would only add requests.
- A single DELETE when one label comes off and none goes on, and one PUT otherwise. A DELETE keeps labels added since the read and matches what the Claim's release and the Sweep do today. A swap stays one PUT, so it can't stop halfway, as the GitHub adapter's comment requires today.
- Every label put on is added to the repository first, if missing, with its description. This applies to every edit, not to each concept's own label only. That makes the rule hold everywhere: today
ready-for-agentandneeds-triagecan be put on with no description. The cost is one repository-label listing, and only when the edit puts on a label the issue lacks. - Marking a plan ready reads labels again just before writing them. The checks still use the read they make, but the write starts from a fresh read, so the gap where a label can be lost is no longer the checks plus the interrupt check plus a progress line.
- The by-hand commands are a function of the issue, the labels to take off and the labels to put on, and need no read. They are printed when an edit fails, and the failed step may be the read itself.
- Tests: an internal seam, not a new adapter. The choice of request (none, DELETE or PUT plus labels to add) is a pure private function, unit-tested in the labels module. The GitHub adapter keeps a single adapter, the real
ghin production and the fakeghprocess in scenario tests, so no trait seam is added. One adapter would make it a hypothetical seam.
Architecture review
Strength: Strong · Dependencies: in-process (the GitHub adapter stays as it is)
Files: src/labels.rs, src/claim.rs, src/architect.rs, src/github.rs, tests/architect_run.rs, tests/fakes/gh.rs
Before
flowchart LR
Claim --> read[issue_labels]
Claim --> ensure[ensure_labels]
Claim --> put[set_labels]
Claim --> del[remove_label]
Claim --> cmd[by-hand commands]
Sweep --> del
Plan[Architect plan] --> ensure
Plan --> put
Idea[Architect idea] --> read
Idea --> ensure
Idea --> put
Claim --> swap[Labels::swapped]
Plan --> swap
Idea --> swap
classDef leak stroke:#dc2626,stroke-width:2px;
class read,ensure,put,del,cmd leak
After
flowchart LR
Claim --> Edit
Sweep --> Edit
Plan[Architect plan] --> Edit
Idea[Architect idea] --> Edit
subgraph Edit[Label edit]
direction LR
read[issue_labels] --> swap[swap] --> ensure[ensure_labels] --> write[PUT or DELETE]
end
classDef deep stroke-width:3px;
class Edit deep
Problem: four concepts stitch read, ensure, swap and write by hand, so the ensure rule is applied unevenly and one site writes back labels it read too early.
Solution: one label-edit module takes the labels to take off and put on, and owns the read, the ensure, the choice of request and the by-hand commands.
Wins
- Locality: ensure rule in one place
- Leverage: one interface, five call sites
- Request choice unit-tested in-process
- Claim's own bookkeeping shrinks
- Read-modify-write gap closes
Activity