Repository navigation
Commit 0c45d66
feat(plugin-audit,spec,client): one read returns the comment threads on the records a list filter selects, as the caller (#39135)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBRcN813GZAexn3xsDCyu5rG)_
Fixes #39084
Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: none — the added keys are the request and response shape of
one built-in REST read on the api shard, not anything a metadata author
writes in an object, view or app, so no authoring skill teaches them;
the read is documented in content/docs/api/data-api.mdx and the
generated reference page, and the list-page UI card (U3) is its consumer
## 维护者速读
-
用户看到什么:列表页评论栏可以一次请求拿到「当前视图里这些记录上的评论串」,按看的人的权限过滤,最新在前,带记录名、回复数和最近三位回复人,可翻页。
- 为什么:专题 #39077 的 S3,列表页评论栏(U3)要用;视图再大也一次算对,不用一条条记录去读。
- 出错会怎样:只按调用者权限读,读不到的记录不出现;筛选不合法或没权限会直接报错,不会给出残缺结果。
- 要你做什么:无。托管部署(调度器)上暂不提供这个读取口,已另立 #39134。
## What changes
- **`@objectstack/spec`** —
`packages/spec/src/api/comment-threads.zod.ts`: strict
`CommentThreadsQueryRequestSchema` (`object`, `filter` in the `GET
/data/{object}` syntax, `showResolved`, `onlyMine`, `limit`
1..`COMMENT_THREADS_MAX_LIMIT`, opaque keyset `cursor`) and
`CommentThreadsQueryResponseSchema` (`threads[]` of `{ comment, record:
{ id, name }, replyCount, repliers[≤3] }`, `nextCursor`), limits as
exported constants. Generated artifacts regenerated (see Verification).
- **`@objectstack/plugin-audit`** — new `comment-threads-query.ts`
serves `POST /api/v1/comments/threads/query` from
`registerCommentDoorsRoutes`, steps 1–6 of the epic's §5, **every read
as the caller**:
1. caller resolution; anonymous 401; held sign-in 403;
2. no query parameter, strict body, a cursor this read issued, a filter
`parseFilterAST` takes — else `400 VALIDATION_ERROR` before the engine
is asked anything;
3. object registered, served by the data door for `get`, not
`sys_comment`, `enable.feeds !== false` (else `403 FEEDS_DISABLED`);
4. `ObjectQL#planReadScope(sys_comment, object, { where: filter, context
})`, **planned per request and never cached** (two-user pin), its
refusals are the answer (`PERMISSION_DENIED`, `INVALID_FILTER` on
MongoDB/OData);
5. ONE `find` on `sys_comment`: object, scope, top-level, unresolved
unless `showResolved`, `participants $contains caller` when `onlyMine`,
keyset after the cursor, newest first by `(created_at, id)`, `limit +
1`; the comment read gate ANDs its condition as on any read;
6. the page's replies (author columns and parent pointer only,
keyset-paged, as the caller) for reply count at any depth and the latest
three distinct repliers, and one read of the object for the page's
record display names (ADR-0079).
- Ledger row `POST /api/v1/comments/threads/query` → `sdk`,
`comments.queryThreads`; conformance test updated.
- **`@objectstack/client`** — `client.comments.queryThreads`; the
URL-conformance sweep now reads the comment route ledger (so
`turbo.json` and `scripts/cross-package-test-inputs.mjs` declare it as a
client test input).
- **`@objectstack/objectql`** — exports the `PlanReadScopeOptions` and
`ReadScopeComparand` types (N3 of 7341533575).
- Docs: a section in `content/docs/api/data-api.mdx`;
`packages/spec/llms.txt` counts; a changeset: `minor` on
`@objectstack/spec` (`Metadata-protocol: added`, because the new schemas
enter the `api` authorable-surface shard, the precedent of #38999),
`patch` on objectql, plugin-audit and client. The claim said `none`; the
Check Changeset gate on cb3695e read the shard as added keys, and
commit fb20c06 corrects the declaration.
## Why
Epic #39077 S3 (rulings 7338398195: a dedicated read; "current view" =
saved filter + temporary filters, the search box not counted). The list
page's comment panel (U3) needs the threads of the view's records in one
request, correct on a view of any size, with the same refusals a list
read gives and no new read authority.
## Acceptance notes
Where each card bullet is pinned (HTTP =
`packages/qa/dogfood/test/comment-threads-query.dogfood.test.ts`, booted
stack with the real SecurityPlugin; engine =
`comment-threads-query.integration.test.ts` and the dogfood file's
engine cells):
- 3 of 5 records selected → only their top-level open threads, newest
first, record id + name, reply count, ≤3 latest repliers: HTTP test 1,
engine.
- A member who cannot read one of the 3 → its threads omitted; no read
on the object → that read's own refusal: HTTP test 2, engine cells on
SQLite and PostgreSQL.
- `showResolved` / `onlyMine`: HTTP tests 3 and 4, engine.
- `limit` + `cursor` walk every thread once while a comment is posted
between pages: HTTP test 5, plus an engine test with a `created_at` tie.
- Unknown key, any query parameter, `limit` out of range → `400
VALIDATION_ERROR` and the engine never called (spy): HTTP test 6. Filter
on an unreadable field → `PERMISSION_DENIED`: HTTP test 7. Feeds off →
403; anonymous → 401: HTTP test 8.
- A view larger than the id cap answered in full with ONE threads
statement carrying the planned read: HTTP test 9 on SQLite (1,005
records, driver statement log), and engine cells on SQLite and
PostgreSQL.
- No new error code: `ERROR_CODE_LEDGER` diff is empty.
- **Two-user per-request pin** (7343013270): unit test "two users
through one door" and the engine cells (`planReadScope` call order BOB,
ALICE, BOB, ALICE). Ablation: caching the planned scope in a
module-level `??=` turns the unit test red.
Deviations and notes:
- **Self-hosted only.** The read is mounted where the comment registrar
mounts (`http.server`); the hosted dispatcher's `/comments` domain does
not claim it, and the boot log says so. Seat ruling on hand-back;
follow-up **#39134** serves it on the hosted kernel. "Advertised
wherever the comment doors are advertised and nowhere it is not mounted"
holds: `packages/runtime/src/domains/comments.ts` is untouched.
- **HTTP fixture:** the dogfood file uses its own inline stack rather
than the showcase, because the acceptance needs a row-scoped persona, a
persona with an unreadable field and one with no read on the object,
which the showcase's fallback permission set makes impossible.
- **Reply counts** come from the page's replies read as the caller
(keyset-paged, author columns only), not a grouped count by `parent_id`:
a count "at any depth" needs each reply's thread root, which a grouped
count over `parent_id` does not give for nested replies.
- **Not measured:** whether `sys_comment` wants an index leading with
`(object_name, created_at)` for this read — no plan was read on
PostgreSQL or SQLite, and `sys-comment.object.ts` is outside this card's
claim.
- **PostgreSQL** (N5 of 7341533575): the PG cells run where
`OS_TEST_POSTGRES_URL` is set; no CI job provisions it, so they are
**not measured in CI**. Local run on PostgreSQL 16.15
(`/usr/lib/postgresql/16/bin`, throwaway server on 127.0.0.1:54391) at
head c4d4266: `OS_TEST_POSTGRES_URL=… pnpm --filter
@objectstack/dogfood exec vitest run
test/comment-threads-query.dogfood.test.ts` → 17 passed (17), including
4 live-postgres tests.
- Claim 7343360143, amendment 7346184382 (llms.txt, the two test-input
declarations, generator outputs).
## Verification
- `@objectstack/plugin-audit` 118 files / 1944 tests passed;
`@objectstack/client` 60 / 841; `@objectstack/objectql` 646 / 14685;
`@objectstack/spec` 922 / 29119 (1 todo); the dogfood file 17 / 17 with
PG. New suites: `comment-threads-query.test.ts` (19),
`comment-threads-query.integration.test.ts` (7),
`comment-threads.test.ts` (9), ledger conformance (+1), client URL
conformance (+2).
- **L2 rounds** (records on this PR): r1 FAIL on fb20c06 (M1: a filter
array the list read cannot lower was dropped, answering every readable
record; S1: a decodable cursor with no instant reached the engine). r2
PASS on 7b0b230 with S1 open for placeholders. r3 PASS on 809a6e1, no
must-fix and no should-fix. The fixes: `lowerThreadsFilter` refuses such
a filter `INVALID_FILTER` / 400 as `GET /data/{object}` does, and the
cursor decoder accepts only what the encoder writes. After them,
`comment-threads-query.test.ts` has 21 tests and the integration file 7,
28 of 28 passing. Ablation against the previous source fails the new
cases. Typecheck and eslint are clean. Nits N1 (a stored thread root, so
reply counts need no in-app walk) and N2 (the microsecond keyset edge on
PostgreSQL) are filed as follow-up **#39142** (Part of #39077, p2,
area:data), per seat amendment 7347081374. r4 PASS on 750a1ea accepts
the one ui file below.
- **`ui/scripts/check-spec-symbol-derivation.mjs`** (seat amendment
7347081374): the new spec export `CommentThread` collides with
`@object-ui/collaboration`'s published React component `CommentThread`.
The two are different layers, so the fix is one ALLOW entry with its
reason, as `EmptyState` has; the seat ruled ALLOW over a rename. The
guard passes, and its 8 test files pass 195 of 195. A UI consumer (U3)
imports the spec type under an alias.
- Typecheck passes for spec, plugin-audit, client, objectql and dogfood;
ESLint `--max-warnings=0` over the changed sources passes.
- `node scripts/pm/dispatch-gates.mjs --ran`: 127 of 127 derived
families run. `check:llms-txt` and `check:cross-package-test-inputs`
were red until the amendment commit and pass on this head.
<details><summary>Generated outputs (written by the generators, never by
hand)</summary>
`packages/spec/authorable-surface/api.json`, `declaration-map/api.json`,
`api-surface/api.json`, `export-origins/api.json`,
`json-schema.manifest/api.json`,
`packages/spec/docs/references/api/comment-threads.md` (the generator's
path; the claim named `content/docs/references/api/`),
`packages/spec/docs/references/README.md`,
`packages/spec/docs/references/api/README.md`,
`content/docs/references/index.mdx`,
`docs/audits/2026-07-unknown-key-strictness-ledger.counts/api.md`.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (eslint on changed files).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the 维护者速读 block is the
allowed Chinese channel).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufzfHCzQWh6PeQnvToFz
<!-- signed: repo:objectstack@os-support-ai · os-support-ai ·
session_01WGufzfHCzQWh6PeQnvToFz -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 491ea82 commit 0c45d66
32 files changed
Lines changed: 2573 additions & 19 deletions
File tree
- .changeset
- content/docs
- api
- references
- docs/audits/2026-07-unknown-key-strictness-ledger.counts
- packages
- client/src
- objectql/src
- plugins/plugin-audit/src
- qa/dogfood/test
- spec
- api-surface
- authorable-surface
- declaration-map
- docs/references
- api
- export-origins
- json-schema.manifest
- src/api
- scripts
- ui/scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
682 | 682 | | |
683 | 683 | | |
684 | 684 | | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
685 | 763 | | |
686 | 764 | | |
687 | 765 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
| |||
481 | 486 | | |
482 | 487 | | |
483 | 488 | | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
7468 | 7470 | | |
7469 | 7471 | | |
7470 | 7472 | | |
| 7473 | + | |
| 7474 | + | |
| 7475 | + | |
| 7476 | + | |
| 7477 | + | |
| 7478 | + | |
| 7479 | + | |
| 7480 | + | |
| 7481 | + | |
| 7482 | + | |
| 7483 | + | |
| 7484 | + | |
| 7485 | + | |
| 7486 | + | |
| 7487 | + | |
| 7488 | + | |
| 7489 | + | |
| 7490 | + | |
| 7491 | + | |
| 7492 | + | |
| 7493 | + | |
| 7494 | + | |
| 7495 | + | |
| 7496 | + | |
| 7497 | + | |
| 7498 | + | |
| 7499 | + | |
7471 | 7500 | | |
7472 | 7501 | | |
7473 | 7502 | | |
| |||
9694 | 9723 | | |
9695 | 9724 | | |
9696 | 9725 | | |
| 9726 | + | |
| 9727 | + | |
9697 | 9728 | | |
9698 | 9729 | | |
9699 | 9730 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
281 | 285 | | |
282 | 286 | | |
283 | 287 | | |
| |||
0 commit comments