Skip to content

fix: backfill schemaDefined on replicas missing the flag#503

Open
ldt1996 wants to merge 2 commits into
mainfrom
fix/schemadefined-on-replicated-tables
Open

fix: backfill schemaDefined on replicas missing the flag#503
ldt1996 wants to merge 2 commits into
mainfrom
fix/schemadefined-on-replicated-tables

Conversation

@ldt1996
Copy link
Copy Markdown
Contributor

@ldt1996 ldt1996 commented May 11, 2026

No description provided.

@ldt1996 ldt1996 requested a review from a team as a code owner May 11, 2026 20:19
Comment thread resources/databases.ts
Comment on lines 1064 to +1085
@@ -1080,6 +1082,7 @@ export function table<TableResourceType>(tableDefinition: TableDefinition): Tabl
if (sealed !== undefined) updatedPrimaryAttribute.sealed = sealed;
if (replicate !== undefined) updatedPrimaryAttribute.replicate = replicate;
if (attribute.type) updatedPrimaryAttribute.type = attribute.type;
if (needsSchemaDefinedBackfill) updatedPrimaryAttribute.schemaDefined = schemaDefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing test for the backfill path

What: The needsSchemaDefinedBackfill check introduces a two-leg runtime-shape branch (schemaDefined === undefined vs present) with no test covering the backfill leg. The normal leg (descriptor already has schemaDefined) is exercised by existing tests; the new leg is not.

Why it matters: A regression here — e.g. the write silently no-ops or persists the wrong value — would leave replica tables still missing the flag after a restart. The fix looks correct today, but without a test this is invisible to CI.

Suggested fix: Add a unit test (alongside the existing unitTests/resources/databases.test.js suite) that:

  1. Opens or creates a table (so schemaDefined=true is written to the descriptor).
  2. Manually overwrites the primary-key entry in attributesDbi with a copy that omits schemaDefined (simulating an old replica).
  3. Calls table() again with the same definition.
  4. Asserts that Table.schemaDefined === true and that the stored descriptor now contains schemaDefined: true.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 11, 2026

1. Missing test for the needsSchemaDefinedBackfill backfill path

File: resources/databases.ts:1064–1085
What: The new needsSchemaDefinedBackfill branch (attributeDescriptor.schemaDefined === undefined) has no test covering the backfill leg. Existing tests only exercise the normal path where the descriptor already carries the flag.
Why it matters: A regression (wrong value written, write silently skipped) would leave replica tables still missing schemaDefined after restart, with no CI signal.
Suggested fix: Add a test that strips schemaDefined from a stored primary-key descriptor via a direct attributesDbi.put, re-calls table(), then asserts both Table.schemaDefined === true and that the stored descriptor was updated — see inline comment for detail.

Copy link
Copy Markdown
Member

@cb1kenobi cb1kenobi left a comment

Choose a reason for hiding this comment

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

I don't know much about this, but makes sense. It would be nice if it was easy to add a test that demonstrates this fixes things.

@kriszyp
Copy link
Copy Markdown
Member

kriszyp commented May 12, 2026

What is the situation where this can occur? I thought line 907 in databases.ts consistently set this flag.
And reminder: please try to use /harper-engineering-guidelines skill to file PRs, this should automatically ensure there is an AI review prior to the PR being filed.

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.

3 participants