Skip to content

Commit dd00bdf

Browse files
yc111233claude
andcommitted
fix(reindex): add lock timeout for stale lifecycle locks
Replace LockContext with explicit acquire_point(timeout=30s) so reindex can wait for stale lifecycle locks left by crashed semantic processing instead of failing immediately with a conflict error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 89c3aa3 commit dd00bdf

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

openviking/server/routers/content.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,37 @@ async def _do_reindex(
229229
regenerate: bool,
230230
ctx: RequestContext,
231231
) -> dict:
232-
"""Execute reindex within a lock scope."""
233-
from openviking.storage.transaction import LockContext, get_lock_manager
232+
"""Execute reindex within a lock scope.
233+
234+
Uses a 30-second timeout to allow stale locks (from crashed semantic
235+
processing) to be detected and cleaned up, or for active locks to be
236+
released naturally. Without a timeout, reindex fails immediately when
237+
a lifecycle lock from semantic processing is present, even if that lock
238+
is stale or about to be released.
239+
"""
240+
from openviking.storage.errors import LockAcquisitionError
241+
from openviking.storage.transaction import get_lock_manager
234242

235243
viking_fs = service.viking_fs
236244
path = viking_fs._uri_to_path(uri, ctx=ctx)
245+
lock_manager = get_lock_manager()
246+
247+
# Create a handle with explicit timeout for lock acquisition
248+
handle = lock_manager.create_handle()
249+
try:
250+
# Acquire lock with 30s timeout (allows stale lock cleanup)
251+
acquired = await lock_manager.acquire_point(handle, path, timeout=30.0)
252+
if not acquired:
253+
raise LockAcquisitionError(f"Failed to acquire lock for {uri} after 30s")
237254

238-
async with LockContext(get_lock_manager(), [path], lock_mode="point"):
239255
if regenerate:
240-
return await service.resources.summarize([uri], ctx=ctx)
256+
result = await service.resources.summarize([uri], ctx=ctx)
241257
else:
242-
return await service.resources.build_index([uri], ctx=ctx)
258+
result = await service.resources.build_index([uri], ctx=ctx)
259+
260+
return result
261+
finally:
262+
await lock_manager.release(handle)
243263

244264

245265
async def _background_reindex_tracked(

0 commit comments

Comments
 (0)