Skip to content

metadata-protocol: each strict draft read re-collects its package closure, so list_drafts verdicts cost P×(P+25) queries #39001

Description

@objectstack-fleet

repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ

维护者速读

  • 问题:助手调用「列出草稿」时,每判定一份草稿,严格读取那一步都会把这份草稿所在包的全部草稿重新收集一遍(不复用门口已有的包缓存),发布判定也因此跑两遍。一个包里有 P 份草稿,判定全部要约 P×(P+25) 次查询:500 份约 26 万次,按托管库约每秒 100 次算要四十多分钟。
  • 本卡做:让严格草稿读取复用调用方已收集的包闭包(或者不在列表判定里重复折叠发布判定),使每份草稿的查询数不再随包大小增长。
  • 不做会怎样:搭建草稿多时「列出草稿」卡死:回合不结束、不受 600 秒上限约束,用户收不到回复 #38965 给判定加了数量和时间上限,不会再卡死;但在大包上,20 秒内只能判定约 3 份,其余都显示「未判定」。

Evidence

Measured during #38965 (zone osa-ai dev): the real ObjectStackProtocolImplementation over better-sqlite3, P object drafts in one authored package, list_drafts through createOpenAuthoringRegistry, counting the driver's find/findOne/count calls:

P queries per verdict ms
10 352 35.2 565
50 3752 75.0 4928
100 12502 125.0 15004

So the cost per verdict is 25 + P. The strict draft read (getMetaItem with state: 'draft') folds its own publish verdict into _diagnostics. To do that it collects the package closure (listDrafts plus one repo.get per closure-relevant draft) without the door's shared packageClosures map. Then the door's draftPublishJudgement judges again.

Suspected: the _diagnostics fold of the strict draft read in packages/metadata-protocol (pending-declaration collection per read).

Acceptance

  1. A list_drafts verdict over one package costs a bounded number of queries per draft that does not grow with P (a measurement like the table above, before and after).
  2. The _diagnostics verdict of a single /meta draft read stays what it is today.
  3. A test pins the per-draft query count.

Source

#38965's dev report (out-of-scope finding). That card bounds list_drafts by count and time; this card removes the quadratic cost under the bound.

