Skip to content

feat(recorder): claim each PR milestone once - #85

Merged
tbhb-agent merged 3 commits into
mainfrom
agent/gm-rec-b-sonnet
Nov 23, 2026
Merged

tbhb-agent merged 3 commits into
mainfrom
agent/gm-rec-b-sonnet

Conversation

@tbhb-agent

@tbhb-agent tbhb-agent commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The reconciler design (#82, PR B of its split) needs one shared rule for counting a merge and a first end, so a webhook and a later repair never count the same pull request twice. This PR adds the webhook half of that rule and wires the store from #84 into the service.

Behavior change

A closed pull request webhook now claims its merge and its first end in the store before it counts them. A redelivery doesn't count a second time. A closed body with no node_id is a drop with reason no_node_id. When a webhook reports a reopen of a PR created before the store existed, the recorder claims the first end without counting it, and a later merge leaves cycle time alone for a first close that an earlier version may already have counted. A reopen of a newer PR claims nothing, because this version counts that first close in any delivery order. recorder.New refuses a nil ledger.

Decisions

RecordClosed takes a ClosedPR that holds the first end's time and state together, so a close followed by a reopen and merge still records cycle time with state closed. Each milestone claims before it counts. A claim error skips the count and returns the error. The caller retries. A milestone older than 24 hours, or no later than the store's creation time, claims without counting. PR F takes the repair floor and the repair path, because that PR adds the first repair caller.

Deviations from the task

The brief had the run leave main's wiring for later, since #84 hadn't merged. It merged first, so main passes the store in this PR. Review round 8 found two blocks. This PR fixes the reopen block. The second block belongs to the repair floor code, which moved to PR F to keep this PR under 400 lines. PR F must read the floor at every start and must not claim a merge at or before it.

Needs human judgment

The round 10 review ruling leaves two gaps as tech debt. A PR closed before the deploy and reopened after can count a second cycle time. A late first close after a reopen and a merge loses its observation. The repair floor PR must limit the reopen claim by that floor.

Risk

Medium. The change alters when closed pull requests count, and a wrong claim loses a count or doubles one. The tests cover each outcome. The diff is 396 of 400 code lines.

Verification

bazelisk test //...
bazelisk run @tbhb_rules//lint:pr_size -- origin/main HEAD

The local run passes but for //deploy:deploy_test, which fails on macOS only. The tests cover a first claim, a second delivery, age and creation-time cutoffs, a claim error, claim order, a missing node_id, the first end after a reopen, and plus a reopen that arrives before or after the first close. A Claude session read the recorder diff before opening the PR. A Sonnet 5.5 run wrote the code.

Human steering

None.

Opened-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:6507fa80a17e0653;surface=cli
Generated-by: LLM effort=high;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:af415c6f0d052b90;surface=sdk-cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:6507fa80a17e0653;started_at=2026-11-15T17:24:44Z;surface=cli

Add ClosedPR and RecordClosed, which apply the 24-hour, store creation
and repair floor rules and claim each milestone through a Ledger before
it counts. The webhook Record reads pull_request.node_id and claims
before any other Add, and a closed body with no node_id counts as a drop
with reason no_node_id. recorder.New now takes the ledger.

main passes the store as the ledger and reads the repair floor at every
start, which stamps the floor and applies a reset flag.

Generated-by: LLM effort=high;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:af415c6f0d052b90;surface=sdk-cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:6507fa80a17e0653;started_at=2026-11-15T17:24:44Z;surface=cli
@tbhb-agent
tbhb-agent force-pushed the agent/gm-rec-b-sonnet branch from 130400e to 370653b Compare November 23, 2026 07:28
…n the store

Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:6507fa80a17e0653;started_at=2026-11-15T17:24:44Z;surface=cli
@tbhb-agent
tbhb-agent merged commit 89c5ec2 into main Nov 23, 2026
8 checks passed
@tbhb-agent
tbhb-agent deleted the agent/gm-rec-b-sonnet branch November 23, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant