Skip to content

[finding] metadata: database-loader spells its own driver-capability predicate inline, duplicating resolveDriverExec one directory away #14121

Description

@claude

Found while implementing #14083, which aligned the three raw-SQL resolvers in packages/metadata-protocol to execute-first. This is a fourth site that carries the same predicate but is deliberately not part of that card, and it is recorded rather than folded in.

The site

packages/metadata/src/loaders/database-loader.ts, line 403, inside the engine branch of the schema-ready path:

if (c && (typeof c.raw === 'function' || typeof c.execute === 'function')) {
  driver = candidate as IDataDriver;
  break;
}

Why this is NOT the #14083 defect

⛔ It is not an order divergence, and #14083 was right to leave it alone. The check is an OR used to pick which candidate out of engineAny.drivers is raw-SQL-capable; it selects a driver, never a surface. The surface decision happens one call later, inside migrateProjectIdToEnvironmentId(driver), which already routes through packages/metadata/src/migrations/driver-exec.ts (resolveDriverExec, execute-first). Swapping the two operands here changes nothing.

What is worth recording

The predicate is spelled inline, a third time, in the same package that already owns the canonical answer. resolveDriverExec is the definition of "this driver can run raw SQL" — resolveDriverExec(d) !== undefined — and driver-exec.ts is one directory away from this file. Two consequences, both small today:

⚠️ Deliberately not claiming a live defect: the current operands are exactly the two surfaces resolveDriverExec tries, so the predicate and the resolution agree today. This is a drift-risk observation, not a measured misbehaviour.

Known limitation this inherits, unchanged

typeof driver.execute === 'function' cannot separate "declares the surface" from "can actually run SQL" — two shipped drivers satisfy the non-optional declaration and execute nothing. That is #14082's subject, is unaffected by anything above, and would be the thing to fix first if this predicate is ever revisited.

Re-run

sed -n '395,410p' packages/metadata/src/loaders/database-loader.ts
git grep -n "resolveDriverExec" -- packages/metadata/src

Whole-tree sweep for the dual-surface shape, which is how this was found:

for f in $(git grep -lE "typeof [A-Za-z_.()]*\braw\b[^=]*=== ?'function'" -- packages apps examples); do
  grep -qE "typeof [A-Za-z_.()]*\bexecute\b[^=]*=== ?'function'" "$f" && echo "$f"
done

⚠️ That sweep needs a firing pathspec. The packages/*/src form used in #14083's original re-run block matches zero files under git's pathspec rules, so it reports a clean zero whatever the tree contains; the positive control is the same regex for execute, which finds 327 member definitions under packages.

At the time of writing the dual-surface sweep returns exactly three files: this one, packages/metadata/src/migrations/driver-exec.ts and packages/metadata-protocol/src/migrations/driver-exec.ts (the two canonical helpers). The five other raw probes in the tree are local variables named raw on HTTP headers and request objects, not driver surfaces.

Dedup declaration

Repo-scoped REST listing of all 282 open issues, bodies included, grepped locally for database-loader, resolveDriverExec, driverCanRunSql, driver-exec and capability predicate. Only database-loader matched, returning #14037 and #14038 — both members of the #13973 driver-Date-materialisation census, neither about driver-capability probing. Control: the same fetched list grepped for metadata-protocol returned 16 issues, so the channel was answering. No duplicate found.

Backlink: #14083, where the sibling package's three copies were collapsed.

Generated by Claude Code


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:p3 · domain:engine · type Task. finding removed.

    Lands in: packages/metadata/src/loaders/database-loader.ts (the inline raw/execute OR at the engine branch of the schema-ready path) — replace with resolveDriverExec(candidate) !== undefined, the package's own canonical predicate one directory over. Why hold rather than queue: the card is honest that no misbehaviour is measured — the two operands are exactly the two surfaces the resolver tries, so the copy and the canon agree today. A one-line drift-risk removal does not justify a dispatch of its own (创业阶段不扩散), but it should ride the next change that touches this file or the predicate's meaning. Two triggers, both machine-readable:

    Restart-when: closed #14082
    Restart-touch: packages/metadata/src/loaders/database-loader.ts

    Rationale for the closed-form trigger: #14082 is the card the finding itself names as "the thing to fix first if this predicate is ever revisited" (a declared execute that runs nothing) — whichever way #14082 resolves, the definition of "can run raw SQL" is re-decided there, and this copy must follow it in the same breath. The touch trigger makes it the declared rider for whoever next edits the loader.

    (Hold provenance: triage seat grading, 2026-09-02; no maintainer ruling involved.)


    Generated by Claude Code

  2. added theissue type on Sep 2, 2026
  3. objectstack-fleet commented on Sep 23, 2026

    @objectstack-fleet
    Contributor

    关 not_planned —— 维护者逐张复核 on-hold 卡时同意关闭;与 #14082 同批

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

    现状(origin/main c1dfa5241b)

    packages/metadata/src/loaders/database-loader.ts:520 仍是内联的 typeof c.raw === 'function' || typeof c.execute === 'function'(卡面写的是 :403,文件后来长了);标准函数 resolveDriverExec 在 packages/metadata/src/migrations/driver-exec.ts:84。两者今天结论一致,没有任何错误行为 —— 本卡记录的只是以后可能走样的重复。

    为什么关

    给以后改到这个文件的人

    下次任何 PR 因为别的原因改 database-loader.ts 的这一段,顺手把内联判断换成对 resolveDriverExec 的调用即可 —— ⛔ 不值得为它单独开一轮。若两处判断真的开始给出不同答案(例如 resolveDriverExec 的判据变了而这里没跟上),那就是一个真实缺陷,另立新卡并引用本卡。

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


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions