Skip to content

stewards: tier the lesson lifecycle and apply its transitions (BB-35 step 3) - #94

Merged
trotterdylan merged 2 commits into
mainfrom
bb/bb-35-step-3-tier-migration-transitions-digest-thr_85k58yk95i
Oct 26, 2026
Merged

trotterdylan merged 2 commits into
mainfrom
bb/bb-35-step-3-tier-migration-transitions-digest-thr_85k58yk95i

Conversation

@trotterdylan

@trotterdylan trotterdylan commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Implements BB-35 step 3: tiers, migration, transitions, caps, retire-from-file and trial injection into wakes. Step 1 (#57) closed the BB-30 gap and step 2 (#58) added cites and the counters; this step makes the counters move a lesson.

Merging to bb-plugins main moves the pin, builds a new bb-server image and stages a restart on every developer's server (Restart now, or the 03:00–05:00 ET quiet window). It is not pressed from this thread.

Classification

owner-reviewed. The store migration (lessons.tier, the pending/merged/dropped → trial/promoted/retired mapping) matches a decide-list project entry, which the project steward's re-approval covers. The change to how a lesson reaches .bb and the digest change (the merged-lessons section removed) match no project entry, so the owner's approval is the gate for this PR as a whole. @trotterdylan

What changes

  • Store. A tier column (candidate | trial | promoted | retired) plus tier_at, cluster_key and superseded_by. The migration keeps the old status column and maps pending → trial, merged → promoted, dropped → retired, guarded so re-running it never clobbers a tier a transition set. It is appended at the end of MIGRATIONS, so no shipped statement index is reused. Lossless and reversible; every old value survives.
  • Config. A lessons block in project.json with the design's defaults: trial.max, trial.retireDays, promote.hits, promote.days, promoted.maxPerFile, promoted.retireDays, promoted.corrections, decayHalfLifeDays. Defaults apply when the key is absent. bb stewards init's template carries the block.
  • Transitions (pure, in lessons.ts, applied by the nightly pass and every sweep): trial → promoted at 3 distinct-binding hits, 0 corrections, ≥ 14 days; trial → retired at 30 days uncited or any correction; promoted → retired at 90 days uncited or 2 corrections; superseded → retired. A citation's weight halves every decayHalfLifeDays; a promotion into a full file (promoted.maxPerFile) displaces the lowest-scoring promoted lesson. A trial that never landed is dropped in the row; one that is in the file is queued for removal.
  • Wakes. Trial lessons appear under ## Lessons (trial) with ids, capped at lessons.trial.max, in both steward and project-steward wakes; candidates never appear. The project wake also lists ## Lessons to land (promoted, not yet in the file) and ## Lessons to retire (retired, still in the file).
  • Files. Promotion lands the anchored block (<!-- lesson:<id> --> and the wording) through multi-repo's existing narrow self-merge. Retirement replaces the block with <!-- lesson:<id> retired --> and fast-forwards through the same call (lessonAction: { action: "retire" }); the row is kept. A lesson may never target stewards/project.json, and supersedes is validated to be an existing, same-project, same-file, non-retired lesson, so a lesson cannot widen a big decision, loosen prGate or relax an approval, or retire another project's lesson. A boundary lesson still goes to the user as Merge/Drop.
  • Digest. The merged-lessons section is removed.
  • Docs. DESIGN.md §20, README, and the stewards skill.

Not in this step: steward_report { lesson } proposals and lessonAction: accept (the candidate → trial path), rationaleWanted/the page box (step 4), validation escalations (step 5), and the guidance-unit indexing and efficacy view (step 6).

Testing

  • npm run typecheck in plugins/stewards: pass.
  • npm test in plugins/stewards: pass (565 tests; stewards is in the CI matrix, and I ran the suite myself). New: lessons.test.ts covers the anchor add/remove, the score's half-life, and every transition including displacement; store.test.ts covers the lossless, idempotent tier migration and that the tier group is appended last; server.test.ts covers promotion landing, retirement removing the anchored text, trial injection, candidate exclusion, the protected project file, never landing a retired lesson, dropping an aged-out never-landed trial, and supersedes validation across projects/files; wake.test.ts and config.test.ts cover the wake grouping/cap and the config defaults.
  • Not tested: the live multi-repo fast-forward against a real .bb (the existing self-merge path, covered by multi-repo's own suite) and the page (unchanged in this step).

…step 3)

Lessons now carry a tier (candidate -> trial -> promoted -> retired) and the
nightly pass applies the thresholds and caps from a new `lessons` block in
project.json, with the design's defaults when it is absent. Trial lessons are
injected into wakes under their own heading with ids; only promoted ones reach
`.bb`, through the existing multi-repo self-merge path with a
`<!-- lesson:<id> -->` anchor, and a retirement removes the anchored text
through the same path. The migration maps the old pending/merged/dropped
statuses onto the tiers, keeps the status column, and is idempotent. The
digest's merged-lessons section is removed.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_8kjarvgn6j.

_— from bb thread

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at a1c3e10)

Owner review required: yes — a store migration (a decide-list project entry, so the project steward's re-approval covers that trigger), plus a change to how a lesson reaches .bb and the digest change (the merged-lessons section removed — an unmatched change, which is the owner's). @trotterdylan, this one needs your approval once the blockers below are fixed. One correction to the body: the Classification line says "The project steward's re-approval is the lane's gate" — that holds for the store.ts trigger, but the digest and lesson-merge-path changes match no project entry in the decide list, so the owner's approval is the gate for the PR as a whole.

Blockers

  1. store.ts:387 — the tier migration is inserted mid-MIGRATIONS, which breaks plugin load on every live database. bb.storage.migrate is an ordered-statement helper: statement index = migration id in _bb_migrations, each with a recorded hash, and it throws on a changed or reused index ("append-only — never reorder or edit shipped statements", @get-bb/plugin-sdk PluginStorage.migrate). LESSON_TIER_MIGRATIONS is spliced in before WORKER_CHECK_MIGRATIONS, shifting every later statement's index; every developer's live DB has WORKER_CHECK, DECLINED_PR, DEPLOYMENT and FINISHED_AND_DIGEST applied at the old indexes, so the hash check fails and createStewardsPlugin throws on load — stewards (a live plugin) fails on every server at the staged restart. I reproduced it by running the SDK's own runPluginStorageMigrations logic against a DB first migrated with the shipped array, then with this PR's: migration <N> does not match the recorded statement; append a new migration instead of changing or reusing an index. The tests miss it because every test DB is fresh, so all statements apply in order with no prior records. Fix: append LESSON_TIER_MIGRATIONS at the end of MIGRATIONS (the store tests splice groups explicitly, so they are unaffected). This is also exactly the "could stop every developer's server from starting" trigger.

  2. server.ts:5243 / store.ts (addLesson) — supersedes is completely unvalidated. The schema takes any non-empty string and addLesson runs UPDATE lessons SET superseded_by = <new> WHERE id = <given> with no check that the named lesson exists, is in the same project, or is in the same file. Two failure modes: a typo'd id silently no-ops, so the older lesson is never retired and the file keeps both wordings — criterion 5's "superseded in the same section" is not enforced at all; and an id belonging to another project marks that project's lesson superseded, after which that project's nightly pass retires it and removes its anchored text from its .bb — a cross-project write from a different project's steward. Fix: validate in steward_update (or addLesson) that the superseded lesson exists, has the same projectId, the same file, and is not already retired; otherwise toolError.

  3. server.ts:3163 (applyLessonTransitions) — a retired lesson whose status is still pending is never resolved and lingers on the Stewards page forever. The pass sets tier: retired and a note but leaves status: 'pending' (an aged-out trial that never landed, or a displaced promoted-before-landing lesson). The wake's ## Lessons to retire lists only tier === 'retired' && status === 'merged', so the steward is never prompted to call retire on these; complete refuses them; nothing ever drops the row. It then shows permanently on the page's Lessons section ("waiting to be landed… the project steward applies, commits and self-merges this") next to its "Retired: …" note — contradictory user-visible state. Fix: in applyLessonTransitions, a retire transition on a lesson with status === 'pending' should markLessonDropped(id, reason) (the row is kept; only lessons actually in the file go through the tombstone path). Add a test for the aged-out-never-landed trial.

Suggestions

  • completeLesson still lets the project steward land a trial lesson immediately (lessonAction: complete checks status and retired-tier only, not tier === 'promoted'), and the recordLesson return text actively instructs it ("To land it now, add … complete"). That path bypasses both the tier system and promoted.maxPerFile, so "files hold only what earned it" and "bloat is capped by construction" are not true for steward-initiated landing. The step-3 criteria don't explicitly forbid it and it preserves BB-3 behaviour, so I am not blocking on it — but it deserves a line in DESIGN §20 saying so, or gating complete on tier === 'promoted', if not here then in step 4.
  • Rollback window: a lesson recorded by a pre-step-3 image (which does not write tier) gets the column default candidate, and the remap never runs again (its index is already applied), so after roll-forward it is invisible to wakes forever. Edge case; worth one sentence in DESIGN's Undo section.
  • removeLessonAnchor and retireLessonAnchor are used only by tests — the project steward performs the edit by hand following the wake. That is fine as the tested definition of the correct edit, but the DESIGN text could say the helper is normative, not executed.
  • lessons.trial.max has min(1), so a project cannot set it to 0 to turn trial injection off entirely. Probably intended; noting in case.

