Skip to content

Commit ef6ac03

Browse files
rboarescuclaude
andcommitted
fix: remove redundant fast-path queue check, harden pending-writes path
- /silent-save: drop the lock-free fast-path queue check (lines removed). The semaphore-protected re-check inside _write_sem is the correct gate; the fast-path was redundant and misleading about thread safety. - _pending_writes_path: replace `or "/tmp"` fallback with `or os.path.expanduser("~")` — avoids world-writable /tmp if palace_path is ever malformed. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 161b3ef commit ef6ac03

1 file changed

Lines changed: 3 additions & 19 deletions

File tree

main.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ async def _exclusive_palace():
187187
def _pending_writes_path() -> str:
188188
"""Location of the jsonl queue that holds silent-saves during rebuild."""
189189
palace_path = _mp._config.palace_path
190-
parent = os.path.dirname(palace_path.rstrip("/")) or "/tmp"
190+
parent = os.path.dirname(palace_path.rstrip("/")) or os.path.expanduser("~")
191191
return os.path.join(parent, "palace-daemon-pending.jsonl")
192192

193193

@@ -602,25 +602,9 @@ async def silent_save(request: Request, x_api_key: str | None = Header(default=N
602602
if msg_count <= 0:
603603
msg_count = 1
604604

605+
# Acquire write slot, check rebuild flag under lock, then write or queue.
605606
# Queue only when /repair is doing a rebuild — other modes (light/scan/
606-
# prune) don't replace the collection out from under in-flight writes,
607-
# so silent-saves can proceed normally.
608-
queue_writes = (
609-
_repair_state["in_progress"]
610-
and _repair_state.get("mode") == "rebuild"
611-
)
612-
613-
# Fast-path: rebuild in progress, queue immediately.
614-
if queue_writes:
615-
await _enqueue_pending_write(body)
616-
return {
617-
"count": msg_count,
618-
"themes": themes,
619-
"queued": True,
620-
"systemMessage": messages.save_queued(msg_count, themes),
621-
}
622-
623-
# Normal path: acquire write slot, re-check flag under lock, then write.
607+
# prune) don't replace the collection out from under in-flight writes.
624608
async with _write_sem:
625609
if (
626610
_repair_state["in_progress"]

0 commit comments

Comments
 (0)