Skip to content

feat(hub): schedule automatic learning runs - #296

Merged
alliscode merged 8 commits into
build/hub/newfrom
alliscode-automatic-learning-runs
Nov 19, 2026
Merged

alliscode merged 8 commits into
build/hub/newfrom
alliscode-automatic-learning-runs

Conversation

@alliscode

Copy link
Copy Markdown
Contributor

Why

Administrators can request learning runs explicitly, but repositories with new review feedback or unfinished work otherwise wait until someone notices and starts another run. Operators need an optional daily path that keeps learning current without taking capacity ahead of user requests.

What changes

Hub can now opt in to a daily 02:00 UTC learning discovery schedule. It runs only while the saved Copilot connection is usable, finds accessible repositories with review changes or unfinished comments and suggestions, and queues the least recently run repositories first.

Automatic work stays on the scheduled queue. Explicit requests remain on the on-demand queue, can promote a queued automatic run for the same repository, and take precedence before automatic execution claims the existing global learning lock. Recovery returns interrupted runs to their original queue, and enqueue or snapshot-drift failures remain visible in run history.

Completed run history is pruned after 90 days while retaining each repository's latest run and latest successful scheduling watermark. Learning consent, evidence import, labeling, consolidation, and package policy remain in the existing run processor. Operators enable discovery with REPLICA_LEARNING_AUTOMATIC_RUNS=true; disabled discovery still performs run retention without initializing learning or Copilot integrations.

Ben Thomas and others added 3 commits November 18, 2026 14:45
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@alliscode
alliscode requested review from a team and nshki as code owners November 18, 2026 23:48
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 23:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical flaws can indefinitely block recovery, fail first-time automatic runs on consent validation, and leave late-committed review changes unscheduled.

6 open issues
What changed in this PR

Adds opt-in daily learning runs to Hub’s existing learning pipeline, reducing the need for administrators to request runs manually.

Changes:

  • Discovers due repositories at 02:00 UTC when automatic runs are enabled and Copilot is usable.
  • Separates automatic and explicit work, adds queued-run promotion, and preserves queue ownership during recovery.
  • Prunes completed history after 90 days while retaining scheduling records, with supporting tests and operator documentation.
File Description
hub/​server/​workers/​configuration.ts Registers automatic processors and the daily schedule.
hub/​server/​workers/​configuration.test.ts Checks processor registration and schedule settings.
hub/​server/​routes/​api/​learnings/​create-learnings-route-dependencies/​index.ts Handles promotion, auditing, and enqueue failures.
hub/​server/​repositories/​learning-runs/​list-queued-learning-runs/​index.ts Returns queue ownership for recovery.
hub/​server/​repositories/​learning-runs/​list-queued-learning-runs/​index.db.test.ts Covers recovery ownership for active runs.
hub/​server/​repositories/​learning-runs/​list-due-learning-repositories/​index.ts Selects and orders repositories needing learning work.
hub/​server/​repositories/​learning-runs/​list-due-learning-repositories/​index.db.test.ts Covers eligibility, ordering, and unfinished work.
hub/​server/​repositories/​learning-runs/​is-learning-run-repository-available/​index.ts Rechecks repository availability before run creation.
hub/​server/​repositories/​learning-runs/​has-pending-user-learning-run/​index.ts Detects explicit work awaiting completion.
hub/​server/​repositories/​learning-runs/​fail-scheduled-learning-run-enqueue/​index.ts Persists automatic enqueue failures safely.
hub/​server/​repositories/​learning-runs/​fail-scheduled-learning-run-enqueue/​index.db.test.ts Checks that promoted runs are not failed accidentally.
hub/​server/​repositories/​learning-runs/​delete-expired-learning-runs/​index.ts Prunes history while preserving scheduling records.
hub/​server/​repositories/​learning-runs/​delete-expired-learning-runs/​index.db.test.ts Covers retention and protected records.
hub/​server/​repositories/​learning-runs/​create-learning-run/​index.ts Creates automatic runs and promotes queued runs.
hub/​server/​repositories/​learning-runs/​create-learning-run/​index.db.test.ts Covers concurrent automatic and explicit requests.
hub/​server/​integrations/​bullmq/​upsert-job-schedule/​index.db.test.ts Checks stable scheduler updates.
hub/​server/​domains/​learning/​schedule-learning-runs/​index.ts Coordinates retention, discovery, and automatic enqueueing.
hub/​server/​domains/​learning/​schedule-learning-runs/​index.test.ts Covers scheduling gates, ordering, and failures.
hub/​server/​domains/​learning/​recover-learning-run-jobs/​index.ts Routes recovered runs to their original queues.
hub/​server/​domains/​learning/​recover-learning-run-jobs/​index.test.ts Checks recovery routing and order.
hub/​server/​domains/​learning/​read-learning-configuration/​index.ts Validates the automatic-runs setting.
hub/​server/​domains/​learning/​read-learning-configuration/​index.test.ts Covers opt-in behavior and invalid settings.
hub/​server/​domains/​learning/​process-learning-run/​index.ts Adds automatic execution and user-work deferral.
hub/​server/​domains/​learning/​process-learning-run/​index.test.ts Covers deferral, system identity, and snapshot drift.
hub/​server/​domains/​learning/​jobs/​schedule-learning-runs.ts Defines discovery payload and retry settings.
hub/​server/​domains/​learning/​create-learning-job-processors/​index.ts Wires discovery, queue separation, and retention.
hub/​docs/​learning-foundation.md Documents scheduling, recovery, and retention behavior.
hub/​docs/​development.md Explains automatic work in scheduled workers.
hub/​docs/​background-jobs.md Documents daily discovery and queue behavior.
hub/​docs/​architecture.md Updates background-worker responsibilities.
hub/​.env.example Shows the automatic-runs opt-in setting.

Review effort: Max (adaptive)

Comment thread hub/server/workers/configuration.ts Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A queue-ownership race can send promoted user requests to the wrong worker, while repository-specific failures can repeatedly block scheduling for later repositories.

5 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Avoid burning retries during expected lock contention

hub/​server/​domains/​learning/​process-learning-run/​index.ts:121

While a long user-requested run holds the global lock, every queued automatic job retries at the fixed 30-second interval. With a full batch, normal priority deferral repeatedly opens database connections, logs failed attempts, and consumes each job's retry budget. Use a non-failing delay for expected contention, or dispatch only one automatic run at a time.

Medium severity Reflect automatic-run availability in the Learnings status

hub/​server/​domains/​learning/​read-learning-configuration/​index.ts:46

With the new switch left at its default false, the Learnings page still says “Hub looks for learnings once a day” whenever Copilot is connected (client/application/hub/view-models/settings-learnings/index.ts:52–56). Expose automatic-run availability in the Learnings response and use it to choose the status message, so default deployments do not promise work they never schedule.

6 resolved since last review

Review effort: Max (adaptive)

Ben Thomas and others added 4 commits November 19, 2026 09:08
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@alliscode
alliscode merged commit c92f9cb into build/hub/new Nov 19, 2026
51 checks passed
@alliscode
alliscode deleted the alliscode-automatic-learning-runs branch November 19, 2026 20:44
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.

3 participants