Skip to content

fix(core): enforce bulkWrite batch response type, cardinality, and correlation #2803

Description

@yinlianghui

Baseline and relation to #2678/#2680

Minimal reproduction

Call bulkWrite for multiple input rows with writeBatch returning each of:

  1. fewer records than inputs;
  2. extra records;
  3. records in reverse order;
  4. a non-array object.

All unsafe variants reproduced 2/2.

Expected / actual

  • Expected: the batch boundary rejects or safely degrades responses that cannot prove one output per input in contract order.
  • Actual: records[i] is trusted without array/type/cardinality validation. Missing records become clean {ok:true, record:undefined}, extras are ignored, and reversed IDs are assigned to the wrong input rows.

Impact

The real import path confirmed downstream corruption: a short response reported a create with no ID; a reversed response mis-correlated IDs; async undo then left a created record permanently untracked.

Evidence and exclusions

  • Source: packages/core/src/utils/bulk-write.ts around the writeBatch success loop.
  • Import consumers: packages/rest/src/import-runner.ts result/undo mapping.
  • An undefined response throws and degrades safely; that subcase is not the bug.
  • Generic correlation may require an explicit validator/key contract; at minimum array type and exact cardinality must be enforced before success.

Required regression tests

  • Reject/degrade non-array, short, and long responses.
  • Define and test correlation/order validation for returned records.
  • Integration test that import result IDs and undo logs remain aligned with original rows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions