Skip to content

fix: handle undefined manifest value in loadShardedData#799

Open
liuhaibin0528 wants to merge 1 commit into
rohitg00:mainfrom
liuhaibin0528:fix/sharded-index-undefined-value
Open

fix: handle undefined manifest value in loadShardedData#799
liuhaibin0528 wants to merge 1 commit into
rohitg00:mainfrom
liuhaibin0528:fix/sharded-index-undefined-value

Conversation

@liuhaibin0528
Copy link
Copy Markdown

@liuhaibin0528 liuhaibin0528 commented Jun 3, 2026

Problem

When upgrading from pre-v0.9.25 to v0.9.25, the sharded index loader crashes with:

TypeError: Cannot read properties of undefined (reading 'v')
    at IndexPersistence.loadShardedData

This happens because kv.get() returns undefined for keys that don't exist in the old data format, and the strict comparison manifest.value !== null evaluates to true when value === undefined, causing undefined to be passed to loadManifestData() which tries to access undefined.v.

Root Cause

In loadShardedData (src/state/index-persistence.ts:361):

if (manifest.value !== null) {  // true when value === undefined
  return this.loadManifestData(manifest.value, label);  // crashes
}

kv.get() returns undefined for non-existent keys (not null), so the strict comparison fails to catch this case.

Fix

Change to loose comparison != null which catches both null and undefined:

if (manifest.value != null) {  // false for both null and undefined
  return this.loadManifestData(manifest.value, label);
}

This allows the function to fall through to the legacy data path as originally intended.

Testing

  • Reproduced the crash on v0.9.25 with pre-existing data from v0.9.24
  • Applied fix, rebuilt, and verified sharded index loads without crash
  • Legacy data path correctly handles old format data

Summary by CodeRabbit

  • Bug Fixes
    • Fixed inconsistent handling of missing index data during persistence operations. The system now uniformly treats both null and undefined values as absent, ensuring more reliable data loading behavior.

When kv.get() returns undefined for a non-existent key, the strict
comparison (manifest.value !== null) evaluates to true, causing
undefined to be passed to loadManifestData which crashes with
'Cannot read properties of undefined (reading "v")'.

Change to loose comparison (manifest.value != null) to catch both
null and undefined, allowing the function to fall through to the
legacy data path as intended.

Fixes: sharded index crash on old data format
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

@liuhaibin0528 is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cdda31bf-0156-4a73-8c0f-b784cbd35106

📥 Commits

Reviewing files that changed from the base of the PR and between d442fee and 87a4c3f.

📒 Files selected for processing (1)
  • src/state/index-persistence.ts

📝 Walkthrough

Walkthrough

A guard condition in IndexPersistence.loadShardedData is updated to use loose equality (!= null) instead of strict inequality (!== null), treating both null and undefined manifest values as absent and preventing loadManifestData from being called with an undefined value.

Changes

Manifest Value Guard Fix

Layer / File(s) Summary
Manifest value guard
src/state/index-persistence.ts
Guard condition in loadShardedData is updated from !== null to != null, causing both null and undefined manifest values to be skipped and preventing loadManifestData from receiving an undefined argument.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops through logic clean,
Null and void now match in scene,
One line guard, undefined caught—
Manifest safety as it ought. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: handling undefined manifest values in loadShardedData. It is concise, clear, and reflects the core fix without unnecessary details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant