Skip to content

driver-mongodb: bulkUpdate's single bulkWrite is only atomic when the caller supplies a session — a mid-batch refusal without one leaves earlier ops applied #14169

Closed as not planned

Description

@os-support-ai

Measured while implementing #13854 (SqlDriver.bulkUpdate transaction wrapper). #13854's dispatch owed one reading: does driver-mongodb carry the same shape? This card records the answer, which is "not the same shape, but a related exposure" — filed separately rather than widened into #13854's PR, exactly as that card's scope required.

The reading (measured on origin/main, by symbol)

packages/drivers/driver-mongodb/src/mongodb-driver.ts:

So the per-row autocommit loop #13854 repaired does not exist here. That half of the reading is settled.

Why this is still worth a card

The consequence class may nevertheless be reachable, through a different mechanism. bulkWrite defaults to ordered: true, which stops at the first failing operation — but operations already applied are not undone unless the operation is running inside a transaction. When the caller passes no options.transaction, session is undefined, so a batch refused partway through would leave the earlier updateOne ops applied: the same end state #13340 / #13435 / #13854 closed on the other two drivers, arrived at by a different route.

⚠️ Split by evidence, because the two halves are not equally established:

Why the #13854 fix does not simply transfer

⛔ Do not assume the repair is "wrap it in a transaction like the SQL driver". MongoDB multi-document transactions require a replica set (or a sharded cluster) — they are unavailable on a standalone mongod, which is a supported deployment. So an unconditional driver-opened transaction would turn a currently-working call into a hard failure on those deployments. That is a genuine decision, not a mechanical port, which is the other reason this is filed rather than fixed in passing.

Sketch of the option space, for whoever picks this up:

  1. Open a transaction only when the topology supports one, and document the weaker guarantee elsewhere — declared ≠ enforced, which is the shape this project usually refuses.
  2. Require the caller to supply a session for atomicity, and say so in the contract — honest, but leaves the bulk door's implied promise unmet by default.
  3. Decide the bulk door does not promise atomicity on this driver, and record that as an explicit, tested difference rather than an accident.

Related

#13854 (driver-sql, the card this reading was owed to) · #13435 · #13340 (the driver-memory half of the same defect class)

Filed unassigned and unlabelled for triage, per the dispatch's out-of-scope rules.

Generated by Claude Code

Activity

  1. huangyiirene commented on Sep 2, 2026

    @huangyiirene
    Collaborator

    Triage (R+89, triage seat, session session_019kDRpB7D2XzVzkaLp57T5D): graded → pm:on-hold · priority:p2 · domain:engine · type Task. finding removed.

    Why hold, not queue: the standing maintainer ruling of 2026-08-05 recorded on #5499 freezes defect-repair and semantic-completion investment in driver-memory / driver-mongodb ("driver-mongodb 暂无客户;创业团队集中精力,不铺大"), and its standing triage rule for new cards is verbatim: 「driver-memory / driver-mongodb 族新单照常按落点打 domain:engine,但直接挂 pm:on-hold 引用本单,不入 pm:queue」. This card's landing file is packages/drivers/driver-mongodb/src/mongodb-driver.ts (bulkUpdate), so the rule applies by construction. The freeze's escalation exception (a driver-memory defect that corrupts CI verdicts) does not reach a driver-mongodb atomicity question.

    What is preserved for the day it restarts: the card's own split — the measured half (single bulkWrite, session from options.transaction) and the unmeasured half (that a mid-batch refusal leaves earlier ops applied here) — plus the three-way option space, of which option 3 (declare and test that the bulk door does not promise atomicity on this driver) is the one that stays inside the freeze's "no investment" letter if a customer ever forces the question.

    Restart-when: closed #5499
    Restart-touch: packages/drivers/driver-mongodb/src/mongodb-driver.ts

    (Hold provenance: triage seat grading under the #5499 maintainer ruling, 2026-09-02.)


    Generated by Claude Code

  2. added
    pm:on-hold
    and removed
    finding
    on Sep 2, 2026
  3. added theissue type on Sep 2, 2026
  4. objectstack-fleet commented on Sep 23, 2026

    @objectstack-fleet
    Contributor

    关 not_planned —— 维护者逐张复核 on-hold 卡时同意关闭;MongoDB 驱动在 #5499 的投入冻结之内

    分诊席(session_01Tw7jnJinGHvoGSi8aFkhPJ),2026-09-23T10:19Z。维护者 2026-09-23 在分诊会话里逐张复核 pm:on-hold 卡,对第七组的回复原文:「其他同意」。本卡在那一组里的建议是关闭。

    读数原样保留,供以后重启时直接取用

    • 已测的一半:driver-mongodb 的 bulkUpdate 不是 driver-sql 那种逐行自动提交的循环,而是一次 collection.bulkWrite(bulkOps, { session }),session 来自 options.transaction;
    • 未测的一半:调用方不带事务会话时,批次中途被拒,之前的操作已经生效(MongoDB 的标准语义,本仓未复现);
    • 选项空间(2026-09-02T01:25Z 分诊 5502936978 记录):其中「声明并测试:本驱动的批量入口不承诺原子性」是唯一不需要事务、也不会让单机 MongoDB 部署失效的那一条。最直接的修法(一律开事务)会让单机部署直接不可用。

    为什么关

    重开条件

    #5499 解冻(出现需要 MongoDB 的客户)⇒ 带着上面的读数重开,先补测「未测的一半」,再在选项里择一。

    关闭理由:not_planned,同时摘掉 pm:on-hold。


    Generated by Claude Code

  5. removed
    pm:on-hold
    on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    domain:enginepriority:p2

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions