Commit b3d9cd2
fix: drain before invalidating watchers, keep cache-clear on failed cleanup
- indexer.ts: the generation bump ran before drainWatcherOps(), so a watcher
that had already completed addDocs() would see itself stale and return
without recording those chunks in pathChunkCounts. The rebuild then computed
staleIds from counts that omitted them and they survived in the index.
`indexing` already blocks new watcher work, so the drain now happens first —
letting in-flight operations record what they wrote — and the generation is
bumped afterwards to cover anything that slips through.
- indexer.ts: discardPartialIndex() reset discardedPreviousIndex when the
delete failed, which made the caller skip clearIndexCache() and leave a
meta.json describing the previous documents — already deleted by this
rebuild. restoreFromMeta() would then report a ready index for documents
that no longer exist on the next launch, which is worse than the leftovers
it was protecting. The flag now stays true so the stale cache is dropped,
while pathChunkCounts is kept for a retry in the same session. This reverses
the choice made in bc906da.
- server.py: runner.run() can end on a transport or LLM error, reaching none
of the disconnect / watchdog / lifespan paths, and the finally discarded the
only session handle without cancelling grade tasks — leaving a grader
subprocess and its Ollama request running until timeout, then queueing into
a dead worker. The finally now awaits session.shutdown() first, suppressed
so teardown cannot mask the original error.
Verified: a watcher writing two chunks as a rebuild starts is stranded under
bump-before-drain and cleaned up under drain-then-bump; a failed partial
cleanup now still clears the cache while keeping the counts; and a runner error
leaves the grader alive without the shutdown call and terminated with it, with
shutdown() confirmed safe to call twice.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent bc906da commit b3d9cd2
2 files changed
Lines changed: 23 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
961 | 961 | | |
962 | 962 | | |
963 | 963 | | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
964 | 971 | | |
965 | 972 | | |
966 | 973 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
115 | 116 | | |
116 | 117 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | 118 | | |
121 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
122 | 126 | | |
| 127 | + | |
| 128 | + | |
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
| |||
482 | 488 | | |
483 | 489 | | |
484 | 490 | | |
485 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
486 | 498 | | |
487 | 499 | | |
488 | 500 | | |
| |||
0 commit comments