Skip to content

fix(adoption-wall): write adopter state back to the orphan branch so lastScan can advance - #398

Merged
jpr5 merged 2 commits into
mainfrom
fix/adoption-state-writeback
Sep 1, 2026
Merged

jpr5 merged 2 commits into
mainfrom
fix/adoption-state-writeback

Conversation

@jpr5

@jpr5 jpr5 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

The fuse

adopters.json on the orphan adoption-data branch was read and never written. This script had no write path, and none of the sixteen workflows wrote it either — the only branch-touching steps were a git ls-remote probe and a sparse read-only checkout. lastScan was stamped by hand once, when the branch was seeded (cd1a474, 22 repos parsed off the live wall), and nothing advanced it.

MAX_STATE_AGE_DAYS = 21. So the feature was correct today and self-destructing on ~2026-09-22: from that Monday on, every weekly run flips to NEEDS-REVIEW and opens a review PR, forever, over a wall that has not changed. MAX_STATE_AGE_DAYS was a fuse, not a guard.

RED — observed on the real surface

The real generator, run as a real child process against a sandbox repo root (stubbed fetch, no network), origin/main @ 32be6ec unmodified:

SCENARIO           : stale        (lastScan 30 days old, wall otherwise unchanged)
EXIT CODE          : 20
ADOPTION_WALL_STATUS=NEEDS-REVIEW
  ! Adopter state was last scanned 30 day(s) ago (…), past the 21-day limit: the routine
    that writes `adopters.json` on the orphan `adoption-data` branch has stopped, so the
    wall is frozen on stale data.
lastScan ADVANCED  : false     ← and it never will

And the defect itself — a fully successful run leaves the file untouched:

SCENARIO           : fresh
EXIT CODE          : 0     ADOPTION_WALL_STATUS=CLEAN     Data changed: false
lastScan BEFORE    : 2026-08-31T07:35:54.344Z
lastScan AFTER     : 2026-08-31T07:35:54.344Z
lastScan ADVANCED  : false

Run twice over one sandbox on unmodified main, the stale state never recovers: FIRST exit=20 … EXIT CODE: 20, lastScan ADVANCED: false.

GREEN — same harness, this branch

=== fresh ===       exit 0   CLEAN            ADOPTION_STATE_WRITTEN=true   lastScan ADVANCED: true
=== stale ===       exit 20  NEEDS-REVIEW     ADOPTION_STATE_WRITTEN=true   lastScan ADVANCED: true

and the recovery, twice over one sandbox:

FIRST  exit=20  lastScan=2026-09-01T07:36:28.672Z
SECOND exit=0   ADOPTION_WALL_STATUS=CLEAN   ADOPTION_STATE_WRITTEN=true
docs/index.html CHANGED BY RUN(S): false

The second run is CLEAN, so nothing is written to docs/ and the workflow has nothing to commit to main.

A failed scan must not stamp freshness

This is the property the whole change turns on: if a run that could not resolve the list stamps lastScan anyway, the staleness guard stops measuring how recently the DATA was confirmed and starts measuring how recently the JOB RAN — which it can already tell. Both failure shapes, on the real surface:

=== probe429 ===    (avatar CDN answers 429 — the probe reaches no verdict)
exit 20   ADOPTION_STATE_WRITTEN=false
⚠ Adopter state was NOT refreshed and `lastScan` did not advance: 8 avatar probe(s)
  reached no verdict (timeout, 429 or 5xx) …
lastScan ADVANCED  : false

=== incomplete ===  (one repo answers 200 but without `fork` — GREEN VERDICT, stamp still withheld)
exit 0    CLEAN   ADOPTION_STATE_WRITTEN=false
⚠ … 1 repo(s) returned no usable metadata, so this run did not resolve the whole
  adopter list: flaky/repo
lastScan ADVANCED  : false

A rate-limited metadata pass never reaches the write at all: both fetch paths already throw on 403/429/5xx and main() exits 1.

Design, and why

Written on all three verdicts (0 / 10 / 20), gated on the SCAN and never on the status. lastScan records that the adopter list was resolved, which is a different question from whether a human should look at the result. A dead avatar, a vanished adopter, a wall under its floor — those are things the run FOUND OUT, and a run that found something out scanned fine. Gating on status would be actively harmful: the first dead logo freezes lastScan, and three weeks later every run carries a second, invented staleness reason on top of the real one — and the workflow only carries three reasons into Slack, so the invented one displaces the real cause from the one line a human reads. The runs that must not stamp are the ones that did not learn the answer, and that is exactly what scanIsConclusive tests. A corrupt or missing state file never reaches the write path at all.

missedRuns keeps the semantics the reader already relies on (> 0 ⇒ not a candidate):

  • resolved by this scan → 0, unconditionally (a repo that comes back is back)
  • definitively absent (GraphQL NOT_FOUND, REST 404/451) → previous + 1
  • neither → carried through unchanged. Two populations land here and both must be left alone: entries already at missedRuns > 0, which are filtered out before the API is asked and so were never looked at; and entries whose repo is not owner/name. Incrementing a repo nobody looked at manufactures evidence of a disappearance, and three of those in a row drops an adopter off a public page for no reason.

That distinction did not exist before: fetchRepoMeta yielded no meta for both a 404 and a reply missing fork, and the two were indistinguishable downstream. They are now split (MetaResolution.indeterminate), which is what makes "could not tell" safe.

