Skip to content

feat(reconcile): repair merge counts in one pass - #90

Merged
tbhb-agent merged 1 commit into
mainfrom
agent/gm-rec-e1-codex
Nov 23, 2026
Merged

tbhb-agent merged 1 commit into
mainfrom
agent/gm-rec-e1-codex

Conversation

@tbhb-dev-agent-pull-requests

@tbhb-dev-agent-pull-requests tbhb-dev-agent-pull-requests Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

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, or auth_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_at when 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 //:gazelle and bazelisk run //:format passed.
  • bazelisk test //:golangci_lint_test passed.
  • bazelisk test //... reported Executed 32 out of 34 tests: 33 tests pass and 1 was skipped.
  • bazelisk run @tbhb_rules//lint:pr_size -- origin/main HEAD reported pr_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

Generated-by: LLM effort=high;harness=codex:0.171.0;model=openai:gpt-6.2-sol;session=sha-256-64:6c7c33e05edde5dd;surface=exec
@tbhb-agent tbhb-agent changed the title Repair merge counts in one reconciler pass feat(reconcile): repair merge counts in one pass Nov 23, 2026
@tbhb-agent
tbhb-agent merged commit 7a2b630 into main Nov 23, 2026
8 checks passed
@tbhb-agent
tbhb-agent deleted the agent/gm-rec-e1-codex branch November 23, 2026 11:17
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
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