Skip to content

fix(daemon): kick recommender on startup + don't burn the interval on a failed launch#151

Merged
thejustinwalsh merged 1 commit into
mainfrom
fix/recommender-startup-kick
May 25, 2026
Merged

fix(daemon): kick recommender on startup + don't burn the interval on a failed launch#151
thejustinwalsh merged 1 commit into
mainfrom
fix/recommender-startup-kick

Conversation

@thejustinwalsh

@thejustinwalsh thejustinwalsh commented May 25, 2026

Copy link
Copy Markdown
Owner

The two follow-ups noted while debugging #150 — both the "mm start should self-start, not idle" class.

1. Startup kick — mm start works in seconds, not after a 15-min wait

A fresh daemon used to idle until the first cron tick (up to a full interval_minutes) before the recommender ran, and never kicked auto-dispatch against an already-ready state issue. Now, right after the crons start, the daemon:

  • runs one recommender due-check pass immediately (runRecommenderCronPass) — any overdue managed repo fires now → auto-dispatch on completion; and
  • nudges auto-dispatch for every managed repo (scheduleAutoDispatch) — so an already-ready #84 from a prior run drains on restart without waiting for a fresh recommender pass.

2. A failed launch no longer burns the full interval

The cron stamps last_recommender_run before firing (overlap guard) — but a failed launch left that stamp, so the repo went quiet for a full interval before retrying. It now rolls the stamp back to the prior value on a failed launch (setLastRecommenderRun), so the failure retries on the next tick. (A successful run keeps its stamp.)

What to verify

  • Cron rolls the stamp back on a throwing launch and retries it next pass; a successful sibling stays stamped + isolated — recommender-cron.test.ts.
  • setLastRecommenderRun writes a value and clears it with nullrepo-config.test.ts.
  • Full suite 674 pass, lint/typecheck/format clean.

This is the last bit of the walk-away loop: pull + mm stop && mm start and the recommender fires within seconds, then the 15-min cron keeps it going.

Summary by CodeRabbit

Release Notes

  • New Features

    • Recommender check now executes immediately upon daemon startup to ensure fresh state assessment in addition to regular scheduled checks.
  • Bug Fixes

    • Enhanced failure recovery: when a recommender operation fails, the system now properly resets its state to allow automatic retry on the next scheduled check, improving overall reliability.

Review Change Stack

…l on a failed launch

Two follow-ups from #150's debugging:

- mm start now runs one recommender due-check pass immediately (any overdue
  managed repo fires now → auto-dispatch on completion) and nudges auto-dispatch
  for every managed repo, instead of idling until the first cron tick (up to a
  full interval). A fresh restart works in seconds, not 15 minutes.
- The cron stamps last_recommender_run before firing (overlap guard) but now
  ROLLS IT BACK on a failed launch (setLastRecommenderRun to the prior value), so
  a failure retries on the next tick rather than going quiet for a full interval.
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e85a9557-621e-4c84-b9a2-af6d2568abd7

📥 Commits

Reviewing files that changed from the base of the PR and between 975a064 and 10c912b.

📒 Files selected for processing (5)
  • packages/dispatcher/src/main.ts
  • packages/dispatcher/src/recommender-cron.ts
  • packages/dispatcher/src/repo-config.ts
  • packages/dispatcher/test/recommender-cron.test.ts
  • packages/dispatcher/test/repo-config.test.ts

📝 Walkthrough

Walkthrough

Adds rollback behavior for failed recommender runs. A new setLastRecommenderRun primitive allows resetting last_recommender_run to prior values. The cron pass captures the prior timestamp, stamps now before dispatch, and on failure rolls back to the captured value, enabling retry on the next pass. Daemon startup now invokes an immediate recommender due-check pass rather than waiting for the first cron interval.

Changes

Recommender run rollback on failure

Layer / File(s) Summary
Rollback timestamp primitive
packages/dispatcher/src/repo-config.ts, packages/dispatcher/test/repo-config.test.ts
setLastRecommenderRun(db, repo, value, now) added to upsert last_recommender_run to an explicit value or null; markRecommenderRun simplified to delegate to it. Unit test covers setting and clearing the timestamp.
Cron pass rollback logic
packages/dispatcher/src/recommender-cron.ts, packages/dispatcher/test/recommender-cron.test.ts
Cron pass captures prior last_recommender_run, stamps now before dispatch, and rolls back to prev on recommender failure. Test verifies failed repo remains due for retry while successful repos are not retried.
Startup integration
packages/dispatcher/src/main.ts
Recommender cron refactored into recommenderCronDeps with updated runRecommender handler that throws on non-202 status. Startup now schedules auto-dispatch and invokes immediate runRecommenderCronPass (with error logging) before entering cron loop.

Sequence Diagram(s)

sequenceDiagram
  participant CronPass as Cron Pass
  participant RepoConfig as Repo Config
  participant Recommender as Recommender
  
  CronPass->>RepoConfig: read last_recommender_run (prev)
  CronPass->>CronPass: check if repo due
  alt Repo is due
    CronPass->>RepoConfig: setLastRecommenderRun(now)
    CronPass->>Recommender: runRecommender
    alt Succeeds with 202
      Recommender-->>CronPass: 202
      CronPass->>CronPass: stamp remains at now
    else Throws
      Recommender-->>CronPass: error
      CronPass->>RepoConfig: setLastRecommenderRun(prev)
      CronPass->>CronPass: log failure, repo due on next tick
    end
  else Repo not due
    CronPass->>CronPass: skip
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • thejustinwalsh/middle#142: Extended the recommender-cron.ts and repo-config.ts logic by adding rollback-on-failed-launch semantics and updating cron/repo-config tests and startup wiring.

Suggested labels

dogfood

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes both main changes: kicking the recommender on startup and preserving retry opportunities after a failed launch by not burning the interval.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Comment @coderabbitai help to get the list of available commands and usage tips.

@thejustinwalsh

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@thejustinwalsh thejustinwalsh merged commit 27659b3 into main May 25, 2026
1 check passed
@thejustinwalsh thejustinwalsh deleted the fix/recommender-startup-kick branch May 25, 2026 18:21
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