Description
Describe the bug
Early releases allowed records to carry a scope ID before Scope was stored as a separate entity. When the historical migration finds such an ID without a matching row in pc_scopes, it preserves the ID but inserts empty strings for both title and summary (#2394). Neither value satisfies the ScopeDescriptor API contract introduced in #1401. A single invalid descriptor prevents the entire page of otherwise valid scopes from being returned.
Steps to reproduce
- Start with a historical database that has a source referencing a scope ID but no corresponding descriptor. Include another scope with valid metadata.
- Upgrade through the historical migration to 1.6.0.
- Make an authenticated GET /v1/scopes?limit=50 with both scopes on the first page. Open the Dashboard scope picker without a search term.
Actual behavior
On an upgraded SeekDB installation, migration reported ready, yet the unfiltered list returned HTTP 422 (invalid_request, string_too_short for title and summary). The picker showed only the current scope. Searching specifically for a different, valid scope succeeded. The database contained a descriptor with two empty strings; whether that particular row already existed before upgrade has not been established.
Expected behavior and regression coverage
- Upgrading historical data yields descriptors the API can return, without changing scope IDs, losing linked records, or overwriting valid metadata.
- Provide a repair path for databases already marked ready that contain invalid descriptors.
- Cover both cases with a regression test that checks the unfiltered scope list returns HTTP 200 and includes the recovered and unaffected scopes.
Environment
PowerContext 0.2.1 development build upgraded to 1.6.0; embedded SeekDB, Python 3.12, macOS.
Are you willing to submit a PR?
Yes, I would like to submit a PR.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
Zxf-xufeng commentedon Nov 26, 2026
Affected upgrade paths
This issue affects upgrades across SQLite, embedded SeekDB, and OceanBase whenever a database goes through the historical migration backfill in
historical._scopes()(introduced in #2394, shipped inv1.5.0+) and anypc_*table contains ascope_idwithout a matching row inpc_scopes:Direct upgrade from pre-
pc_scopesreleases (v0.0.1,v0.0.2,v0.1.0) tov1.5.0–v1.6.0(with existing data)pc_scopeswas introduced inv0.2.0(feat: implement scope organization runtime for RFC #1345 #1401).historical._scopes()scans allpc_*tables with ascope_idcolumn and inserts missing rows intopc_scopeswithtitle = ''andsummary = ''.ScopeDescriptorvalidation (min_length=1,pattern=".*\S.*") onGET /v1/scopes, causing the entire page to return HTTP 422.Multi-hop upgrade starting on
<= v0.1.0, upgraded in place throughv0.2.0–v1.4.x, then upgraded tov1.5.0–v1.6.0create_all()) onv0.2.0–v1.4.xcreatedpc_scopeswithout backfilling legacyscope_idvalues left inpc_sources,pc_artifacts, etc. (those tables do not have a foreign key topc_scopes).pc_schema_revision, upgrading tov1.5.0+ enters historical admission and runshistorical._scopes()whenever any compatibility step is pending (historical_structure,historical_processing, orhistorical_atomic_memory), backfilling those orphanedscope_idvalues with empty strings.Subsequent upgrades from an already-migrated
v1.5.0/v1.5.1/v1.5.2database tov1.6.0v1.5.x, the empty-string rows are already stored inpc_scopeswhilepc_schema_revisionis marked ready, so upgrading further tov1.6.0carries the invalid rows forward.Any pre-
pc_schema_revisiondatabase (<= v1.4.x) containing orphanedscope_idvaluesv0.2.0+, if anypc_*table contains ascope_idmissing frompc_scopes(for example from direct database writes or unmanaged tooling),historical._scopes()will backfill it withtitle = ''andsummary = ''.Paths not affected
v0.2.0+ that only wrote through normal Server APIs (whereScopeDraft/ScopeMutationrequire non-emptytitleandsummary, and_scope_operation()verifies the scope exists before writes), as well as databases already managed underpc_schema_revisionwithout pre-existing empty descriptors.Checking an upgraded database
DEMONCODEX commentedon Nov 26, 2026
I'll take this.
hireview001 commentedon Dec 2, 2026
This issue belongs to the Core module. @hidb4ai, please lead follow-up, with support from @frf12, @Fengzdadi, @beatenevo. Please provide a substantive response within 72 hours of issue creation, outlining the proposed disposition, any additional information needed, or the next investigation steps. After sufficient discussion and agreement on the scope and acceptance criteria, a contributor who volunteers to take it on can undertake implementation.
hidb4ai commentedon Dec 3, 2026
Confirmed the API failure with real SQLite and the current ASGI application. After creating a valid Scope, I seeded empty title/summary fields to represent an invalid historical descriptor.
GET /v1/scopes?limit=50then returned 422 withstring_too_shortvalidation errors, instead of a usable list.This reproduces the read-path symptom; it is not a full released-version upgrade replay. The repair in #2877 should cover both historical backfill and databases already admitted with invalid descriptors, preserve Scope IDs and valid metadata, and verify successful listing after repair/restart. The supported backend upgrade matrix still needs separate acceptance.
Validation baseline:
masteratd896b799ab316a452e868565c228f6807818e734.