Skip to content

Handle corrupt LanceDB reads during resume - #1882

Merged
RaghavChamadiya merged 4 commits into
repowise-dev:mainfrom
siddheshbhurke:fix/handle-corrupt-lancedb-resume
Oct 3, 2026
Merged

RaghavChamadiya merged 4 commits into
repowise-dev:mainfrom
siddheshbhurke:fix/handle-corrupt-lancedb-resume

Conversation

@siddheshbhurke

Copy link
Copy Markdown
Contributor

Summary

Handle corrupted or incomplete LanceDB vector-store reads during resume generation instead of crashing.

Changes

  • Guard LanceDBVectorStore.list_page_ids() against LanceDB read failures.
  • Log a warning with the vector-store path and recommend repowise reindex.
  • Return an empty set so generation can continue and regenerate resume state.
  • Add a regression test covering a failed LanceDB read and the warning behavior.

Verification

  • uv run pytest tests/unit/persistence/test_vector_store.py -v
  • Result: 28 passed

Closes #1765

@siddheshbhurke

Copy link
Copy Markdown
Contributor Author

Additional validation completed:

uv run pytest tests/unit/persistence/test_vector_evidence_snippet.py tests/unit/persistence/test_vector_store_batching.py -v

21 passed. Combined with the targeted vector store tests: 49 relevant tests passing.

@RaghavChamadiya

Copy link
Copy Markdown
Member

Thanks @siddheshbhurke. Returning an empty set rather than propagating is the right call for list_page_ids specifically: the caller uses it to decide what resume can skip, so an unreadable store degrading to "skip nothing" regenerates everything, which is correct if slow. Naming repowise reindex in the message is what makes it recoverable instead of just survivable, and using logging.getLogger(__name__) matches vector_store/_base.py next door rather than the structlog half of the package.

Your CI red is real but it is not your fix, and you cannot reproduce it the way you ran it. All three Pythons fail on one assertion, your new one:

FAILED tests/unit/persistence/test_vector_store.py::test_lancedb_list_page_ids_handles_corrupt_store
  AssertionError: assert 'vector store may be damaged' in ''
  +  where '' = <LogCaptureFixture>.text

The list_page_ids() == set() assertion above it passes, so the guard works. Only caplog is empty.

The cause is process-wide state that an earlier test leaves behind. silence_logs_for_machine_output in packages/cli/src/repowise/cli/helpers.py:75 does this and never undoes it:

for _name in ("repowise.core", "repowise.server"):
    logging.getLogger(_name).setLevel(logging.ERROR)

Your logger is repowise.core.persistence.vector_store.lancedb_store, which has no level of its own, so its effective level comes from the nearest ancestor that does. Once any test has run a command that calls that helper, that ancestor is repowise.core at ERROR, logger.warning is dropped before a handler sees it, and caplog.text is ''. Run the file on its own and nothing has poisoned the ancestor yet, which is exactly the 28-passed and 49-passed results you got.

tests/conftest.py has an autouse fixture documenting this same trap for structlog, and its docstring describes your symptom almost word for word:

a filtering logger drops the event before LogCapture ever runs and the test reads an empty list. Tests collected after tests/unit/cli therefore pass alone and fail in a full run.

There is no equivalent for stdlib logging, which is the gap you have walked into.

The fix on your side is one line at the top of the test:

caplog.set_level(logging.WARNING, logger="repowise.core.persistence.vector_store.lancedb_store")

Setting the level on the logger itself stops the lookup before it reaches the poisoned ancestor, so it holds regardless of what ran first. Please avoid caplog.set_level(logging.WARNING) with no logger=, that sets the root and the ancestor still wins.

The wider problem is ours, not yours. That helper mutating global logger levels with no restore is going to keep catching people, and the conftest fixture should cover stdlib levels the way it covers structlog. I will open an issue for it and link this thread.

One small thing while you are pushing, non-blocking: there is a single blank line between test_lancedb_embed_batch_isolates_failed_chunk and your new test, and the file uses two elsewhere.

Add the caplog.set_level line and ping me. I will merge on green without another round.

@RaghavChamadiya

Copy link
Copy Markdown
Member

Filed the wider problem as #1976, which covers both the missing test-isolation fixture and giving silence_logs_for_machine_output a restore path so it is not a one-way door for in-process library callers either. Your PR is linked there as the case that surfaced it.

