Repository navigation
Description
Problem
The Service polls GitHub for state that GitHub already pushes as webhooks. Its 4000-request hourly budget binds all day (693 holds in 24 hours on 2026-11-16, #6012), and about 1700 requests an hour come from loops that name no row; about 170 an hour go to each of 6 Service repositories that have little work. Each row reads the same issue and pull request data again (labels, body, state, checks, mergeable state), so the same object is fetched several times between two changes.
Owner, 2026-11-16: "that's why I want more webhook drive workflows over polling workflows and the project brain to cache gh isssue data when it is updated, which could save some repeated gh requests".
Expected behavior
- The project brain keeps a cache of the GitHub objects that the rows read: issues (title, body, labels, state, update time, the roadmap record), pull requests (head, base, draft, labels, mergeable state, linked item) and the check state of each head, for each Service repository.
- A webhook (
issues,issue_comment,label,pull_request,pull_request_review,check_suite,check_run,status,push) updates the cached object at once from the event payload, and wakes the lane of the job that needs it (feat(service): webhook events wake the lanes of their jobs #5555, feat(roadmap): PR, review and check events start a scoped sweep #4413). - Each row reads the cache first. It reads GitHub only on a miss, for a write, or when the cached object is older than a limit. A write by the Service updates the cache too.
- The cache is eventually consistent with a local fallback (owner rule of 2026-11-11): when Valkey is offline, a row reads GitHub as today. A slow reconcile poll (for example each hour, with conditional requests
If-None-Matchso a 304 costs no rate limit) repairs missed or redelivered events (feat(service): redeliver webhook deliveries that failed #4560). - Metrics: cache hits and misses for each row, and GitHub requests for each row (fix(service): Name the row of each GitHub request and cut the waste #6012). Target: the budget holds rounds fewer than 10 times an hour at today's job load, and the 6 quiet repositories cost less than 20 requests an hour each.
- The keys follow the cache-key rules of docs(adr): Valkey keys are coordination keys or cache keys #5245.
Related
- fix(service): Name the row of each GitHub request and cut the waste #6012 (name the row of each request; measure the waste first), feat(service): webhook events wake the lanes of their jobs #5555, feat(roadmap): PR, review and check events start a scoped sweep #4413, feat(roadmap): handle closed plan PRs from GitHub webhooks #4414, feat(roadmap): handle trusted issue_comment webhook replies #4415, feat(roadmap): comment releases from GitHub release webhooks #4416, feat(service): redeliver webhook deliveries that failed #4560, feat(service): make the webhook router stateless #4575, feat(service): share the GitHub budget and holds in Valkey #4563 (share the budget in Valkey), feat(roadmap): track the project brain #4624 (project brain), docs(adr): Valkey keys are coordination keys or cache keys #5245, feat(service): give each roadmap pod an hourly request budget #5497.
Alternatives check of 2026-11-17: rejected.
Rejected by ADR 0023. A newer fact can change an ADR.
Tool: karpetrosyan/hishel (https://github.com/karpetrosyan/hishel), BSD-3-Clause, last activity 2026-11-10, maintained.
Reason: hishel caches HTTP answers with ETag revalidation and pluggable stores, covering only the conditional reconcile; it has no webhook writes, GitHub object schema or per-row read-through, and ADR 0023 rejected it for token-private GitHub answers.
Covers:
- HTTP response cache with stored ETag validators
- If-None-Match requests answered by 304 with no body
- Pluggable storage backends such as Redis
Lacks:
- No webhook payload to cached object write
- No GitHub issue, pull request or check schema
- No per-row read-through, reconcile schedule or cache counters
Proposed design
Problem statement
The Service polls GitHub for issue, pull request and check state that GitHub already pushes as webhooks. The 4000-request hourly budget binds all day, and rows read the same object again. This change adds one project-brain cache entry for each GitHub object that a row reads, scoped to its Service repository. Webhooks write the entry, rows read it first, and a slow reconcile with conditional requests repairs missed events. A row falls back to GitHub when Valkey is offline.
Acceptance criteria
Requirement: Brain caches row GitHub objects
The project brain SHALL hold one cache entry for each issue, pull request and head check state that a Service row reads, scoped to its Service repository.
Scenario: A row reads a cached issue
- WHEN A row asks the brain for an issue that a fake webhook has already cached.
- THEN The brain returns the title, body, labels, state and update time of that issue, and the fake GitHub client receives no request.
Requirement: Webhook writes cached issue and wakes row
A subscribed webhook event MUST write its object into the brain from the event payload before the Service wakes the lane of the job that needs it.
Scenario: A labeled issue event updates the cache and wakes the row
- WHEN The webhook router receives an
issuesevent with actionlabeledfor a cached issue. - THEN The fake brain store holds the new label set with the event time, and the fake lane trigger records one wake for the due row.
Requirement: Webhook writes cached pull request
A pull_request webhook event MUST write the pull request head, base, draft state and labels into the brain.
Scenario: A pull request event updates the cache
- WHEN The webhook router receives a
pull_requestevent with actionsynchronizefor a cached pull request. - THEN The fake brain store holds the new head SHA, base and draft state from the event payload, and the fake GitHub client receives no request.
Requirement: Brain caches head check state
The project brain SHALL hold the check state of each pull request head that a row reads.
Scenario: A row reads cached check state
- WHEN A row asks the brain for the check state of a head that a fake reconcile has already cached.
- THEN The brain returns the check suite and check run states, and the fake GitHub client receives no request.
Requirement: Row reads cache before GitHub
Each row MUST read the brain before GitHub and MUST read GitHub only on a cache miss, for a write, or when the cached object is older than one hour.
Scenario: A miss reads GitHub once and fills the cache
- WHEN A row reads an object that the fake brain does not hold.
- THEN The row reads the fake GitHub once, writes the object into the brain, and counts one cache miss.
Requirement: Service write updates cache
A write that the Service makes to GitHub MUST write the same object into the brain.
Scenario: A label write fills the cache
- WHEN The Service adds a label to an issue through the fake GitHub client.
- THEN The fake brain holds the new label set before the fake webhook for that label is delivered.
Requirement: Row falls back to GitHub when Valkey is offline
When Valkey is offline, a row MUST read GitHub as today and MUST NOT fail its round on the cache.
Scenario: The brain store refuses a connection
- WHEN The fake brain store raises a connection error during a row round.
- THEN The row reads the fake GitHub, the round returns its normal result, and the Service logs and counts the cache outage.
Requirement: Reconcile reads each object at most hourly
The reconcile poll MUST read each cached object at most once an hour with a conditional request.
Scenario: A second reconcile in the same hour skips the object
- WHEN The reconcile poll runs twice within one hour for the same cached object.
- THEN The second run sends no GitHub request for that object.
Requirement: A 304 leaves the cache unchanged
A 304 answer MUST leave the cached object unchanged and MUST NOT spend GitHub's primary rate limit.
Scenario: A 304 answer keeps the stored object
- WHEN The reconcile poll sends
If-None-Matchwith the stored validator and the fake GitHub transport answers304. - THEN The cached object stays as it is, the fake ledger records the attempt in the Service's own window and no spent primary-limit unit.
Requirement: Cache hit and miss counters
The Service MUST count cache hits and cache misses for each row and MUST count the GitHub requests of each row.
Scenario: A cache hit is counted
- WHEN A row reads a cached object that the brain holds and that is not stale.
- THEN
devops_cli_brain_cache_total{row="refine",result="hit"}increases by one, and the GitHub request counter of that row does not change.
Requirement: Brain cache keys follow the brain key form
Each brain cache key MUST be roadmap:v1:brain-<kind>:<owner>/<name>[:<id>], built by RepoRef.valkey_key, with no empty part and no glob character.
Scenario: A key names its repository and object
- WHEN The brain builds a key for an issue of a Service repository.
- THEN The key is
roadmap:v1:brain-issue:<owner>/<name>:<number>, andRepoRef.valkey_patternsfinds it and no key of another repository.
Requirement: Quiet Service repository stays inside request budget
A Service repository with little work MUST cost fewer than 20 GitHub requests an hour.
Scenario: One simulated hour of a quiet repository
- WHEN A test runs the rows of a quiet Service repository for one simulated hour with a fake clock and a fake GitHub client that counts requests.
- THEN The fake GitHub client records fewer than 20 requests for that repository.
Existing Tool Considered
The alternatives check in the issue body (2026-11-17) records a rejected verdict for hishel (https://github.com/karpetrosyan/hishel) under ADR 0023. The block lists what hishel covers and lacks. This proposal does not adopt hishel; it uses the project brain in Valkey for storage and adds the webhook-to-object write, the GitHub object schema, the per-row read-through, the reconcile schedule and the cache counters. The project builds that code itself: about 40,000 tokens to build it, about 15,000 tokens a month to keep and fix it, and about 3 days of elapsed work.
Key questions
- Where does the brain keep the cache of GitHub objects?: In
valkey-roadmap, under the brain key formroadmap:v1:brain-<kind>:<owner>/<name>[:<id>]thatRepoRef.valkey_keybuilds, with a TTL on each key. (best practice) [sources: CONTEXT.md, docs/adr/0023-the-project-brain-is-a-derived-index-in-two-cache-tiers-and-two-scheduled-runs-keep-it.md, src/devops_cli/github/repo_ref.py, docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]- Chosen:
valkey-roadmapunder the brain key form. The brain holds the caches of GitHub answers. ADR 0023 names the brain keys, andRepoRef.valkey_keyis the recorded builder of a repository-scoped key. - Rejected:
valkey-devopsundervalkey:cache keys. No record builds a repository-scopedvalkey:key. The instance prefix is the namespace, andvalkey-devopskeys start withvalkey:. - Rejected: A JSON file in the Service home. Each lane and each pod needs the same object, and a file has one writer on one host.
- Rejected: GitHub itself. That is the poll that this item removes.
- Chosen:
- Which route ingests the webhook events into the cache?: The existing webhook router and its roadmap consumer. The consumer's
eventsset is the subscription, and each repository's hook must name the events it sends. Add no second route. (best practice) [sources: docs/adr/0009-one-webhook-router-delivers-each-event-to-the-consumers-subscribed-to-it.md, docs/CLUSTER.md]- Chosen: Extend the existing router and roadmap consumer. ADR 0009 builds one router with one consumer for each subscriber. The roadmap consumer already takes
issues,pull_request,milestoneandrelease. - Rejected: A second webhook route for the cache. ADR 0009 rejects a second route. The existing receiver is extended instead.
- Chosen: Extend the existing router and roadmap consumer. ADR 0009 builds one router with one consumer for each subscriber. The roadmap consumer already takes
- Does the Service still poll GitHub for the cached objects?: Yes. The poll becomes a slow reconcile with conditional requests and repairs a missed or redelivered event. The sweep keeps its 5-minute schedule for the due marks. (best practice) [sources: docs/adr/0017-each-subscribed-webhook-event-runs-the-update-scoped-to-it.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
- Chosen: Keep a slow reconcile poll with conditional requests. ADR 0017 keeps the poll as the reconcile, and GitHub never retries a failed delivery.
- Rejected: Webhooks only. A missed delivery would never repair, and the cache would stay wrong.
- How old may a cached object be before a row reads GitHub again?: One hour, the interval of the reconcile. (best practice) [sources: docs/adr/0023-the-project-brain-is-a-derived-index-in-two-cache-tiers-and-two-scheduled-runs-keep-it.md, docs/adr/0017-each-subscribed-webhook-event-runs-the-update-scoped-to-it.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md]
- Chosen: One hour, the reconcile interval. The reconcile reads each entry at most once an hour, so the row and the reconcile do not read the same object twice in one hour. The six quiet repositories stay inside the 20-request target.
- Rejected: The row interval of the due table. A short row would read GitHub again on each round and spend the budget that this item saves.
- Rejected: 24 hours, the bound of the listing snapshot. ADR 0023 drops a listing copy whose last full read is older than 24 hours. A missed webhook would leave an object wrong for a day.
- Rejected: No limit. A missed webhook would leave the entry wrong with no repair.
- Which cache key scheme do the brain entries use?: The brain key form of ADR 0022 section 5 as ADR 0023 section 3 restates it:
roadmap:v1:brain-<kind>:<owner>/<name>[:<id>], built byRepoRef.valkey_key(for examplebrain-issue,brain-pr,brain-check). The repository holds no text of docs(adr): Valkey keys are coordination keys or cache keys #5245, so the key rule in force is the ADR andRepoRef. (best practice) [sources: src/devops_cli/github/repo_ref.py, docs/adr/0022-one-repository-reference-names-the-objects-labels-and-keys-of-each-repository.md, docs/adr/0023-the-project-brain-is-a-derived-index-in-two-cache-tiers-and-two-scheduled-runs-keep-it.md, openspec/specs/repository-names/spec.md]- Chosen: The brain key form of ADR 0022 section 5. It is the recorded key form of
valkey-roadmap.RepoRefbuilds it, and the repository part holds the only/, so the two patterns of a repository find its entries and no other's. - Rejected: A new scheme for the brain. Two schemes for one store make the keys of the same object differ, and no record builds a repository-scoped
valkey:key.
- Chosen: The brain key form of ADR 0022 section 5. It is the recorded key form of
- Which names do the cache counters use?:
devops_cli_brain_cache_totalcounts a hit or a miss for each row, beside the existing per-row GitHub request counterdevops_cli_github_requests_total. (best practice) [sources: docs/CLUSTER.md]- Chosen: Follow the existing counter naming with a row label. The Service already counts GitHub requests per row under
devops_cli_github_requests_total, and the samerowlabel keeps the two series together. - Rejected: A separate metrics namespace. A second naming rule for the same Service makes the dashboards harder to read.
- Chosen: Follow the existing counter naming with a row label. The Service already counts GitHub requests per row under
- Which webhook events update the cache?: The first version writes the cache from
issuesandpull_requestevents.labelis an action ofissues, not an event.issue_comment,pull_request_review,check_suite,check_run,statusandpushhave no roadmap consumer subscription today, and each repository's hook does not send them; their cache writes are deferred to a new issue. Check state is still read on a miss and by the hourly reconcile. (best practice) [sources: docs/adr/0009-one-webhook-router-delivers-each-event-to-the-consumers-subscribed-to-it.md, docs/CLUSTER.md, src/devops_cli/config/constants.py]- Chosen: Write from
issuesandpull_requestnow, and defer the other events. The roadmap consumer already takesissuesandpull_request. The other events need a consumer subscription and a person to change each repository hook. - Rejected: Add all listed events in this change. No subscriber exists for the check, comment and push events, and a person must change each repository hook. This would block the core cache.
- Chosen: Write from
- Where does the reconcile keep the validator for its conditional request?: With the object in its brain entry (the
ETagand the update time), and the reconcile sends it asIf-None-Match. Until the two-token probe of ADR 0021 section 6 passes, the reconcile reads that object in full once an hour. (best practice) [sources: docs/adr/0023-the-project-brain-is-a-derived-index-in-two-cache-tiers-and-two-scheduled-runs-keep-it.md, docs/adr/0021-the-roadmap-service-is-a-webhook-router-cluster-pods-run-the-roadmap-jobs-and-valkey-holds-their-shared-state.md, src/devops_cli/github/session_transport.py, docs/adr/0006-github-session-requests-go-through-gidgethub.md]- Chosen: The validator goes in the brain entry with the object. The gidgethub ETag store is in process and dies with the pod, so a restarted pod would read every object in full. The entry's validator survives the pod.
- Rejected: The in-process gidgethub store alone. A pod restart loses every validator, and the first reconcile after a restart reads each object in full.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 16, 2026
The Service hits GitHub rate limits 693 times per day, causing job holds and degraded throughput.Both reduce counted GitHub requests via Valkey, but #4668 shares listing snapshots and PyPI facts while the candidate caches issue and PR state updated by webhooks.devops-cli-service commentedon Nov 16, 2026
Owner question: Who adds the events to each repository's webhook? (a person decides)
Options
Recommendation: Decide the question: only a person can answer it.
Evidence
devops-cli-service commentedon Nov 17, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (6)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 20, 2026
Owner question: See the first point of Open questions in the section Proposed design of the body.
Options
Recommendation: Decide the question: only a person can answer it.
Evidence
devops-cli-service commentedon Nov 21, 2026
Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.
6 remaining items
feat(service): cache GitHub issue state in the brain from webhooks (#…
test(roadmap): cover issue revalidation and shared-only mapping (#6013)
devops-cli-service commentedon Nov 24, 2026
Released in v0.209.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.209.0
devops-cli-service commentedon Nov 24, 2026
Live since 2026-11-24 13:45 UTC
fix(roadmap): the brain issue cache follows the shared-tier rules (#7297