fix(store,server): resolve four store data-loss/traversal bugs (#499 #500 #501 #502) - #520
Draft
TYRMars wants to merge 1 commit into
Draft
fix(store,server): resolve four store data-loss/traversal bugs (#499 #500 #501 #502)#520TYRMars wants to merge 1 commit into
TYRMars wants to merge 1 commit into
Conversation
…500 #501 #502) Auto-resolves a batch of related code-review findings in the JSON-file store layer plus the WS chat save path. #502 atomicWrite shared `.tmp`: all concurrent writers of one target shared a single staging file, so the loser's rename hit ENOENT and its turn was silently dropped. Stage to a unique per-write name (`<path>.<pid>.<uuid>.tmp`) with best-effort cleanup on failure, making last-writer-wins the real semantics. #501 JsonFileConversationStore.list unguarded shape: one foreign-but-parseable `.json` in the base dir (e.g. workspaces.json) dereferenced `stored.messages.length` and threw a TypeError that permanently 500'd GET /v1/conversations. Guard `Array.isArray(messages)` and wrap the per-file body in try/catch so a bad entry is skipped, not fatal — matching activity-store / observability behaviour. #499 encodeId `..` partition escape: `encodeId` keeps `.` in its safe set, so a `project_id`/`requirement_id` of `..` joined as a directory component climbed out of the store partition into the sibling conversation dir. Add `encodeSegment`, which neutralises all-dots segments, and use it in every directory-component call site (requirement / requirement-run / comment / activity / doc stores). Filename call sites (with the `.json` suffix) are unaffected. #500 WS chat save erased metadata: the WS turn-completion handler called `store.save()`, which hard-codes `defaultMetadata()`, so every chat turn wiped the conversation's `project_id` and un-archived it. Track `ConversationMetadata` across the socket (seeded from `loadEnvelope` on resume, reset on reset/new) and round-trip it via `saveEnvelope`, matching the REST message routes. Adds regression tests for the concurrent-write, foreign-file, encodeSegment, and partition-containment cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NKLVVpJ3ckDHgYMrP867bd
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.
Auto-resolves a batch of related JSON-file store findings filed by the scheduled
crcode-review task. All four live inpackages/store/src/(plus one WS call site inpackages/server) and interlink, so they're fixed together.Fixes
#502 —
atomicWriteshared.tmp→ silent turn loss on concurrent writesAll concurrent writers of one target shared a single
<path>.tmp; whoever renamed first consumed it and the loser'srenamehitENOENT, silently dropping a turn (reachable via double-submit / two tabs onPOST /v1/conversations/:id/messages, which catch-and-ignore the save error).<path>.<pid>.<uuid>.tmpwith best-effort cleanup on failure. Last-writer-wins becomes the real semantics; no more ENOENT.#501 —
JsonFileConversationStore.listunguarded shape → permanent 500One foreign-but-parseable
.jsonin the base dir (e.g.workspaces.jsonfromJsonFileWorkspaceStore) dereferencedstored.messages.length, throwing aTypeErrorthat escapedlist()and permanently 500'dGET /v1/conversations.Array.isArray(stored.messages)and wrap the per-file body intry/catch, so a bad entry is skipped rather than fatal — matchingactivity-store/observability.#499 —
encodeId..partition escape (security)encodeIdkeeps.in its safe set, soencodeId("..") === ".."; joined as a directory component it climbs out of the store partition into the sibling conversation dir (aproject_idof..corrupts the conversation listing).encodeSegment, which neutralises all-dots segments (.→%2E,..→%2E%2E), and use it in every directory-component call site: requirement / requirement-run / comment / activity / doc stores. Filename call sites (with the.jsonsuffix) are unaffected.#500 — WS chat
save()erases conversation metadataThe WS turn-completion handler called
store.save(), which hard-codesdefaultMetadata(), so every chat turn wiped the conversation'sproject_idand resetlifecycletoactive(requirement-run conversations lost their project link the first time a user chatted over the WS).ConversationMetadataacross the socket (seeded fromloadEnvelopeonresume, reset onreset/new) and round-trip it viasaveEnvelope, matching the REST message routes.Tests
Added regression tests covering: concurrent same-id writes no longer ENOENT and leave no
.tmplitter;list()skips a foreign JSON with nomessagesarray;encodeSegmentneutralises./..while leaving normal ids intact; aproject_idof..stays inside therequirements/partition and never lands in the base dir.Verification
pnpm --filter @jarvis/store typecheck— cleanpnpm --filter @jarvis/server typecheck— cleanpnpm lint— 0 errors (1 pre-existing warning in an unrelated test file)better-sqlite3andnode-ptynative binaries can't compile, webdist/absent) and are identical with the changes stashed.Generated by Claude Code