Skip to content

Back off Keep Awake reconciles after host worker exits - #1792

Merged
ymichael merged 1 commit into
mainfrom
bb/keep-awake-worker-exit-backoff
Aug 18, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/keep-awake-worker-exit-backoff

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Problem

Keep Awake's experimental_onWorkerExit handler called requestReconcile(), which forces an immediate pass and skips the retry backoff. When a host worker crashes on start (see #1790 for the packaging cause), the server loops every ~80ms:

Keep Awake host worker exited unexpectedly on host host_...; retrying
Could not reconcile Keep Awake on host host_...: host plugin worker exited (1)

One log file collected 60k+ of these lines.

Change

  • plugins/keep-awake/server.ts: worker exits now request a retry, which waits for the exponential backoff (1s → 2s → … → 30s cap). Configuration changes and host connects still reconcile immediately.
  • plugins/keep-awake/server.test.ts: fake-timer tests for the delayed retry and the crash-loop backoff. The crash-loop test spins forever on the old code.

This is the plugin-side half of #1790, split out so it can land now. The packaging fix (ship bb-plugin-host-worker.mjs) stays in #1790.

Verification

turbo run test typecheck --filter=bb-plugin-keep-awake passes.

AGENT GENERATED: by Claude Opus 5

🤖 Generated with Claude Code

Keep Awake requested an immediate reconcile on every host worker exit,
which skipped the retry backoff. A crash-looping worker spun the
reconciler every ~80ms and flooded the server log. Worker exits now wait
for the exponential retry delay (1s to 30s); configuration and host
changes still reconcile immediately.

Co-Authored-By: Claude <[email protected]>
@ymichael
ymichael merged commit 911bb50 into main Aug 18, 2026
10 checks passed
@ymichael
ymichael deleted the bb/keep-awake-worker-exit-backoff branch August 18, 2026 18:26
ymichael added a commit that referenced this pull request Aug 18, 2026
## Problem

Packaged `bb-app` daemons fail every host plugin call with `host plugin
worker exited (1)`. Their stderr reports that neither the compiled
worker nor its TypeScript development fallback exists in the installed
package.

`defaultWorkerEntryPath()` looked for `plugin-host-worker.js` beside
`daemon-bundle.mjs` and fell back to the `.ts` source. The published
package contained neither: the bundle manifest had no worker target, and
the `bb-app` package whitelist only shipped the `.mjs` bundles.

The Keep Awake-specific retry mitigation was split out and merged in
#1792. This PR now contains only the general packaging fix and its
release-level coverage.

## Changes

- Add a self-contained `bb-plugin-host-worker.mjs` bundle.
- Resolve the packaged `.mjs` worker first while retaining
compiled-development and source-development fallbacks.
- Ship the worker in `bb-app` and require it during launcher artifact
validation.
- Assert that the npm package whitelist includes the worker.
- Exercise the packed worker directly with the packed Keep Awake host
artifact.
- Verify worker startup in the full packaged stack and on two
independently enrolled packaged daemons.

No daemon wire contract changed, so no `HOST_DAEMON_PROTOCOL_VERSION`
bump is needed.

## Verification

- `turbo run typecheck --filter=@bb/host-daemon --filter=bb-app`
- `turbo run test --filter=@bb/host-daemon --filter=bb-app --force` (583
host-daemon tests and 65 bb-app tests)
- `turbo run smoke:tarball --filter=bb-app --force` (direct packed
worker, full stack, and two-daemon enrollment)
- Prettier, JavaScript syntax check, and `git diff --check`

> AGENT GENERATED: by GPT-5

---------

Co-authored-by: Michael Yong <[email protected]>
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.

2 participants