Nothing changes for this PR: the one-line caplog.set_level(..., logger="repowise.core.persistence.vector_store.lancedb_store") is still the right fix here, and it will keep working after #1976 lands.

@siddheshbhurke
siddheshbhurke force-pushed the fix/handle-corrupt-lancedb-resume branch from d20b923 to 4d5da9f Compare September 4, 2026 04:48
@RaghavChamadiya

Copy link
Copy Markdown
Member

@siddheshbhurke, an update and an apology for the long gap.

Two things changed in your favour. It is no longer conflicting — whatever was colliding on main has since moved, and GitHub now reports this as mergeable. And CI had never actually run on your latest head: the run was sitting at action_required waiting for a maintainer to approve it, which is the fork-PR default. That is on us, not on you. I have approved it just now, so the matrix is building.

More importantly, the red you saw before was not your code, and the underlying cause now has a fix in flight. The failure was the cross-test logging interaction filed as #1976: silence_logs_for_machine_output raised the level on the repowise.core logger and never restored it, so any later test asserting on a caplog record from a module under that ancestor read an empty list. It passes when the file runs alone and fails only in a full run, which is exactly the shape you hit.

@Aman-goel-04's #2011 fixes that properly, with an autouse fixture in tests/conftest.py that restores the levels between tests. I reviewed it today and it is right; it is waiting on one rebase.

So you have two ways forward and I am happy with either:

  1. Wait for fix: restore logger levels after silencing machine output #2011. If it lands first, your test should go green with no change from you at all.
  2. Do not wait, and add the explicit level to your own test now:
    caplog.set_level(logging.WARNING, logger="repowise.core.persistence.vector_store.lancedb_store")
    That is correct on its own terms regardless of fix: restore logger levels after silencing machine output #2011, since a test asserting on a log record should name the logger it expects the record from.

The guard itself I have no further notes on. Let me know which you would rather do, or just push and I will pick it up.

@RaghavChamadiya

Copy link
Copy Markdown
Member

Thanks @siddheshbhurke for adding the logger-specific caplog level. I missed commit 4d5da9f when I commented on 11 September: the exact line was already present, and the current Python 3.11, 3.12, and 3.13 jobs all pass. Correcting that clearly here.

The only branch-owned failure left is Ruff I001 in tests/unit/persistence/test_vector_store.py: import logging and import math are split into two standard-library groups. Put them in one sorted block and push that small cleanup. After that, this is ready on my side. #2011 is no longer a dependency for this PR because your explicit logger level already isolates the assertion.

@RaghavChamadiya

Copy link
Copy Markdown
Member

@siddheshbhurke I approved the workflow run on your 5c5eb1a head, and it came back red on all three Python versions. It is not your change. The failure is:

AssertionError: packages/types/src/generated/http.ts is stale. Run: python scripts/generate_http_types.py

That guard compares a committed TypeScript file against the live FastAPI schema. Your branch touches lancedb_store.py and test_vector_store.py and nothing else, so it cannot have moved that contract. Main was briefly red on this around 16 September, which is the base your branch carries, so the failure came with the base and not with your work.

A rebase is all it needs:

git fetch origin && git rebase origin/main

I verified that guard passes on current main, all 18 cases, so a rebased run should be clean.

Two things I confirmed on your branch while I was there, both of which were in doubt in the earlier thread and both of which are fine: the ruff import ordering is fixed in 5c5eb1a, and the logger-scoped caplog.set_level(..., logger="repowise.core.persistence.vector_store.lancedb_store") is present in the test.

So the guard itself, returning an empty set so resume degrades to regenerating everything, is reviewed and right. Push the rebase and I will merge it on green with no further review. Sorry this has dragged since August.

# Conflicts:
#	packages/core/src/repowise/core/persistence/vector_store/lancedb_store.py
#	tests/unit/persistence/test_vector_store.py

@RaghavChamadiya RaghavChamadiya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @siddheshbhurke, and sorry this waited after the review. Catching the read failure in list_page_ids and telling the user to run repowise reindex, instead of letting resume crash, is the right degradation. To save you a round trip, I merged main into your branch and resolved the two conflicts (the new import and constants block in lancedb_store.py, and the appended tests); your change is untouched apart from putting back a ``IN`` in a comment. Ruff and the 34 vector store tests pass on top of current main. Nothing needed from you, merging.

@RaghavChamadiya
RaghavChamadiya merged commit 84f0afb into repowise-dev:main Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Crashed when generating pages.

2 participants