Skip to content

fix(storage): preserve LockAcquisitionError through write_context (#4612) - #5764

Open
akushonkamen wants to merge 1 commit into
volcengine:mainfrom
akushonkamen:fix/4612-lock-error-propagation
Open

akushonkamen wants to merge 1 commit into
volcengine:mainfrom
akushonkamen:fix/4612-lock-error-propagation

Conversation

@akushonkamen

Copy link
Copy Markdown
Contributor

Description

#4615 (merged 2026-09-08) added except LockAcquisitionError: raise guards so
that lock conflicts in the semantic queue are re-enqueued without tripping the
API circuit breaker. On main those guards are defeated at the
VikingFS.write_context boundary: the function's catch-all wraps every
internal failure into a bare IOError without from e, destroying the
exception type before any guard can see it:

  • openviking/storage/viking_fs/_semantic.py (write_context):
    raise IOError(f"Failed to write {uri}: {e}") — no from e, so
    __cause__ is empty and the type is gone.
  • semantic_processor._process_memory_directory's
    except LockAcquisitionError: raise (fix(memory): preserve semantic lock errors for abstract retries #4615) never matches; the error falls
    into the generic RuntimeError wrap.
  • The top-level handler's isinstance(e, LockAcquisitionError) check
    (semantic_processor) never matches either, so lock conflicts are treated
    as transient/unknown errors: re-enqueued with breaker.record_failure.
    Clustered lock contention during batch reindex therefore accumulates breaker
    failures and can open the breaker for unrelated VLM calls — matching the
    v0.4.20 follow-up in [Bug]: v0.4.17.1 L0 directory abstracts not generated — Lock error wrapping + missing parent rollup #4612 (internal error: encrypted write lock error: lock acquire timed out after 1001ms).
  • classify_api_error (utils/model_retry.py) walks only __cause__
    (not __context__), so it classified the wrapped lock error as unknown.

The same wrapping also affects the L0/L1 directory bootstrap path
(DirectoryInitializer._ensure_agfs_directory → write_context), which is
where .abstract.md / .overview.md contention surfaces during memory
writes.

This PR is intentionally narrow: it only restores lock-error type
propagation. It does not implement parent rollup / L0 vector backfill
(Bug 2), does not enqueue memory writes into SemanticQueue (deliberate cost
control per maintainer feedback in #4612; open PR #4657 covers that
direction), does not change reindex task terminal states (main already has a
tracker.fail path), and does not touch ov backup --include-vectors.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Fixes #4612 (the "lock error type swallowed" residual defect; see scope note above)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

In openviking/storage/viking_fs/_semantic.py, write_context:

  1. Add except LockAcquisitionError: raise ahead of the generic wrap, so
    lock conflicts keep their type and the existing fix(memory): preserve semantic lock errors for abstract retries #4615 guards
    (semantic_processor / semantic_executor "Let SemanticProcessor
    re-enqueue this recoverable conflict") become effective again.
  2. Chain the generic wrap with from e, so __cause__ carries the original
    error for classify_api_error's cause traversal and for log chains.
  3. Other bare raise IOError(...) wrap points in the same file are left as
    they are; they are recorded here as follow-up candidates only
    (_semantic.py internal helpers), not changed in this PR.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS (arm64, macOS 15)
    • Windows

New tests (tests/storage/test_write_context_lock_error.py, all offline; the
real mixin methods run against a minimal fake _async_agfs, no LLM/storage/
local config):

  • write_context re-raises LockAcquisitionError when an internal file
    write hits a lock conflict (message matches the [Bug]: v0.4.17.1 L0 directory abstracts not generated — Lock error wrapping + missing parent rollup #4612 report verbatim:
    ... lock acquire timed out after 1001ms) — failed before this fix
    (surfaced as OSError);
  • same for a lock error raised while creating the directory itself — failed
    before;
  • non-lock failures still surface as IOError, but with __cause__ chained
    to the original exception (__cause__ was None before);
  • guard-rail: _process_memory_directory re-raises LockAcquisitionError
    unwrapped (the fix(memory): preserve semantic lock errors for abstract retries #4615 guard this fix restores for wrapped paths);
  • guard-rail: top-level on_dequeue handling takes the lock-specific requeue
    path (_requeue_semantic_msg_after_error, no breaker.record_failure),
    not the transient branch.

Test results (local, uv run pytest ... --no-cov -q):

 volcengine#4612

VikingFS.write_context wrapped every internal failure into a bare
IOError without 'from e', destroying the exception type before the
semantic queue's lock-retry guards could see it:

- the 'except LockAcquisitionError: raise' guards added by volcengine#4615
  (semantic_processor._process_memory_directory, semantic_executor)
  never matched, so lock conflicts fell through to the generic
  RuntimeError wrap;
- the top-level handler treated them as transient/unknown errors and
  recorded circuit-breaker failures, so clustered lock contention
  during reindex could open the breaker and take down unrelated VLM
  calls;
- classify_api_error only inspects __cause__ (not __context__), so it
  classified the wrapped lock error as unknown.

- Add 'except LockAcquisitionError: raise' ahead of the generic wrap so
  lock conflicts keep their type, letting the existing re-enqueue
  without breaker path work as designed.
- Chain the generic wrap with 'from e' so __cause__ carries the
  original error for classify_api_error and log chains.

fixes volcengine#4612

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Core server, runtime, storage, retrieval, SDK, and CLI.

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Bug]: v0.4.17.1 L0 directory abstracts not generated — Lock error wrapping + missing parent rollup

2 participants