Repository navigation
feat(reconcile): repair merge counts in one pass - #90
Merged
Merged
Conversation
Generated-by: LLM effort=high;harness=codex:0.171.0;model=openai:gpt-6.2-sol;session=sha-256-64:6c7c33e05edde5dd;surface=exec
This was referenced Nov 23, 2026
tbhb-agent
added a commit
that referenced
this pull request
Nov 23, 2026
Why The reconciler pass from #90 has no caller. This change adds a loop that runs it at startup and every 15 minutes, with self-metrics and a log line per pass. It also adds the recorder test that debt row D-89a asked for. Behavior change `reconcile.Loop` runs one pass at startup and then on a 15-minute ticker. A busy pass drops ticks, so passes never overlap. Each pass gets a 14-minute deadline. An error from the pass function ends the loop and returns to the caller. Cancelling the context stops the loop after the running pass. Each pass records four metrics with no repository attribute: runs, duration, repairs, and last success time. It also writes one info log line with counts only. A later change wires `Loop` into the service. Decisions The loop takes a pass function and a clock that supplies the ticker, so tests control time and the loop doesn't depend on the signature of `Run`. The repairs metric counts merges only. Ended counts arrive with the first-end read. Deviations from the task The task asked for a requests counter. `RunResult` has no field for a request error count, so this change leaves it out. Needs human judgment None. Risk The change adds code that no binary calls, so it can't alter running behavior. The recorder test only adds coverage. Verification `bazelisk test //...` passes 33 tests, with one skipped. The lint target passes. The size check shows 368 of 400 code lines. Human steering None. Generated-by: LLM effort=high;harness=codex:0.171.0;model=openai:gpt-6.2-sol;session=sha-256-64:0041532240a38cf8;surface=exec Assisted-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:6507fa80a17e0653;surface=cli
tbhb-agent
added a commit
that referenced
this pull request
Nov 23, 2026
Why The reconciler pass from #90 repairs the merge count only. When a webhook goes missing, a pull request that closed without a merge, or that someone reopened and closed again, loses its ended count. This change reads the issue events to find each first end and records the ended count as well. Behavior change For each closed item the pass reads up to three pages of issue events. The earliest `closed` event gives the first end time. The state is `merged` when a `merged` event shares that time, otherwise `closed`. An unmerged close now records as ended only. When the events run past three pages or lack a `closed` event, the pass records the merge and leaves the ended count unclaimed. It counts the item as ambiguous. When recording fails after a clean walk, the pass clears the repository's first-page tag and keeps its watermark. The next pass then reads the page in full instead of getting a 304. An events read error follows the same rule and ends the repository's items for that pass. This closes D-90a. Decisions `Run` takes an `EndReader`, and `Lister` provides it. The reader clears each events page tag before it fetches, because the client would answer 304 with an empty body for a URL it saw before. `RunResult` gains ended outcome counts and an ambiguous count. Event pages count in `Pages`. `Run` now passes the item body to `RecordClosed`, because the cycle time starts from it. Deviations from the task The design says to read events only for items that would record an ended count. This change reads them for every closed item, including items that come back as too old or before the floor. A gate needs a ledger read before the call. That adds one events request per closed item in a walk. The debt row D-91b tracks a later fix. Needs human judgment Whether D-91b needs a fix before the scheduler goes live, given the request budget. Risk The pass has no caller until the wiring change, so this change doesn't alter a running service. The events requests use the incremental budget priority, so a sweep or a webhook retry can still take precedence. Verification `bazelisk test //...` passes 32 tests with the macOS-only deploy test failing as before. The size check shows 400 of 400 code lines. Human steering None. Generated-by: LLM effort=high;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:dd3f70854f2fb413;surface=sdk-cli Assisted-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:6507fa80a17e0653;surface=cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A missed pull request webhook can leave a merge out of the metrics. One incremental pass can find the merge and use the same milestone claim as webhook processing.
Behavior change
The pass lists the installation's repositories and walks recent pull request updates. It starts each walk at the later of the stored watermark minus five minutes and the start of the pass minus 24 hours. It submits closed, merged pull requests as repairs. The recorder applies the repair floor to each one. A watermark moves only after a complete walk and the recording of its items. The pass returns counts and a result of
ok,partial, orauth_failed.Decisions
The page count includes pull request pages returned with a 304 or a body that fails to decode. The pass skips a repository whose request ran out of retries while the run context is live. An expired context ends the pass after the current walk.
Deviations from the task
The change adds 363 Code lines, over the estimate of about 300 and within the 400-line cap.
Needs human judgment
The design assumes GitHub moves
updated_atwhen a pull request merges. That assumption still needs verification against GitHub.Risk
A capped walk still repairs the items it read and keeps its watermark for the next pass. Shared milestone claims prevent repeat walks from counting the same merge twice.
Verification
bazelisk run //:gazelleandbazelisk run //:formatpassed.bazelisk test //:golangci_lint_testpassed.bazelisk test //...reportedExecuted 32 out of 34 tests: 33 tests pass and 1 was skipped.bazelisk run @tbhb_rules//lint:pr_size -- origin/main HEADreportedpr_size: code=363/400 raw=464/1500.Human steering
The task brief scoped E1 to merge repairs and placed the first-end lookup in E2.
Generated-by: LLM effort=high;harness=codex:0.171.0;model=openai:gpt-6.2-sol;session=sha-256-64:6c7c33e05edde5dd;surface=exec
Assisted-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:6507fa80a17e0653;surface=cli