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

address review: atomic update lock, strict index parsing, negative index guard

Adam Eivy8fcf12abfc37
diff --git a/server/routes/meatspace.js b/server/routes/meatspace.js
index 48d4ca425a..483c2368f8 100644
--- a/server/routes/meatspace.js
+++ b/server/routes/meatspace.js
@@ -181,8 +181,8 @@ router.post('/alcohol/custom-drinks', asyncHandler(async (req, res) => {
* Update a custom drink button
*/
router.put('/alcohol/custom-drinks/:index', asyncHandler(async (req, res) => {
- const index = parseInt(req.params.index, 10);
- if (!Number.isInteger(index)) {
+ const index = Number(req.params.index);
+ if (!Number.isInteger(index) || index < 0) {
throw new ServerError('Invalid index', { status: 400, code: 'INVALID_INDEX' });
}
const data = validateRequest(customDrinkUpdateSchema, req.body);
@@ -198,8 +198,8 @@ router.put('/alcohol/custom-drinks/:index', asyncHandler(async (req, res) => {
* Remove a custom drink button
*/
router.delete('/alcohol/custom-drinks/:index', asyncHandler(async (req, res) => {
- const index = parseInt(req.params.index, 10);
- if (!Number.isInteger(index)) {
+ const index = Number(req.params.index);
+ if (!Number.isInteger(index) || index < 0) {
throw new ServerError('Invalid index', { status: 400, code: 'INVALID_INDEX' });
}
const removed = await alcoholService.removeCustomDrink(index);
diff --git a/server/routes/update.js b/server/routes/update.js
index 87d81e213e..efc884d01c 100644
--- a/server/routes/update.js
+++ b/server/routes/update.js
@@ -45,10 +45,6 @@ router.post('/execute', asyncHandler(async (req, res) => {
if (!status.latestRelease?.tag) {
throw new ServerError('No release available to update to', { status: 400, code: 'NO_RELEASE' });
}
- if (status.updateInProgress) {
- throw new ServerError('Update already in progress', { status: 409, code: 'UPDATE_IN_PROGRESS' });
- }
-
const tag = status.latestRelease.tag;
// Validate tag is a well-formed semver release (e.g. "v1.27.0" or "v1.27.0-rc.1") to prevent option injection
@@ -61,10 +57,11 @@ router.post('/execute', asyncHandler(async (req, res) => {
throw new ServerError('Auto-update is not supported on Windows', { status: 400, code: 'UNSUPPORTED_PLATFORM' });
}
- // Lock out duplicate requests synchronously BEFORE spawning the update,
- // preventing the race where a second request slips in before executeUpdate's
- // first await persists the flag
- await updateChecker.setUpdateInProgress(true);
+ // Atomic check-and-set: rejects if already in progress, preventing concurrent updates
+ const acquired = await updateChecker.setUpdateInProgress(true);
+ if (!acquired) {
+ throw new ServerError('Update already in progress', { status: 409, code: 'UPDATE_IN_PROGRESS' });
+ }
const io = req.app.get('io');
diff --git a/server/services/updateChecker.js b/server/services/updateChecker.js
index b0a9424541..d7302b2709 100644
--- a/server/services/updateChecker.js
+++ b/server/services/updateChecker.js
@@ -205,13 +205,17 @@ export async function clearIgnored() {
/**
* Mark update as in progress or completed in state file.
+ * When setting to true, atomically rejects if already in progress (returns false).
+ * Returns true if the flag was set successfully.
*/
export async function setUpdateInProgress(inProgress) {
return withLock(async () => {
const state = await loadState();
+ if (inProgress && state.updateInProgress) return false;
state.updateInProgress = inProgress;
state.updateStartedAt = inProgress ? new Date().toISOString() : null;
await saveState(state);
+ return true;
});
}