Skip to content

Learning loop: a pull request scorecard, lessons from people's edits, closes and reverts, reviewer asks, and guide pull requests - #652

Closed
nambok wants to merge 4 commits into
mainfrom
learning-loop
Closed

nambok wants to merge 4 commits into
mainfrom
learning-loop

Conversation

@nambok

@nambok nambok commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

CoderHelm gets a learning loop for the pull requests it opens. What becomes of each one is counted from the webhooks as they arrive, what people do with one (their own commits on top, the comment they close it with, the reason they revert it) becomes a lesson the next run is given, what each reviewer keeps asking for is given to the build when that reviewer is likely to review the change, and lessons seen on several pull requests are proposed for the repository's guide file as a pull request the team reviews.

Most of the machinery was already there and is reused: outcome events (common::rewards), the lessons store with its half-life, the change log an admin can turn off, the run reading the repository's guide files every run. This adds what was missing on top of it.

No new tables, indexes or permissions. Every record is on the settings table under the team's own key.

Changes

Scorecard (common::scorecard, gateway/routes/scorecard.rs)

  • Per repository and per team: opened, merged, closed without merging, reverted, review rounds to approval, time from open to merge, merged after a person's commit, finished with open items.
  • One small record per pull request (SCOREPR#), changed by the webhooks: opened, reopened, a person's review, a person's push to its branch, closed or merged, a revert pull request or a revert commit naming it.
  • Every change adds the difference between what the record counted for before and after to the counters (SCORE#<month or ALL>#T and #R#<repo>), in the transaction that writes the record and only when the record is still the one that was read. A redelivered or late event counts nothing twice, events may arrive in any order, and nothing is recomputed by reading runs.
  • A pull request counts in the month it was opened. Guide pull requests and people's pull requests are not counted.
  • The worker counts a close the webhook missed when the reconcile sweep hands it over.
  • GET /api/learning/scorecard?months=N&repo= (months=0 is all time). A rate with nothing behind it is null, never zero.

Lessons from outcomes (common::rewards::lessons, worker/passes/outcome_learning.rs)

  • When people push commits on a CoderHelm pull request before merging, close one with a comment, or revert one with a reason, the worker reads their words and the lines they changed and asks the team's model for at most one lesson. One call per closed pull request, none when there is nothing to learn from.
  • A lesson is kept only when it is specific and checkable, enforced in code: it names code, says how to check a change against it, is not advice that fits any change, and is not about a person.
  • It goes through the existing lessons store with the evidence attached (what happened, people's words, their changed lines), is counted once per pull request, and reinforces the kept lesson that says the same.
  • A lesson a later outcome contradicts loses weight; contradicted as often as confirmed, it is no longer recalled. Lessons still fade with the existing half-life.
  • A revert now writes the area's lesson again and carries the reason people gave. A revert made with git revert (a commit naming the merge commit) is recognised as well as GitHub's revert pull request.
  • Only people with standing in the repository are read (owner, member, collaborator).

Reviewer asks (common::reviewer_prefs)

  • What each reviewer asked for on CoderHelm's pull requests is distilled into general asks, kept per reviewer login within the team with the pull requests they were seen on.
  • Review-relevant only: a fixed list of categories, mentions, addresses and links removed, anything about a person dropped, never the reviewer's comments themselves, never a login the model made up.
  • An ask seen on two pull requests is given to the build and to CoderHelm's review of its own pull request when that reviewer is a likely reviewer: a code owner of the files, or someone who reviewed that part of the repository in the last 120 days.
  • GET /api/learning/reviewers lists them; POST /api/learning/reviewers/forget (admins) forgets one ask or everything kept about a reviewer.

Guide file (common::guide, worker/passes/guide_pr.rs)

  • The run already read AGENTS.md, CLAUDE.md and the other agent files every run; it now reads CONTRIBUTING.md too, last, under the same byte cap.
  • A lesson seen on two pull requests, never contradicted and not turned off, is proposed for the guide file: one commit on a new branch and one pull request whose description names each lesson with the pull requests and evidence behind it. Nothing is ever written to the default branch.
  • Rate limited by one record per repository: at most one guide pull request open, 14 days after one merges, 60 days after one is closed without merging (doubling when closed again). The record is claimed before anything is written to GitHub, so two workers open one.
  • When it closes: lessons still in the merged file are marked as in the guide and leave the prompt; lessons people removed, or all of a closed one, are declined, never proposed again, and count as contradicted once.
  • A team can turn guide pull requests off, for every repository or for one (GET and PUT /api/settings/guide-prs; on unless turned off, a repository's own setting wins). The switch is read before anything is claimed or created: off, no branch, commit or pull request is made and lessons still reach the prompt. A switch that cannot be read counts as off.
  • A guide pull request says where it comes from: its title starts "CoderHelm lessons:", its description opens by saying so, and it carries the coderhelm-lessons label.
  • CoderHelm's reviewer leaves a guide pull request to the team: the gateway queues no review job for one, and the worker's review ends before any model call with a neutral check. No findings are written into its description and no fix round is asked for.
  • GET /api/learning/lessons lists the coder's lessons with their evidence and state, and each repository's guide pull request.

Shared files touched, kept small

  • worker/src/passes/mod.rs: two pub mod lines, and CONTRIBUTING.md in INSTRUCTION_FILES.
  • worker/src/passes/review_pr.rs: the own-review context gets the likely reviewers' asks (one block).
  • worker/src/passes/incidents/ac_partial_and_red_ci.rs: guide_pr.rs joins the list of places that may open a pull request, as the guide pull request and not a run's.
  • gateway/src/routes/github_webhook.rs: calls into routes/scorecard.rs at opened, reopened, closed, a person's review and a push; the revert handler passes the reason on.
  • resume.rs and implement.rs are not touched.

Not in this change

  • No backfill: the scorecard counts from the release on, and the page says when counting began.
  • No new loop on the learning health check; outcome lessons feed the existing coder lessons loop.

Verification

Run locally on this branch (both commits), at main 9582ee99:

  • cargo fmt --check --all: clean.
  • cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test --workspace -- 'incidents::': 166 passed, 0 failed.
  • cargo test --workspace -- 'replay::': 5 passed, 0 failed.
  • cargo test --workspace -- --skip 'incidents::' --skip 'replay::': common 2124, gateway 906, worker 1465 passed, 0 failed.

What the tests cover:

  • Scorecard: a merge delivered three times counts once; a merge arriving before its open; closed, reopened, merged; a late close never undoing a merge; review rounds before the first approval; a person's push found by branch and GitHub's count winning over it; a revert by pull request and by commit, once, only against a merged pull request; open items; a write that loses a race reading again; teams and repositories never sharing a counter; the view giving null where nothing is behind a rate.
  • Lessons: specific and checkable is enforced (vague, naming nothing, no check, about a person are refused); one lesson per rule however worded, each pull request counted once; contradiction demotes then retires; lists stay bounded; a lesson reaches the guide only with confidence; the written item reads back as written.
  • Reviewer asks: only review-relevant asks from people who did review, nothing personal, no login the model made up; counted once per pull request; given only when repeated, recent and the reviewer is likely.
  • Guide: one pull request, never a write to the default branch (the fake repository records every write's branch); at most one open; two workers open one; a failure at GitHub is retried the next day; a merged one marks what stayed and declines what people removed; a closed one pauses proposals.
  • Guide switch: off for the team, off or on for one repository against the team, a switch that cannot be read, and one turned off while a guide pull request is open; each checks that nothing reached the repository and the lesson is still recalled.
  • Incident case al_learning_loop replays the whole loop on the fixture repository with webhook payloads in GitHub's shapes and recorded model replies read by the real parser, and checks the pipeline still calls each piece at its place. docs/incidents.md has its row.
  • The gateway holds its webhook handler to feeding each event (routes::scorecard::tests).

Not verified live: nothing here ran against GitHub, DynamoDB or a model. The DynamoDB transaction in scorecard::Dynamo::commit, the lesson and reviewer updates in the stores, and the real GitHub calls of guide_pr::GitHubRepo are exercised only through their in-memory stand-ins. The dashboard change is CoderHelm/coderhelm#406; its sections stay hidden until a gateway with these routes is deployed.

… closes and reverts, reviewer asks, and guide pull requests

What becomes of every pull request CoderHelm opens is now counted, and what
people do with one teaches the next run.

Scorecard (common::scorecard). Per repository and per team: opened, merged,
closed without merging, reverted, review rounds to approval, open to merge,
merged after a person's commit, finished with open items. Each pull request
has one small record the webhooks change (opened, a person's review, a
person's push to its branch, closed or merged, reopened, a revert pull
request or revert commit naming it). Every change adds the difference
between what the record counted for before and after to the counters, in
the transaction that writes the record, so a redelivered or late event
counts nothing twice and nothing is recomputed by reading runs. The worker's
reconcile path counts a close the webhook missed. GET
/api/learning/scorecard serves it.

Lessons from outcomes (common::rewards::lessons, passes::outcome_learning).
When people push commits on top of a CoderHelm pull request, close one with
a comment, or revert one with a reason, the worker reads their own words
and the lines they changed and asks the team's model for at most one lesson.
A lesson is kept only when it names code and says how to check a change
against it. It goes through the existing lessons store with the evidence
attached, is counted once per pull request, reinforces the kept lesson that
says the same, and counts against the kept lessons it contradicts, which
lose weight until they are no longer recalled. A revert now writes the
area's lesson again and carries the reason; a revert by commit is
recognised as well as GitHub's revert pull request. Only people with
standing in the repository are read.

Reviewer asks (common::reviewer_prefs). What each reviewer asked for on
CoderHelm's pull requests is distilled into general asks kept per login
within the team, in a fixed list of review categories, with mentions,
addresses and links removed and anything about a person dropped. An ask
seen on two pull requests is given to the build and to CoderHelm's review
of its own pull request when that reviewer is a code owner of the files or
reviewed that part of the repository recently. The team can list the asks
and forget a reviewer or one ask.

Guide file (common::guide, passes::guide_pr). The run already reads the
repository's guide files every run; CONTRIBUTING.md is now read too. A
lesson seen on two pull requests and never contradicted is proposed for
the guide file as a pull request of its own: one commit on a new branch,
never a write to the default branch, at most one open per repository, with
a pause after one merges and a longer one after one is closed. When it
closes, lessons still in the merged file are marked as in the guide and
leave the prompt; lessons people removed, or all of a closed one, are
declined and count as contradicted.

No new tables, indexes or permissions: every record is on the settings
table under the team's own key.
… and no review by CoderHelm of its own lessons

A team can turn guide pull requests off, for every repository or for one
(SETTINGS#GUIDE_PRS; on unless turned off, a repository's own setting wins
over the team's). The switch is read before anything is claimed, read from
GitHub or created: off, there is no branch, no commit, no pull request and
no claim on the repository's record, and lessons reach the prompt exactly
as before. A switch that cannot be read counts as off. A guide pull request
already open when the switch goes off is still settled when it closes.
GET and PUT /api/settings/guide-prs serve it; saving needs the learning
capability's admin role.

A guide pull request says where it comes from three ways: its title starts
"CoderHelm lessons:", its description opens by saying it comes from
CoderHelm's lessons and not from a ticket and that an admin can turn these
off, and it carries the coderhelm-lessons label.

CoderHelm's reviewer leaves a guide pull request to the team. Before this,
a repository with the reviewer on would have reviewed it as CoderHelm's own
pull request once it carried the review label or someone asked: findings
written into its description as open, with no run behind it to fix them.
Now the gateway queues no review job for one, and the worker's review ends
before any model call with a neutral check that says it is for the team to
review, whatever started it.
Both sides added a module to common, an incident case and its row in docs/incidents.md; all are kept.
Both sides added an incident case and its row in docs/incidents.md; all are kept.
@nambok nambok closed this Nov 13, 2026
@nambok
nambok deleted the learning-loop branch November 13, 2026 17:20
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