Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: guard bundle sync queueBacklog calls in share bucket watcher (#8909)

[._.]/ Adam Eivy4275bc19c51b
diff --git a/server/services/sharing/watcher.js b/server/services/sharing/watcher.js
index 636dba8605..535cf061f4 100644
--- a/server/services/sharing/watcher.js
+++ b/server/services/sharing/watcher.js
@@ -45,7 +45,7 @@ function queueBacklog(bucketId) {
backlogQueues.set(bucketId, { running, queued: null });
return running;
}
- const queued = slot.running.then(() => {
+ const queued = slot.running.catch(() => {}).then(() => {
// Promote the follow-up before scanning. Events arriving during it need
// another trailing scan, since their manifest may already have been read.
slot.running = queued;
@@ -86,26 +86,26 @@ export async function attachWatcher(bucketId) {
// /setTimeout/setInterval callbacks" rule (chokidar events fire outside the
// request lifecycle, no Express middleware to bubble the throw to).
w.on('add', async (path) => {
- if (isBundleSync(path)) { await queueBacklog(bucketId); return; }
- const file = basename(path);
- if (!file.endsWith('.json')) return;
try {
+ if (isBundleSync(path)) { await queueBacklog(bucketId); return; }
+ const file = basename(path);
+ if (!file.endsWith('.json')) return;
await processManifest(bucketId, file);
} catch (err) {
- console.error(`❌ sharing.watcher: processManifest threw for ${file}: ${err?.message || err}`);
+ console.error(`❌ sharing.watcher: processManifest threw for ${basename(path)}: ${err?.message || err}`);
}
});
w.on('change', async (path) => {
- if (isBundleSync(path)) { await queueBacklog(bucketId); return; }
- // A manifest *changing* after first write is unusual (atomicWrite
- // produces a stable file), but it can happen if a peer's sync app
- // does a delete-then-write. Re-process — cursor will dedup.
- const file = basename(path);
- if (!file.endsWith('.json')) return;
try {
+ if (isBundleSync(path)) { await queueBacklog(bucketId); return; }
+ // A manifest *changing* after first write is unusual (atomicWrite
+ // produces a stable file), but it can happen if a peer's sync app
+ // does a delete-then-write. Re-process — cursor will dedup.
+ const file = basename(path);
+ if (!file.endsWith('.json')) return;
await processManifest(bucketId, file);
} catch (err) {
- console.error(`❌ sharing.watcher: processManifest threw on change ${file}: ${err?.message || err}`);
+ console.error(`❌ sharing.watcher: processManifest threw on change ${basename(path)}: ${err?.message || err}`);
}
});
w.on('unlink', async (path) => {
diff --git a/server/services/sharing/watcher.test.js b/server/services/sharing/watcher.test.js
index 43d2b0def0..90c6262ade 100644
--- a/server/services/sharing/watcher.test.js
+++ b/server/services/sharing/watcher.test.js
@@ -138,4 +138,22 @@ describe('share-bucket watcher backlog lifecycle', () => {
await deliver(watcher, 'change', path);
expect(processBacklog).toHaveBeenCalledTimes(4);
});
+
+ it('bundle-sync path event with failing backlog scan does not produce unhandled rejection and subsequent scan still runs', async () => {
+ const { watcher, paths, root } = await attach();
+ const blocked = deferred();
+ const secondStarted = deferred();
+ processBacklog
+ .mockImplementationOnce(() => blocked.promise.then(() => { throw new Error('Bundle sync backlog failure'); }))
+ .mockImplementationOnce(() => { secondStarted.resolve(); return Promise.resolve(); });
+ const assetPath = paths.join(root, 'assets', 'blobs', 'example-blob');
+ const pending = deliver(watcher, 'add', assetPath);
+ const trailing = deliver(watcher, 'add', assetPath);
+ expect(processBacklog).toHaveBeenCalledTimes(1);
+ blocked.resolve();
+ await secondStarted.promise;
+ await Promise.all([pending, trailing]);
+ expect(console.error).toHaveBeenCalledWith(expect.stringContaining('Bundle sync backlog failure'));
+ expect(processBacklog).toHaveBeenCalledTimes(2);
+ });
});