Commit 924d078
feat(mine): queue requests during repair-rebuild + drain after (#4)
Mirrors the existing /silent-save queue pattern for /mine. Closes a
gap JP noticed: when the daemon is in repair-mode rebuild, hook fires
that POST /mine fail outright (the rebuild replaces the collection
mid-flight; running a concurrent mine subprocess would race the
swap). The /silent-save queue covered diary writes; /mine had no
equivalent, so transcript-ingest requests during a rebuild window
were lost.
Adds three pieces, all parallel to the silent-save infrastructure:
* `_pending_mines_path()` — separate jsonl queue file (next to the
silent-save pending file).
* `_enqueue_pending_mine(payload)` — appends a /mine request body to
the queue, off-loop via asyncio.to_thread.
* `_drain_pending_mines()` — replays queued mines after rebuild via
the same subprocess pattern the live /mine endpoint uses, gated by
`_mine_sem`. Same rename-then-read pattern as
`_drain_pending_writes` so concurrent /mine POSTs landing during
the drain go to a fresh queue file. Dedup by (dir, wing, mode)
before replay — a storm of hook fires queues the same target many
times, but one mine catches up all of them via convo_miner's
mtime-based dedup, so we don't need to run it N times.
The /mine endpoint checks `_repair_state` and queues if in rebuild
mode, returning `{"queued": true, "reason": "repair-in-progress"}`
to signal the caller. After the rebuild completes,
`_drain_pending_mines()` runs alongside `_drain_pending_writes()`.
Also extends `/repair/status` to surface `pending_mines` count
alongside `pending_writes`.
Tests: 5 new unittest cases — pending-mines path is distinct from
writes, enqueue→drain replays each target, drain dedups repeated
targets (hook-storm scenario), failed replays quarantine to
.failed-* files instead of getting lost, empty queue returns 0.
NOT a fix for the HNSW corruption that prompted the current incident
— that came from concurrent update_drawer calls hitting chromadb's
HNSW concurrency hazards (CLAUDE.md row 15). The corruption-side fix
is `PALACE_MAX_WRITE_CONCURRENCY=1` in the daemon env. This PR
covers a separate failure mode: hook writes during repair windows.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent dedface commit 924d078
2 files changed
Lines changed: 282 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
323 | 425 | | |
324 | 426 | | |
325 | 427 | | |
| |||
1164 | 1266 | | |
1165 | 1267 | | |
1166 | 1268 | | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
1167 | 1295 | | |
1168 | 1296 | | |
1169 | 1297 | | |
| |||
1381 | 1509 | | |
1382 | 1510 | | |
1383 | 1511 | | |
| 1512 | + | |
1384 | 1513 | | |
1385 | 1514 | | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
1386 | 1519 | | |
1387 | 1520 | | |
1388 | 1521 | | |
1389 | 1522 | | |
1390 | 1523 | | |
1391 | 1524 | | |
1392 | 1525 | | |
| 1526 | + | |
1393 | 1527 | | |
1394 | 1528 | | |
1395 | 1529 | | |
1396 | 1530 | | |
1397 | 1531 | | |
1398 | 1532 | | |
1399 | 1533 | | |
1400 | | - | |
1401 | | - | |
1402 | | - | |
1403 | | - | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
1404 | 1538 | | |
1405 | | - | |
1406 | | - | |
| 1539 | + | |
| 1540 | + | |
1407 | 1541 | | |
1408 | | - | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
1409 | 1546 | | |
1410 | 1547 | | |
1411 | 1548 | | |
1412 | 1549 | | |
1413 | | - | |
1414 | | - | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
1415 | 1554 | | |
1416 | 1555 | | |
1417 | 1556 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
0 commit comments