The retirement tombstone (asked of this review)

Judged against criterion 6 and project-steward limit 1: it satisfies both, to the limit of what the existing narrow path can enforce. The wording is removed and the row is kept, through the same mergeGuidance guard (fast-forward only, refusal leaves the branch alone, and the branch may change nothing but the lesson's own file). The tombstone is necessary because mergeGuidance can only verify presence of text, not absence, and the ticket restricts changes to plugins/stewards; it also keeps the id findable and prevents re-promotion (hasLessonAnchor deliberately does not match the retired form, and reconcileLessons skips retired tiers so a stale file cannot resurrect one). Within the file, over-removal by the project steward is detected no worse than it was for promotion — the guard never diffed the file content beyond the required text in either direction, so the tombstone retirement is exactly as narrow as the existing self-merge path. Limit 1's "removes only text between its own anchor" is defined by the tested retireLessonAnchor boundaries and carried in the wake instructions; enforcing it mechanically would need a multi-repo change, which is out of scope here.

Checked

  • Ran: npm install, npm run typecheck (pass) and npm test in plugins/stewards — 562/562 pass (~48s). The CI plugins matrix does include stewards, so nothing was skipped, but I ran the suite myself anyway, plus the migration repro above.
  • Criterion 1 (store: tier/hits/corrections/lastCitedAt/citation set/cluster key; lossless idempotent mapping, old status kept, nothing dropped): met, except the array placement (blocker 1). lessonTier fails closed to candidate.
  • Criterion 3 (trial injected into steward and project-steward wakes under their own heading with ids, capped at lessons.trial.max; candidates never appear): met.
  • Criterion 5 (thresholds as specified, decay half-life, caps with displacement of the lowest-scoring, configurable with defaults when the key is absent): met for the nightly pass, except supersedes validation (blocker 2) and the retired-pending rows (blocker 3).
  • Criterion 6 (promotion lands the <!-- lesson:<id> --> block through the existing self-merge path; retirement through the same narrow path, row kept; a boundary lesson still needs the user's Merge): met — see the tombstone judgment above.
  • Criterion 10 (nothing in the digest): met — lessonsMerged removed from DigestRecords, formatRecords and the server; no dangling references.
  • Limit 1 (no self-widening; automatic promotion/retirement write only anchored lesson text; stewards/project.json refused as a lesson target): enforced at record time by the new refine and tested; note that complete does not re-validate the file of a pre-existing row (recorded before this PR), a residual worth a later guard.
  • Limit 2 (only the owner's words or this project's own threads teach): no new teaching path in this PR; the steward_update actor gate is unchanged from steps 1–2.
  • Limit 3 (migration lossless and reversible, idempotence tested, old values survive): met — the old status column is kept and every old value survives the round trip.
  • Limit 4 (owner-reviewed lane; the PR body carries the restart-staging note; not pressed from the thread): met, with the body's gate-owner correction noted above.

— from bb thread thr_8kjarvgn6j

…B-35 step 3)

Address the reviewer's three blockers: append LESSON_TIER_MIGRATIONS at the end
of MIGRATIONS so no shipped statement index is reused; validate supersedes in
steward_update (same project, same file, not retired); and resolve a retired
trial that never landed by dropping the row instead of leaving it pending.
Also document the manual-complete override, the rollback window and the
normative retirement helper.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 2 reply at 000b2fe. All three blockers fixed, and each suggestion answered.

Blockers

  1. Migration placement — fixed in 000b2fe. LESSON_TIER_MIGRATIONS is now appended at the end of MIGRATIONS, so every previously shipped statement keeps its index. Added a store test (store.test.ts) that asserts the tier group is the last group in MIGRATIONS, so a future mid-array splice fails a test rather than a live database.
  2. supersedes unvalidated — fixed in 000b2fe. steward_update now refuses a supersedes that is not a lesson of this project, not in the same file, or already retired, before any write. Added a server test covering a foreign project's lesson (left untouched), a different file, and the valid case.
  3. Retired-but-pending lessons — fixed in 000b2fe. applyLessonTransitions now drops the row (markLessonDropped, tier retired, status dropped) when a retire transition hits a lesson whose status is still pending, since there is no anchored text to remove and nothing to wait on; a lesson that is in the file still goes through the tombstone path and the ## Lessons to retire wake. Added a server test for the aged-out never-landed trial.

Suggestions

  • complete on a trial bypasses the cap — declined for this step, documented instead (DESIGN §20, "Tiers and transitions"): the manual complete is an explicit project-steward override and promoted.maxPerFile is enforced by the mechanical nightly pass. Gating it would also change the boundary-lesson Merge/Drop timing, which the description puts at the promotion threshold; that is step 4/5 territory.
  • Rollback window — taken: one sentence added to DESIGN §20's Undo bullet (a pre-step-3 row gets candidate and the remap has already run; bb stewards lessons --all still shows it).
  • Helpers only used by tests — taken: DESIGN §20 now says retireLessonAnchor is the normative definition of the retirement edit and the tests pin it.
  • trial.max min 1 — intended; the wake cap and the trial-set cap share the key and a project does not turn trial injection off in this step.

npm run typecheck and npm test (565) pass locally. I also corrected the PR body's Classification line: the owner's approval is the gate for the PR as a whole.

— from bb thread thr_85k58yk95i

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at 000b2fe)

Owner review required: yes — store migration (a decide-list project entry), plus the digest change and the change to how a lesson reaches .bb (unmatched by any project entry, so the owner's). @trotterdylan, this one needs your approval; my blockers are cleared.

Blockers

None.

Resolved since round 1

  1. Mid-array migration insertion — resolved by 000b2fe: LESSON_TIER_MIGRATIONS is now appended at the end of MIGRATIONS, with a regression test asserting the group stays last. I re-ran the SDK's own runPluginStorageMigrations logic against a DB first migrated with the shipped array, then with this PR's: no throw, the tier columns exist and the remap ran. Fresh indexes only; no shipped statement index is reused.
  2. Unvalidated supersedes — resolved by 000b2fe: steward_update now refuses a superseded lesson that does not exist, is in another project, is in a different file, or is already retired, before anything is written; the new server test covers the foreign-project case (the other project's row is untouched), the wrong-file case and the valid case.
  3. Retired-but-pending lessons lingering — resolved by 000b2fe: applyLessonTransitions now markLessonDroppeds a retire transition whose lesson is still pending (nothing waits on the steward, the page no longer shows it as waiting to land), while a lesson actually in the file stays merged until its tombstone lands through ## Lessons to retire. The new test covers the aged-out-never-landed trial.

Suggestions

  • Round 1's complete-on-trial suggestion is declined with a reason that holds for this step: the step-3 criteria do not forbid it, and DESIGN §20 now states plainly that a hand complete of a trial is an explicit override that bypasses promoted.maxPerFile, with the nightly pass as the mechanical path. Flagging for @trotterdylan: if "files hold only what earned it" is meant strictly, step 4 should gate complete on tier === 'promoted'.
  • The rollback-window and normative-helper notes are now in DESIGN §20's Undo section — accurate as written.
  • trial.max min 1 intended — accepted.

Checked

  • Ran: npm run typecheck (pass) and npm test in plugins/stewards — 565/565 pass (~48s), including the three new tests; plus the migration repro above on the new head. CI's plugins matrix includes stewards and is green at 000b2fe.
  • Reviewed the round-2 diff itself (DESIGN.md, server.ts, store.ts, both test files): no scope change, no new behaviour beyond the three fixes; the supersedes gate sits after the project-steward actor gate, so only the project steward reaches it.
  • Criteria re-checked at this head: 1 (store fields, lossless idempotent migration, status kept) met; 3 (trial injection with ids and cap in both wake kinds, candidates never appear) met; 5 (thresholds, decay, caps with displacement, configurable defaults) met; 6 (anchored promotion via self-merge, retirement through the same narrow path, row kept, boundary still the user's Merge) met — the tombstone judgment from round 1 stands; 10 (nothing in the digest) met.
  • Lane unchanged: owner-reviewed. The store-migration trigger's approval may be the project steward's (decide list), but the digest and lesson-merge-path changes are the owner's, so the owner's approval gates the PR as a whole.

— from bb thread thr_8kjarvgn6j

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Approved 000b2fe from the Stewards page

@trotterdylan
trotterdylan merged commit 8536b40 into main Oct 26, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-35-step-3-tier-migration-transitions-digest-thr_85k58yk95i branch October 26, 2026 16:07
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: owner-reviewed, approved by trotterdylan on 000b2fe (comment 2026-10-26T16:06:39Z, "Approved … from the Stewards page"); the independent reviewer approved the same sha (round 2, verdict=approved), and all 20 checks were green. merge commit 8536b40.

This merge moves the bb-plugins pin, builds a new bb-server image and stages a restart on every developer's server (Restart now, or the 03:00–05:00 ET quiet window). It was not pressed from this thread.

— from bb thread thr_85k58yk95i

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