Entries absent from the latest scan are never deleted. They keep their row, their firstSeen and a rising counter, so a repo that reappears is recognised as the same repo. isFork, channels and firstSeen are carried through verbatim — overwriting isFork with the API's answer would make the fork-disagreement report self-cancelling, erasing the very evidence it exists to surface. Entries are sorted by repo so the orphan branch's weekly diff is the delta, not a reshuffle.

Writing state pushes nothing to main. The new workflow step runs inside the orphan-branch checkout, stages one named file (never git add -A), and pushes to refs/heads/adoption-data named in full. adoption-data stays a true orphan: it is a checkout of that branch in its own gitignored directory, so no repo history and no repo files can reach it. Guard adoption-data naming is untouched and still passes (verified locally). No retry, no rebase, no force — this job is the branch's only writer and concurrency serialises it against itself, so a rejected push means someone else wrote there; it fails loudly and lastScan simply does not advance that week, which is the safe direction and leaves three weeks of budget.

cacheplane/dawnai

Root cause: the branch was seeded by parsing the live wall, which can only ever contain repos that were already rendering. cacheplane/dawnai is a curated adopter sitting below the wall's cut, so the parse could not see it — and because the file is also the candidate list, a repo missing from it could never climb back on. missingFromState reported the gap every week and nothing could close it.

The producer's state now derives from the scan: withKnownAdopters seeds every ADOPTER_DISPLAY key the incoming file does not mention into the scan itself, so they are resolved from the API, ranked on their real numbers, and written back with whatever the scan actually found. missedRuns: 0 there is an INPUT meaning "ask about this one", not an assertion — buildNextState overwrites it with the scan's answer, and if the scan was inconclusive nothing is persisted. missingFromState still reports against the incoming file, so it keeps describing what the upstream producer failed to discover instead of answering "none" every time.

Tests

25 new cases. Each was observed FAILING under a targeted mutation and passing with the fix restored (script byte-identical after restore, verified with cmp):

Mutation Red
the stamp is never withheld 2 failed — both "does NOT advance lastScan" cases
the write removed (the shipped defect) 5 failed — advances / recovers / NEEDS-REVIEW-still-refreshes / absent-repo / curated-writeback
unscanned entries incremented 1 failed — "leaves a repo it never looked at exactly as it found it"
indeterminate tracking removed 3 failed — REST + GraphQL definitive-vs-not, and the no-usable-metadata run
curated seeding removed 3 failed — both withKnownAdopters cases and the curated write-back

Gates (raw exit codes)

Gate Code
prettier --check . 0
npx eslint . 0
npx tsc --noEmit 0
npx vitest run 0 — 5592 passed / 46 skipped (baseline 5567/46; +25 new)
actionlint .github/workflows/update-adoption-wall.yml 0
npx commitlint --from origin/main --to HEAD 0

🤖 Generated with Claude Code

https://claude.ai/code/session_01AvkmhXVLqSSEW6FvPQHSu5

jpr5 added 2 commits September 1, 2026 00:43
The state file was read and never written. No workflow wrote it, this script
had no write path, and `lastScan` was stamped by hand once when the orphan
branch was seeded. MAX_STATE_AGE_DAYS was therefore a FUSE, not a guard: every
run green until the seed aged past 21 days, then NEEDS-REVIEW and a review PR
every Monday forever, over a wall nothing had changed.

The run now writes the state it read, gated on the scan and on nothing else.
A fresh `lastScan` is a claim that this run resolved the whole adopter list, so
it is withheld whenever the run reached no verdict: a repo that answered without
the facts the ranking needs, or an avatar probe that timed out or was throttled.
A definitely-dead logo is the opposite and does not withhold it — that is a
finding, and a run that established one scanned fine. Rate-limited metadata
never gets here at all; both fetch paths already throw and exit 1.

`missedRuns` keeps its meaning: 0 for a repo that came back, +1 for one the API
definitively does not have, and UNCHANGED for one this run never looked at.
Nothing is ever deleted, and `isFork` is carried through verbatim so the fork
disagreement report is not quietly self-cancelling.

The scan is also seeded from ADOPTER_DISPLAY. The branch was seeded by parsing
the live wall, which can only contain repos already rendering, so a curated
adopter below the cut -- cacheplane/dawnai -- was absent from the file and,
because the file is the candidate list, could never climb back onto the wall.
…ta branch

The generator's write is only half a producer: without this the refreshed file
is rewritten in the runner's checkout and thrown away with it, and `lastScan`
never moves.

Pushes to refs/heads/adoption-data and nothing else. It runs inside the
orphan-branch checkout, stages one named file rather than `git add -A`, and
names the destination ref in full, so it cannot reach the default branch and
cannot carry repo files onto a branch that holds nothing but adopters.json.

Gated on the generator's own ADOPTION_STATE_WRITTEN flag, not on the verdict:
a NEEDS-REVIEW run that resolved the whole list still refreshes state. Placed
before the docs/ steps so a failed state push stops the job with nothing landed
half-done. No retry, no rebase, no force -- this job is the branch's only writer
and `concurrency` serialises it against itself, so a rejected push means someone
else wrote there and re-applying over it would delete their work.

Slack says so when a run did not refresh the state, because the verdict, the
diff and the logo count can all look ordinary while `lastScan` stops moving.
@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@398

commit: 4046292

@jpr5
jpr5 merged commit 654e38d into main Sep 1, 2026
26 checks passed
@jpr5
jpr5 deleted the fix/adoption-state-writeback branch September 1, 2026 07:48
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