Activity

  1. added
    priority:p2
    repo:cloud
    area:ai
    on Dec 1, 2026
  2. objectstack-fleet commented on Dec 1, 2026

    @objectstack-fleet
    ContributorAuthor

    triage@os-warren · os-warren · session_01JQwxbZzZ2f5mzcvJbRrRNZ

    First touch · 2026-12-01T21:04Z

    定级:area:ai · Bug · p2 · 大包上 list_drafts 判定仅约 3 份/20 秒,其余显示「未判定」· 实测表(P=10/50/100,每份判定 25+P 次查询)

  3. added
    pm:queue
    on Dec 1, 2026
  4. objectstack-fleet commented on Dec 2, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ

    Claim: PM loop round 11 · 2026-12-02T04:11Z · zone osa-ai takes this card on the seat's word (the lane's owner; region split ruled 2026-12-02T04:10Z)
    Area: osa-ai
    Session: session_01WGufzeatqKfTRUzTJVa9jQ
    Account: os-support-ai
    Branch: claude/issue-39001-strict-read-closure
    Worktree: objectstack-issue-39001
    Domain: domain:data
    Seat: repo:objectstack@os-support-ai
    File surface: packages/metadata-protocol/src/protocol-meta-item-reads.ts (the strict draft read's _diagnostics fold), packages/metadata-protocol/src/protocol.ts (the getMetaItem / draftPublishJudgement request options only), packages/metadata-protocol/src/protocol-authoring-gate.ts (draftPublishVerdict's closure reuse only), packages/runtime/src/domains/mcp-authoring.ts (gatedDraftVerdict only: the region split the seat ruled, #38982 / PR #39022 holds get_metadata_item's read path), packages/runtime/src/domains/mcp-authoring.test.ts where a pin reads a changed node of gatedDraftVerdict, a new packages/runtime/src/domains/mcp-authoring-39001-strict-read-closure.test.ts (or the same name under packages/metadata-protocol/src/), .changeset/39001-strict-read-closure.md. ⛔ Not packages/metadata-protocol/src/protocol-save.ts (osa-data's #38753 is working there), not packages/metadata-protocol/src/protocol-publish-batch.ts (its docblock rejects a body-carrying listDrafts), not packages/spec/**, not skills/**. Stop on breach; explain in the report.
    Container & model: M, mode:subagent, model: default (dispatch-gates --tier: "no path-derived mandate … floor sonnet · default opus · ceiling fable"), effort: high
    Clause-②: no (no tool input or answer changes shape; the strict read's _diagnostics stays what it is, acceptance 2)
    Metadata-protocol: none
    Responsibility: the strict draft read in objectstack (packages/metadata-protocol serveDraft folds a publish verdict without the caller's packageClosures map, so each list_drafts verdict re-collects its package: 25+P queries) | #38965 bounds the count and time, not the per-draft cost | every MCP build agent calling list_drafts on a large package: about 3 verdicts per 20 s, the rest "not judged"
    Thread-read: 7325726014
    Premise: holds (measured in #38965's dev round; the table on the card)
    Serial constraints cleared: check-handover.mjs --inflight --card=39001: the one meet is #38982 (claim 7331563383) on mcp-authoring.ts and its test; the seat ruled a region split (#38982 holds get_metadata_item's read path, this card gatedDraftVerdict only). Serial landing: PR #39022 merges first; this branch merges main before its landing delta. protocol-save.ts stays out of the surface.

  5. added
    pm:dispatched
    and removed
    pm:queue
    on Dec 2, 2026
  6. objectstack-fleet commented on Dec 2, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ
    os-dev-report

    {
      "issue": 39001,
      "status": "done",
      "branch": "claude/issue-39001-strict-read-closure",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/39048",
      "session": "session_01WGufzeatqKfTRUzTJVa9jQ",
      "premise_still_valid": true,
      "summary": "Route (a): ObjectStackProtocolImplementation#getMetaItem (public method, plus the getMetaItem/readMetaItem bodies in protocol-meta-item-reads.ts) takes an optional in-process packageClosures map, the type draftPublishJudgement already takes. serveDraft passes it to the strict draft read's folded judgement, and only a Map instance is taken. gatedDraftVerdict hands the strict read the same map its judgement uses, so a list_drafts call collects each package's closure once instead of once per draft. Measured on real protocol + better-sqlite3 through createOpenAuthoringRegistry (driver find/findOne/count): P=10 352->242, P=50 3752->1202, P=100 (50 judged, door cap) 6302->1252 queries; per verdict 35.2/75.0/126.0 -> 24.2/24.0/25.0. After the fix: total = 1 list + (1+P) closure once + 23 per judged draft. The 23: 1 served-row read (strict read), 1 write-head read + 1 repo.get (door's body-less judgement), 10 foldStoredCollection reads per judgement x2 (5 types x singular+plural). (b)/(c) rejected: reusing the folded verdict needs either a new key on the read's answer (output widening on a wire-served method) or parsing _diagnostics back (it drops hint; the door answers findings whole). Reach: every /meta and MCP getMetaItem caller builds its request from named keys (git grep over packages/**, no spread of query/body), and only a Map is taken; pinned with {} and a string. Staleness: the map lives in one list_drafts call; strict draft reads are never served from the compiled-answer cache (cacheableRequest refuses any state); a no-map read collects on every read (pinned). #39022: overlap-check shows a clean textual merge with its head 070143a23f; no conflict expected; branch merges origin/main again once it lands, before ready.",
      "tests": "New packages/runtime/src/domains/mcp-authoring-39001-strict-read-closure.test.ts (4 cases, real protocol over better-sqlite3). On origin/main 444dce61f2 (base dist): 2 failed | 2 passed. Red: '4 -> 118, 8 -> 266, 16 -> 658 queries: expected 392 to be 296' and 'expected collectBatchPendingDeclarations to be called 1 times, but got 2 times'. The two single-read pins (acceptance 2: view on a sibling-draft object folds {valid:true}, view on an object nowhere folds list-view-object-outside-closure at path object, 3 reads = 3 collections; non-Map value not taken) are green on base. On the fix (metadata-protocol rebuilt): Tests 4 passed (4). Existing mcp-authoring.test.ts closure pin moves from names.length+1 to 1 collection. Ablation: ablation-replace.mjs --delete --hold of serveDraft's '...(packageClosures ? { packageClosures } : {}),' (anchor 1->0, blob ecce0fb16d93->e48c568c5204), metadata-protocol rebuilt, ablation-dist-preflight --absent passed: 2 failed | 2 passed with the same two base messages. Restore: blob == HEAD ecce0fb16d93c2f83a661f692985207accc76127, git diff HEAD empty, rebuilt, dist-preflight marker present in 2 built files. metadata-protocol test: 381 files passed, 9 skipped; 23940 tests passed, 45 skipped. runtime vitest --project local src/domains/mcp-authoring: 3 files, 86 tests passed. NOT MEASURED: full @objectstack/runtime local suite (timeout 590s, exit 124: did not finish inside the 10-minute foreground limit); Test Core owns it. Package runs taken on 66622c7a64; head 926ce2d055 adds only origin/main's c748e7dfd6 (two gate scripts, no package).",
      "gates": "Local: metadata-protocol typecheck exit 0; runtime typecheck (tsc + check:test-typecheck) exit 0; dispatch-gates --commands derived 76 families: 75 exit 0. check:closed-ceremony-text was exit 1 on 66622c7a64 (ENOBUFS: git ls-files over packages/content/docs/.changeset is 1048565 bytes on origin/main 444dce61f2, 11 under the 1 MiB default buffer, and this diff's two new paths pushed it over). origin/main c748e7dfd6 (#39027) fixed the script; after merging it, re-run on 926ce2d055 exit 0, and check-affected-docs exit 0. NOT-MEASURED pnpm check:dual-build-cjs-loads :: PREREQUISITE NOT MET exit 3, it reads every package dist and 41 packages outside the diff are unbuilt here. dispatch-gates --ran (exit codes recorded): 76 derived, 75 run, 1 NOT-MEASURED, 0 UNRUN, exit 0. overlap-check before each push: VERDICT clean exit 0 (origin/main and #39022). Declared narrowing: the gate union ran on 66622c7a64; on 926ce2d055 only the two families the merge touched were re-run. CI on 926ce2d055 when this report was written: Governed Surface Queue Guard success; Lint/Type Check/Check Changeset/PR-body guards in_progress; dogfood opt-in skipped. PM reads convergence.",
      "mcp_calls": "0",
      "api_writes": "2 relay writes: pr_create (POST /repos/objectstack-ai/objectstack/pulls draft + POST /issues/39048/assignees [os-support-ai]) via fleet-write dispatch request fw-20261202T051959Z-cd73ac, read-back identical 10438 bytes; this os-dev-report comment via post-stamped.mjs (POST /issues/39001/comments). git push x3 to the branch (not REST).",
      "classifier_refusals": [],
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: none · noted in PR Acceptance notes, not filed: the list_drafts branch comment 'one map collects it once per package for the judgements' is now incomplete (the strict reads take the map too). It sits outside gatedDraftVerdict, so it stayed out of the fence.",
        "carrier: none · noted, not filed: the 20 per-draft foldStoredCollection reads (two judgements x 10) read environment-wide active rows that do not change within one list_drafts call. They do not grow with P; sharing them across a pass is a performance idea with no defect class.",
        "carrier: #39027 (merged c748e7dfd6) · observed, not filed: check:closed-ceremony-text ENOBUFS at the 1 MiB git ls-files buffer, triggered here by two new paths; main already holds the fix."
      ],
      "files_changed": [
        ".changeset/39001-strict-read-closure.md",
        "packages/metadata-protocol/src/protocol-meta-item-reads.ts",
        "packages/metadata-protocol/src/protocol.ts",
        "packages/runtime/src/domains/mcp-authoring.ts",
        "packages/runtime/src/domains/mcp-authoring.test.ts",
        "packages/runtime/src/domains/mcp-authoring-39001-strict-read-closure.test.ts"
      ],
      "line_budget": "256 changed lines (+253 / -3) across 6 files, under the 3000 human-merge line; no skills/** file touched",
      "deviations": [
        "protocol-authoring-gate.ts was not edited: draftPublishJudgement already reuses the map, so draftPublishVerdict needed no change.",
        "The packageClosures key is declared on the two ends (public getMetaItem in protocol.ts; getMetaItem/readMetaItem in protocol-meta-item-reads.ts). The intermediate face types (readMetaItemFace in protocol-meta-item-face.ts and the private readMetaItemFace/readMetaItem signatures in protocol.ts) forward the request object unchanged without declaring the key, so the edit stays inside the fence. The per-draft query pin fails if a later refactor drops it in transit.",
        "No ledger row was needed for the new test file: check:engine-double-contract exit 0.",
        "Full runtime local suite NOT MEASURED (10-minute foreground limit); targeted mcp-authoring files run instead.",
        "Worktree removed after the PR opened, per resource rule 4. The merge of origin/main after #39022 lands is owed in a later round from origin/claude/issue-39001-strict-read-closure@926ce2d055."
      ]
    }
  7. objectstack-fleet commented on Dec 2, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack@os-support-ai · os-support-ai · session_01WGufzeatqKfTRUzTJVa9jQ

    Close-out · 2026-12-02T06:52Z · zone osa-ai

    • PR fix(metadata-protocol): a list_drafts verdict no longer re-collects its package closure per draft #39048 merged 2026-12-02T06:52Z (merge commit 7814822). The strict draft read now takes the list_drafts door's packageClosures map, so one call collects each package's closure once. Measured per verdict (SQLite, one package): P=10 35.2 → 24.2 queries, P=50 75.0 → 24.0, P=100 126.0 → 25.0; it no longer grows with P. A single /meta draft read folds the same _diagnostics as before. pm:dispatched and the zone's assignee are removed with this comment.
    • Accepted nits, not filed: N1, the list_drafts comment at mcp-authoring.ts:981-982 still says the map serves the judgements only; N2, packageClosures rides undeclared through the face types (the per-draft query pin guards it). The 20 environment-wide foldStoredCollection reads per draft are constant in P, a possible later optimisation with no defect.
  8. removed
    pm:dispatched
    on Dec 2, 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

    area:aidomain:datapriority:p2repo:cloud

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions