feat(learn): opt-in automatic promotion of learned lessons
Issue for this PR
Follow-up to #1405 (learn v1). No separate issue (feature PR).
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Learn already captures feedback and reflects it into a staged candidate automatically, but a person has to run learn promote before anything reaches the agent. This adds an opt-in mode that closes the loop: after an automatic reflection stages a candidate, it is promoted without a person if every safety gate passes. If any gate fails, the candidate stays staged and the reason is recorded.
Turning it on. learn enable --auto-promote, or set learn.auto_promote: true. ALTIMATE_LEARN_AUTO_PROMOTE overrides the setting in either direction. It only takes effect when learn is enabled and capture and automatic reflection are on. Two limits are configurable: learn.auto_promote_max_changes (default 3) and learn.auto_promote_daily (default 5 per rolling 24h).
Gates. All are checked under the learn lock before anything is written:
- the state file is readable;
- the reflection used at least one external signal, and its feedback was not flagged;
- it is the exact candidate this reflection staged (hash taken under the lock);
- the candidate had no earlier unreviewed changes;
- it passes the same validation as a manual promote (lint, overlaps);
- it makes a real lesson change;
- none of the changed lessons is flagged as verification-weakening;
- no lesson a person approved or pinned is edited or removed;
- the change and daily limits are respected.
Things a reviewer should know:
- Person-approved lessons keep their approved counters. They are published with those counters; the candidate's counter updates stay staged for the next manual promote, so an automatic promotion cannot reorder a person's core lessons.
- Auto-promoted lessons are tracked locally, in
auto-promote.jsonby id and text hash. They are not marked inapproved.json, whose schema is strict and shared through Git, so older clients still parse it. - Rollback always works. Each promotion is archived like a manual promote. A first promotion writes an empty baseline, so
learn rollbackalways has something to restore. - Status and history show it. History records the added, edited and removed ids.
learn status/--jsonshow the last promotion and the last hold reason,learn showmarks lessons as(auto-promoted), andrun --format jsonincludes the promotion inlearn_auto_reflect. - Only the automatic path promotes. Only the automatic reflection path and the default store are affected. Manual
reflect,bootstrapandimport-reviewsstill only stage candidates. - Promotion never breaks a run. Every promotion error becomes a hold. Promotion is skipped once the run's deadline or abort has fired.
- No user validation command. I deliberately left out a user-configured validation command: it would come from repository config, so a cloned repo could run a command in the background.
The default behaviour does not change: with auto_promote unset, nothing new happens.
How did you verify your code works?
- 42 new tests in
test/altimate/learn/auto-promote.test.ts. They cover:- each gate holding back with its reason;
- a hash mismatch;
- pinned lessons;
- a non-refusal failure leaving no auto marks;
- counters held back on person-approved lessons;
- the rolling window;
- rollback restoring the previous set;
- an end-to-end run through the real automatic-reflection entry point;
enable --auto-promote.
- I removed each gate in turn, and its tests failed.
- An independent adversarial review found three bugs (pinned lessons, stale auto marks after a failed publish, and counter ride-along). All are fixed, each with a regression test.
- From
packages/opencode, these pass:bun run typecheck,test/altimate/learn/,test/session/,test/tool/andtest/server/httpapi-config.test.ts. The upstream marker check passes.
Screenshots / recordings
N/A: CLI behaviour. The outcome line reads, for example: learn: 1 signal -> +1 added; auto-promoted (previous lessons archived as v1). Undo with \altimate-code learn rollback``.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
🤖 Generated with Claude Code
[!NOTE]
Medium Risk
Opt-in only, but when enabled it can write to shared approved.json and affect every later session; mitigated by gates, rate limits, rollback, and voiding auto-ownership on manual edits.
Overview
Adds opt-in fully automatic mode for Learn: after automatic reflection stages a candidate, it can go live without learn promote when every safety gate passes. Default behavior is unchanged (learn.auto_promote off).
Enable with learn enable --auto-promote, config (learn.auto_promote, learn.auto_promote_max_changes, learn.auto_promote_daily), or ALTIMATE_LEARN_AUTO_PROMOTE (requires capture and auto_reflect). New auto-promote.ts runs only on the automatic reflection path for the default store; manual reflect, bootstrap, and import-reviews still only stage candidates.
Gates (all under the learn lock) include: exact staged candidate hash, no prior unreviewed candidate changes, same validation as manual promote, human/review/CI feedback (not tool-retry-only), no verification-weakening flagged edits, no edits/removals of person-approved or pinned lessons, size and rolling 24h rate limits, and deadline/cancel rechecks. Failures record a hold reason; successes archive like promote and are undoable with learn rollback.
State and store behavior: tracks auto-published lessons in .altimate-code/learn/<name>/auto-promote.json (not in committed approved.json). Person actions (promote, rollback, pin, unpin) void automatic ownership (fail closed if state cannot be updated). Counter-only updates on person-approved lessons stay staged so core-tier ordering cannot shift silently. CLI status/show, run outcome lines, and learn_auto_reflect JSON report promotion vs held; docs add a Fully automatic mode section. Config schema, OpenAPI, and SDK types include the new keys; large test suite in auto-promote.test.ts.
Reviewed by Cursor Bugbot for commit e387da1f9b1626f4c077f64f92da5a534f6beede. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Adds opt-in automatic promotion of lessons after automatic reflection, closing the learn loop without a manual learn promote step. Default behavior is unchanged: without learn.auto_promote, every candidate stays staged for review.
Gates and limits
- Promotes only the candidate automatic reflection just staged, on the default store, when it passes the same validation as a manual promote; a landed publish is reported as promoted with a warning if a later failure occurs. Cancellation and the run deadline are rechecked under the learn lock, and a pre-write refusal never claims an externally written approved set as auto-promoted.
- Holds the candidate when it lacks a correction, review, or CI signal (tool-failure-only reflections never promote), its feedback is flagged, it adds or edits flagged/verification-weakening lessons, edits or removes person-approved or pinned lessons, exceeds
learn.auto_promote_max_changes(default 3), or the store haslearn.auto_promote_dailypromotions (default 5) in 24 hours. The reason is recorded. - Person-approved lessons publish with their approved counters; counter updates stay staged.
learn rollbackundoes automatic promotions. Manual promote, rollback, pin, or unpin clears the tracked promotions under the learn lock and fails without changing anything when that cannot be recorded, including unreadable auto-promote state, so marks never revive when the approved set later returns to the same bytes. History,learn status, andlearn showreport promotions and holds; manual reflect, bootstrap, and import-reviews still only stage candidates.
Enable with learn enable --auto-promote, learn.auto_promote: true, or ALTIMATE_LEARN_AUTO_PROMOTE=1; it requires capture and automatic reflection to be on.
Summary by CodeRabbit
- New Features
- Added optional automatic promotion of reflected lesson candidates when all safety checks pass; candidates that don’t qualify remain staged for review.
- Added configurable limits for lesson changes per promotion and promotions per store in a 24-hour period, defaulting to 3 and 5.
- Added CLI controls and status details for automatic promotion, including promotion and holdback outcomes.
- Documentation
- Updated setup and configuration guidance with automatic-promotion settings, safety checks, limits, and rollback instructions.