fix([triage-gemini-pr515-out-of-scope-findings]): atomic writes for sub-agent index/metadata + quoted-arg shell parsing#521
Merged
Conversation
…ub-agent index/metadata + quoted-arg shell parsing Four crash-safety / parsing bugs gemini surfaced during the PR #515 review. All confirmed reproducible in the current code (verified before edit). 1. server/services/commands.js — executeCommand was hand-rolling allowlist + metachar checks against a naive split(/\s+/), so any quoted argument containing whitespace (e.g. `git commit -m "msg with spaces"`) was chopped and passed to spawn as separate tokens. Now routes through the canonical validateCommand() in commandSecurity.js, which parses quoted args and runs both safety checks. 2. server/lib/fileUtils.js — createCachedStore.save was writing via writeFile, so a mid-write crash truncated the cache file. Swapped to atomicWrite (temp + rename, with the existing Windows backup-swap fallback). 3. server/services/cosAgents.js — saveAgentIndex was reimplementing the temp+rename dance with no Windows backup-swap fallback, and several sibling paths wrote agent metadata.json + index.json directly via writeFile. All converted to atomicWrite for uniform crash safety — completeAgent, the empty/initial migration writes, cleanupZombieAgents, submitAgentFeedback, archiveStaleAgents. Cross-filesystem fallback inside the rename-failure branches stays on plain writeFile (write-once data inside an error handler). Gemini also flagged the body-size limit and `*` CORS in server/index.js; both are intentional per CLAUDE.md's single-user/private-network trust model and were explicitly dismissed when the PLAN entry was written. Tests: server suite 364 files / 8097 pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Triage the four out-of-scope findings gemini surfaced during the PR #515 review. All verified reproducible before edit.
server/services/commands.js—executeCommandwas splitting commands on whitespace and ignoring quoted arguments, so e.g.git commit -m "msg with spaces"was passed tospawnas five separate tokens. Now routes through the canonicalvalidateCommand()incommandSecurity.js, which already does quote-aware parsing plus the allowlist + metachar checks.server/lib/fileUtils.js—createCachedStore.savewas writing via plainwriteFile, so a mid-write crash truncated the cache. Swapped to the existingatomicWritehelper (temp + rename, with the Windows backup-swap fallback).server/services/cosAgents.js—saveAgentIndexwas re-implementing the temp+rename dance with no Windows fallback.completeAgentand several sibling paths wrotemetadata.json/index.jsonnon-atomically. All converted toatomicWritefor uniform crash safety. The cross-filesystemwriteFilecalls inside the rename-failure error handlers stay on plainwriteFile(write-once data inside a fallback path).Gemini also flagged the body-size limit and
*CORS inserver/index.js; both are intentional per CLAUDE.md's single-user / private-network trust model and were explicitly dismissed when the PLAN entry was written.Test plan
cd server && npm test— 364 files / 8097 pass / 7 skippedcommandSecurity.test.js(41),fileUtils.test.js(85),cosAgents.test.js(1) all pass