Repository navigation
Fix storage never becoming ready when pluginStorage has no migration record - #422
Merged
Merged
Conversation
…sent
A data.json whose pluginStorage had no migration object, e.g.
{"storageVersion": 2, "sourceOfTruthLocation": "vault-root"}, made
buildRuntimeState() throw on persistedState.migration.state. The storage
plan never resolved, so the adapter never became ready and every save
(workspaces, workflows, schedules) failed with "Storage is not ready".
PluginScopedStorageCoordinator now reads the persisted record through
readPersistedStorageState(), which returns it only when migration is an
object with a known state. Anything else is treated like an absent record:
legacy data is re-detected on disk (pending when found, not_needed
otherwise) and a fully formed record is written back. Only a well-formed
verified record skips detection, so bad data cannot suppress a migration.
persistMigrationState() and writeCacheBackendState() use the same reader.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In 5.21.1, a vault whose Nexus
data.jsonhas apluginStorageobject without amigrationsub-object never gets storage ready. Every save fails with "Failed to save workspace" / "Storage is not ready, so this change was not saved": workspaces, workflows and schedules. The shape that triggers it:It came from hand-cleaning a shipped vault's
data.json(the course Seed Vault).Root cause
PluginScopedStorageCoordinator.buildRuntimeState()readpersistedState?.migration.state. The optional chain guards onlypersistedState, so when the record exists butmigrationisundefinedornull, it throwsCannot read properties of undefined (reading 'state').prepareStoragePlan()rejects,HybridStorageAdapterinitialization fails, and every write is refused by the storage-not-ready guard.buildPersistedState()(baseState.migration.startedAt) had the same unguarded access.Fix
readPersistedStorageState()returns the persisted record only whenmigrationis an object with a knownstate(not_needed | pending | verified | failed). Otherwise it returnsundefined.buildRuntimeState(),persistMigrationState()andwriteCacheBackendState()read through it. A missing, partial or malformed record is handled exactly like an absent one, which is the path a fresh install takes (and the path the known workaround, deletingpluginStorage, takes):pending, and the normal backfill migrates it. The backfill only appends events missing from vault-root and dedups by event id, so a re-run is non-destructive;not_needed;data.json, and an existingcacheBackendrecord is preserved.verifiedrecord skips detection, so unusable data can never suppress a needed migration.plan.stateis always built by the coordinator, so downstream readers (HybridStorageAdapter) always get a complete shape.docs/changelog.mdgets an Unreleased draft entry, following the existing convention. No version bump.Tests
New
tests/unit/PluginScopedStorageCoordinator.malformedState.test.ts(14 tests). 8 of them failed onmainwith the productionTypeError:initializes a not_needed state when pluginStorage is absenttreats pluginStorage without a migration object as absent instead of throwingnormalizes %s to a not_needed state when no legacy data exists, for: null migration, migration without a state, migration with an unknown state, non-object migration, non-object pluginStorage, null pluginStoragestill migrates real legacy data when pluginStorage is partial, then persistsverifiedstill migrates real legacy data when migration is nullpersists a migration outcome when data.json still holds a partial recordwrites a fully formed record when saving cache-backend state over a partial recordpreserves cacheBackend from a partial record across the repair writekeeps the normal verified path unchangedTest plan
npm run lintclean;npm run buildpasses, includingtsc --noEmitand the CLI and connector buildscheck_live_lane_gates.pyandcheck_catalog_target.pyOKpluginStoragelackingmigration):main.jsreproduced it:HybridStorageAdapter Initialization failed: TypeError: Cannot read properties of undefined (reading 'state') at buildRuntimeState, andDefaultWorkspaceManagerfailed with "Storage is not ready";data.jsonwas rewritten withmigration.state: "not_needed";workspaceService.createWorkspace()were both saved toNexus/data/workspaces/;Notes
pluginStoragefrom itsdata.json. This PR makes Nexus tolerate that shape for anyone else who has it.🤖 Generated with Claude Code