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: bulk-status review endpoint to stop dropping updates under concurrent writes

Adam Eivya2b1e6e4e2bb
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 63bda92fba..68642a1809 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -12,6 +12,8 @@
- **Review Hub: only had a "Mark All Read" (dismiss) bulk action.** Added a green "Complete All" button next to the renamed "Dismiss All" so the user can clear a queue of finished items as completed (correct status for things that were actually done) instead of dismissing them (which means "ignored"). File: `client/src/pages/Review.jsx`.
+- **Review Hub: "Dismiss All" / "Complete All" only marked ~10 items per click.** The first cut of those buttons fanned N parallel `POST /api/review/items/:id/{dismiss,complete}` requests at the server. Each handler did its own `loadItems → mutate → atomicWrite(items)` cycle, so concurrent requests read overlapping snapshots of `data/review/items.json` and the last writer overwrote everyone else's status changes — the user had to keep clicking until every item settled. Added a single `POST /api/review/items/bulk-status` endpoint that does one read-modify-write for `{ status, ids? }` (omit `ids` to target every pending item), and switched the client to call it once instead of N times. Side-effect emits (`item:updated`) now fire after the save, not inside the mutation loop, so socket clients can't observe state ahead of disk. Files: `server/services/review.js`, `server/routes/review.js`, `server/services/review.test.js`, `client/src/services/apiReview.js`, `client/src/pages/Review.jsx`.
+
- **Flux i2i: portrait iPhone photos came out rotated 90°.** Modern browsers honor the EXIF Orientation tag when rendering `<img>`, so the upload thumbnail looked right — but mflux/PIL reads raw pixel data and ignores EXIF, so a portrait iPhone photo (Orientation=6 or 8) landed sideways in the generated output. The init image picker now passes the file through `createImageBitmap({ imageOrientation: 'from-image' })` and re-encodes via canvas before upload, baking the rotation into the actual pixels and stripping the EXIF tag. Any image decoder downstream now sees the same orientation the browser displayed. File: `client/src/pages/ImageGen.jsx`.
- **Multipart upload server crash: `Cannot read properties of null (reading 'write')`.** Streaming multipart parser (`server/lib/multipart.js`) crashed with an uncaught `TypeError` when the request stream's `'end'` event fired while a file part's `ws.end()` flush was still in flight. After consuming a part boundary, `endPart()` synchronously nulled `writeStream` but kept `state` at `STATE_BODY` until the async `ws.end` callback ran. If `req.on('end')` fired during that window, the end handler called `tick()`, which re-entered `STATE_BODY`, found another boundary in the trailing buffer, and called `writePartChunk()` → `writeStream.write(chunk)` on a `null` stream → process-killing `uncaughtException`. Fix: `tick()` now returns early when `pendingFlush > 0`; the existing `endPart` callback already re-invokes `tick()` once the flush completes and state has advanced. Added a regression test that defers the mocked `ws.end()` callback so the bug reproduces without the fix. File: `server/lib/multipart.js`.
diff --git a/client/src/pages/Review.jsx b/client/src/pages/Review.jsx
index eec0b417e3..697dfcb84c 100644
--- a/client/src/pages/Review.jsx
+++ b/client/src/pages/Review.jsx
@@ -114,13 +114,8 @@ export default function Review() {
setEditingId(null);
};
- const applyToAllPending = (apiFn) => {
- const pendingItems = items.filter(i => i.status === 'pending');
- return Promise.all(pendingItems.map(i => apiFn(i.id).catch(() => null)));
- };
-
- const handleMarkAllRead = () => applyToAllPending(api.dismissReviewItem);
- const handleCompleteAll = () => applyToAllPending(api.completeReviewItem);
+ const handleMarkAllRead = () => api.bulkUpdateReviewStatus({ status: 'dismissed' }).catch(() => null);
+ const handleCompleteAll = () => api.bulkUpdateReviewStatus({ status: 'completed' }).catch(() => null);
const grouped = items.reduce((acc, item) => {
if (!acc[item.type]) acc[item.type] = [];
diff --git a/client/src/services/apiReview.js b/client/src/services/apiReview.js
index c5ffcebe01..77671e75f3 100644
--- a/client/src/services/apiReview.js
+++ b/client/src/services/apiReview.js
@@ -21,3 +21,7 @@ export const updateReviewItem = (id, data) => request(`/review/items/${id}`, {
export const completeReviewItem = (id) => request(`/review/items/${id}/complete`, { method: 'POST' });
export const dismissReviewItem = (id) => request(`/review/items/${id}/dismiss`, { method: 'POST' });
export const deleteReviewItem = (id) => request(`/review/items/${id}`, { method: 'DELETE' });
+export const bulkUpdateReviewStatus = ({ status, ids }) => request('/review/items/bulk-status', {
+ method: 'POST',
+ body: JSON.stringify({ status, ...(ids ? { ids } : {}) })
+});
diff --git a/server/routes/review.js b/server/routes/review.js
index 355a30a4a9..c70f4cbf28 100644
--- a/server/routes/review.js
+++ b/server/routes/review.js
@@ -16,6 +16,11 @@ const updateItemSchema = z.object({
description: z.string().max(5000).optional()
});
+const bulkStatusSchema = z.object({
+ status: z.enum(['completed', 'dismissed']),
+ ids: z.array(z.string()).optional()
+});
+
// GET /api/review/items — list all items (optional ?status=pending&type=todo filters)
router.get('/items', asyncHandler(async (req, res) => {
const { status, type } = req.query;
@@ -65,6 +70,13 @@ router.post('/items/:id/dismiss', asyncHandler(async (req, res) => {
res.json(item);
}));
+// POST /api/review/items/bulk-status — bulk update many items in one write
+router.post('/items/bulk-status', asyncHandler(async (req, res) => {
+ const data = validateRequest(bulkStatusSchema, req.body);
+ const updated = await reviewService.bulkUpdateStatus(data);
+ res.json({ updated: updated.length, items: updated });
+}));
+
// DELETE /api/review/items/:id — delete an item
router.delete('/items/:id', asyncHandler(async (req, res) => {
await reviewService.deleteItem(req.params.id);
diff --git a/server/services/review.js b/server/services/review.js
index 59b63bc8f4..33beb5bbbc 100644
--- a/server/services/review.js
+++ b/server/services/review.js
@@ -144,6 +144,39 @@ export async function dismissItem(id) {
return updateItemStatus(id, 'dismissed');
}
+/**
+ * Bulk-update many items to the same status in a single read-modify-write.
+ * Concurrent per-item POSTs race on saveItems and silently drop updates;
+ * this endpoint handles the "Complete All" / "Dismiss All" cases atomically.
+ * Pass `ids` to target specific items, or omit to target every pending item.
+ */
+export async function bulkUpdateStatus({ ids, status }) {
+ if (!ITEM_STATUSES.includes(status)) {
+ const err = new Error(`Invalid status: ${status}`);
+ err.status = 400;
+ throw err;
+ }
+
+ const items = await loadItems();
+ const idSet = Array.isArray(ids) && ids.length > 0 ? new Set(ids) : null;
+ const updated = [];
+ const now = new Date().toISOString();
+ for (const item of items) {
+ if (item.status !== 'pending') continue;
+ if (idSet && !idSet.has(item.id)) continue;
+ item.status = status;
+ item.updatedAt = now;
+ updated.push(item);
+ }
+
+ if (updated.length === 0) return [];
+
+ await saveItems(items);
+ console.log(`📋 Review items bulk-${status}: ${updated.length}`);
+ for (const item of updated) reviewEvents.emit('item:updated', item);
+ return updated;
+}
+
/**
* Update an item's title and/or description
*/
diff --git a/server/services/review.test.js b/server/services/review.test.js
index f2c84c7b4e..44682218f1 100644
--- a/server/services/review.test.js
+++ b/server/services/review.test.js
@@ -186,6 +186,58 @@ describe('review service', () => {
});
});
+ describe('bulkUpdateStatus', () => {
+ it('updates every pending item in a single write when no ids passed', async () => {
+ const { bulkUpdateStatus } = await import('./review.js');
+ const items = [
+ { id: 'a', status: 'pending', metadata: {} },
+ { id: 'b', status: 'pending', metadata: {} },
+ { id: 'c', status: 'completed', metadata: {} }
+ ];
+ readFile.mockResolvedValue(JSON.stringify(items));
+
+ const updated = await bulkUpdateStatus({ status: 'dismissed' });
+
+ expect(updated).toHaveLength(2);
+ expect(atomicWrite).toHaveBeenCalledTimes(1);
+ const written = atomicWrite.mock.calls[0][1];
+ expect(written.find(i => i.id === 'a').status).toBe('dismissed');
+ expect(written.find(i => i.id === 'b').status).toBe('dismissed');
+ expect(written.find(i => i.id === 'c').status).toBe('completed');
+ });
+
+ it('only updates items whose ids are passed in', async () => {
+ const { bulkUpdateStatus } = await import('./review.js');
+ const items = [
+ { id: 'a', status: 'pending', metadata: {} },
+ { id: 'b', status: 'pending', metadata: {} }
+ ];
+ readFile.mockResolvedValue(JSON.stringify(items));
+
+ const updated = await bulkUpdateStatus({ status: 'completed', ids: ['a'] });
+
+ expect(updated).toHaveLength(1);
+ const written = atomicWrite.mock.calls[0][1];
+ expect(written.find(i => i.id === 'a').status).toBe('completed');
+ expect(written.find(i => i.id === 'b').status).toBe('pending');
+ });
+
+ it('skips the write entirely when nothing matches', async () => {
+ const { bulkUpdateStatus } = await import('./review.js');
+ readFile.mockResolvedValue(JSON.stringify([{ id: 'a', status: 'completed', metadata: {} }]));
+
+ const updated = await bulkUpdateStatus({ status: 'dismissed' });
+
+ expect(updated).toEqual([]);
+ expect(atomicWrite).not.toHaveBeenCalled();
+ });
+
+ it('rejects invalid status values', async () => {
+ const { bulkUpdateStatus } = await import('./review.js');
+ await expect(bulkUpdateStatus({ status: 'bogus' })).rejects.toThrow('Invalid status');
+ });
+ });
+
describe('cosEvents bridge', () => {
it('auto-completes the matching review item when an agent finishes successfully', async () => {
const handler = registeredHandlers['agent:completed'];