Skip to content

perf(plugin-audit): count comment thread replies by a stored thread root, and page threads at PostgreSQL microsecond precision - #39169

Merged
objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/project-thread-ovqx20
Dec 2, 2026
Merged

objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/project-thread-ovqx20

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Yibo Wang · project thread

Fixes #39142

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

What changes

  • sys_comment.thread_root_id (packages/plugins/plugin-audit/src/objects/sys-comment.object.ts): a read-only, platform-written text column with an index. On a reply it holds the id of the top-level comment its parent_id chain leads to inside its record's discussion, or the reply's own id when it is in no thread. It is null on a top-level comment. A null on a reply means the reply has not been stamped yet, and that set is exactly what the backfill visits. The rule is the existing < 16 hop rule the participants keeper already uses: a reply up to 15 levels below its top-level comment belongs to the thread.
  • Stamping (comment-participants.ts):
    • beforeInsert stamps a reply from its parent, with one system read of the parents by $in. The client's value is replaced.
    • The participants keeper's reconcile now also corrects every stamped root of the discussion the rule moved, in the same system write that already keeps participants (updated_at kept, and only the differing columns written). So a re-point or a delete moves the roots under it. After a write it stamps an unstamped reply only if that write wrote it (stampOnly). A reply on a discussion full of older replies therefore writes one root, not one system update, audit row and activity row per older reply (L2 r1 S1). The backfill stamps the rest.
    • beforeUpdate strips the column from non-system writers, so it is reported in droppedFields.
    • A parent-read failure at create stamps null and logs a warning. The reconcile or the backfill fixes it later.
    • threadRootByRow and COMMENT_THREAD_ROOT_COLUMN are exported.
  • Backfill (comment-participants-backfill.ts, os migrate comment-participants): the existing command now also stamps roots, and reports roots. It walks the discussions of top-level comments first, then the discussions that still hold unstamped replies. The second walk reaches a discussion whose top-level comment was deleted. It is idempotent, and a dry run comes first, as before.
  • N1, the threads read (comment-threads-query.ts, POST /api/v1/comments/threads/query): reply count and the latest three distinct repliers now come from one engine.aggregate over the page's replies, grouped by (thread_root_id, author_id) with count(id) and max(created_at). A second read fetches each candidate replier's newest reply for the display columns. Both run as the caller, so the comment read gate applies as on any read. Before, the read fetched every reply on the page's records and followed parent_id in the server. Without an aggregate on the engine the handler answers 503, as it does without planReadScope.
  • Ruling (b), unstamped replies: replies whose root is still null are counted by a bounded fallback in the same request (readUnstampedPlaced). It reads the page's unstamped replies paged by id (1,000 a page), then their ancestors level by level, at most 16 rounds, as the caller. The result is placed with the same rule as the stamp. After the backfill this is one read that returns nothing. A count therefore never drops to 0 on a deployment that has not run the backfill. Pinned at engine level before, half-way through and after the backfill (see Acceptance).
  • N2, the keyset (comment-threads-query.ts): PostgreSQL stores microseconds, but every read hands back milliseconds, so two threads stored microseconds apart could be skipped at a page edge. The cursor now pages by the millisecond bucket, then by id, compared at the millisecond on both sides: created_at < c OR (c ≤ created_at < c+1ms AND id < cursorId). When a page's last millisecond may hold more threads, that bucket is read again in the database ordered by id (limit room + 1), so the page and the cursor agree. instantMs parses every spelling a driver hands back. A cursor issued before this release still decodes.
  • Docs: content/docs/api/data-api.mdx (reply count and keyset wording), content/docs/deployment/cli.mdx (the backfill now also stamps roots, the depth rule, the slow-path fallback), and content/docs/permissions/system-context.mdx (row 45a: the root stamp and the parent read as system).
  • Translations: the column's label and help in the ten locales (--write regenerated the bundles).
  • Changeset: patch on @objectstack/plugin-audit and @objectstack/cli, with both declaration lines.

Acceptance notes

  • Grouped read instead of reading every reply: the unit test "a backfilled page costs the same statements whatever its reply count" pins one threads read, one grouped read, one read of the candidates' newest replies, one unstamped probe and one record-name read for a thread with 10,000 replies, all as the caller. The aggregate's where, groupBy and aggregations are asserted exactly. A page whose last millisecond may hold more threads adds the one edge re-read (its own unit test).
  • Backfill: comment-participants.integration.test.ts adds stamping at any depth (forged values replaced), re-point, and a backfill that includes a discussion with no top-level comment.
  • Ruling (b): comment-threads-query.integration.test.ts adds an account where a depth-3 thread has count 5 with repliers [ben, ann, dee] and an orphan left out. The same answer is checked for ANN and BEN before the backfill (every root null), half-way through, and after. Ablation: disabling the fallback turns this test red. The dogfood file adds the same check on the real engine on SQLite and PostgreSQL (roots nulled through raw SQL, then the backfill).
  • N2: the dogfood file adds "two threads stored one microsecond apart, across a page edge: both answered, once each". Reverse check: with comment-threads-query.ts restored from origin/main (and the package rebuilt), the live-postgres cell fails (expected [ 'MeNl4wlWzztPS4pN' ] to deeply equal [ 'MeNl4wlWzztPS4pN', …(1) ], so one thread is skipped). The SQLite cell passes on both. On this head both pass. Unit tests cover the edge re-read and every instantMs spelling.

Deviations and notes:

Verification

  • @objectstack/plugin-audit: 118 files / 1964 tests passed; typecheck (including check:test-typecheck) passes. Changed suites: comment-threads-query.test.ts 26, comment-participants.test.ts 23, comment-threads-query.integration.test.ts 8, comment-participants.integration.test.ts 12.
  • @objectstack/cli: typecheck passes; the migrate tests and the two pins that name the command (migrate-confirmation-exit.pin, json-stdout-purity.e2e): 90 files / 764 passed, 8 skipped.
  • The dogfood file: 21 / 21 with PostgreSQL 16 as above, on 7e8c04a and again on 2b906d9.
  • L2 (records on this PR): r1 PASS on 7e8c04a (comment 7356253578), with S1 (a write stamped a discussion's whole unstamped backlog in the user's request) and S2 (docs said the next comment stamps a record's replies). Both are fixed in 2b906d9; a new unit test pins the bound, and it goes red with the bound removed. r2 delta PASS on 2b906d9 (comment 7356480731): S1 and S2 closed, no must-fix, no should-fix. Accepted nits: N2 (pre-backfill ancestor read unchunked), N3 (degenerate edges not reachable by platform writes), N5 (card body's stale Clause-② line, the seat's), N6 (three internal comments still describe r1 stamping).
  • ESLint --max-warnings=0 over the changed sources passes. check:system-context-census, check-tenant-audit-census and check-i18n-bundles pass.
  • node scripts/pm/dispatch-gates.mjs --ran on 2b906d9: 111 of 111 derived families run, every one exit 0, none not measured. (On 7e8c04a four first answered exit 3 for missing prerequisites and passed after the fetch or build each named.)

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (packages/spec untouched.)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes (eslint on changed files).
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: n/a.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

Generated by Claude Code

@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/cli, @objectstack/plugin-audit, touching 52 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/plugins/plugin-audit/src/index.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

46 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json b98173cea88f0cdc9fbe1a80a6bf1214396c1472.

⛔ 13 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/plugins/plugin-audit/src/index.ts) — pages documenting those are invisible to this run
  • 2 anchor(s) matched too much of the corpus to be a work list: created_at (literal, 49 pages), organization_id (literal, 43 pages)
  • 5 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 71 of 255 client-bound route-ledger rows — the other 184 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 184: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 60 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 49 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json b98173cea88f0cdc9fbe1a80a6bf1214396c1472 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 07247db0643632cfe6c1e221c2dcd4148d89a3f8 — the merge of head 2b906d9bf66c2ebee3c9aa3d0166c6f9edf57e1d into base b98173cea88f0cdc9fbe1a80a6bf1214396c1472, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 07247db0643632cfe6c1e221c2dcd4148d89a3f8 && git checkout 07247db0643632cfe6c1e221c2dcd4148d89a3f8
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin b98173cea88f0cdc9fbe1a80a6bf1214396c1472 2b906d9bf66c2ebee3c9aa3d0166c6f9edf57e1d && git checkout -B drift-repro b98173cea88f0cdc9fbe1a80a6bf1214396c1472 && git merge --no-ff 2b906d9bf66c2ebee3c9aa3d0166c6f9edf57e1d

node scripts/docs-audit/affected-docs.mjs --json b98173cea88f0cdc9fbe1a80a6bf1214396c1472

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs b98173cea88f0cdc9fbe1a80a6bf1214396c1472 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufziM2GUsShZcjp6TiyD
Contract-review-claim: session_01WGufziM2GUsShZcjp6TiyD · head 7e8c04a · 2026-12-02T19:18Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

Contract review brief — PR #39169 @ 7e8c04ac401406f000655b8ced76c35f32991635 (card #39142)

You review at TIER_DEFAULT: the face this PR's committed tree decides is the declaration face (no published schema under packages/spec/src/**, no governed path, Clause-②: yes (widening) on the PR body and the changeset). The seat asked that this review run on the CONTRACT_REVIEW_TIER model, in an isolated sub-agent, and that it carry a ④ design judgment as S3 (#39135) did; the record's Served-tier: still names the face's tier. Render ONE ## Contract review record on this head — its shape is
node scripts/pm/record-recognisers.mjs --template --face declaration, plus a ### ④ Design judgment section after ③ — with a PASS or FAIL verdict, written to the scratch file below; the card thread posts it as ONE comment on the PR.

Inputs — these and nothing else:
· card #39142: its body and EVERY comment (rulings and earlier records included), and the parent epic #39077 where the card cites it
· PR #39169: its body, its file list, and the net diff against main at 7e8c04ac401406f000655b8ced76c35f32991635
· the check-runs on 7e8c04ac401406f000655b8ced76c35f32991635: their conclusions ARE the gate verdicts
· PR #39135's L2 records, where N1 and N2 (the origin of this card) were graded
⛔ Not the dispatch order, ⛔ not the dispatching seat's own conclusions — this brief is adversarial by design.

⛔ READ-ONLY. No worktree, no checkout, no build, no test run, no gate re-run, no ablation: the check-runs
on the head already answered every derived gate family, and a local run costs more than it returns.
If ONE probe is unavoidable, the record's Local-runs: line says probe — REASON; otherwise none.
Scratch space is /tmp/claude-0/-home-claude/a260ff68-50f9-5238-a25f-356897ca855c/scratchpad/pr-39169/ alone; nothing there you did not write this round is read.

Judge, in the record's own sections:
① Derived judgments — every accept-set and public-surface change the diff implies, each named right or wrong.
② Semver level — the changeset (or skip-changeset) matches what the diff publishes, and the Clause-②: line.
③ Boundary flags — every dev flag and every open_questions entry answered, or escalated.
On every face, SQL push-down: a new id materialisation or in-app join where SQL could push down is a
finding unless a reason is given (AGENTS.md, Prime Directive 5: SQL first).
④ Design judgment (the seat's addition) — for comment-participants.ts, comment-participants-backfill.ts,
comment-threads-query.ts, sys-comment.object.ts and the CLI command: does the code agree with the card,
the seat's rulings (a) and (b) on the card, and the changeset and docs sentence by sentence? Try to break it:
the stamp under concurrent creates and re-points, the fallback's bound, the keyset edge on PostgreSQL and SQLite,
a forged thread_root_id, the read running as the caller. Grade each finding must-fix, should-fix or nit;
spell a graded finding S1 (should-fix) — … and a clean round No must-fix, no should-fix.
⛔ Judge the tree, never the PR body's account of it.
Sign Implemented-by: with the dev's branch and Reviewed-by: with the adopting session id — the value is the FIRST
thing after each colon.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 7e8c04ac401406f000655b8ced76c35f32991635
Local-runs: none

Inputs read: card #39142 (body, the first-touch comment, the claim with seat rulings (a) and (b), and the dev report); epic #39077 where the card cites it; PR #39169 (body, its 26 files, and the net diff against main); the three ## Contract review records on PR #39135 where N1 and N2 were graded (heads fb20c06f, 7b0b2300, 809a6e17); the check-runs on this head. Code was read in the local tree at this head with read-only tools: comment-threads-query.ts, comment-participants.ts, comment-participants-backfill.ts, sys-comment.object.ts, the CLI command, the comment read gate (comment-access-hooks.ts) and the engine's aggregate entry. Nothing was built, run or changed. The dispatch order and the seat's own conclusions were not read.

Check-runs at read time: 58 runs. Success: TypeScript Type Check, Lint & Repo Gates, Lint · ESLint, every Lint and Type Check family, Build Core, Build Docs, Check Changeset, Check PR Size, PR-body guards, Governed Surface Queue Guard, Spec property liveness, Check Documentation Links, Dogfood Regression Gate, Test UI, Live E2E UI, and Test Core shards 4, 7, 9, 10, 11 and 12 of 12. Still in progress: Test Core shards 1, 2, 3, 5, 6 and 8. Skipped: the UI jobs, the opt-in batteries, and Temporal Conformance (live PG + MySQL). No run had failed. This record does not stand in for the six shards still running: their conclusions are the test verdict, and a red shard overrides the PASS below. No job sets OS_TEST_POSTGRES_URL, so no check-run measured a PostgreSQL cell.

① Derived judgments

  • sys_comment.thread_root_id, a new served column (text, readonly, indexed): right. It is a widening. A client cannot land a value: beforeInsert assigns over what was sent for every caller, system included, and beforeUpdate deletes the key for every non-system writer. The keeper's own system updates name only participants, thread_root_id and updated_at, so they do not re-enter the reconcile.
  • The threads read's accept-set is unchanged (same strict body, same refusals). One new refusal path: 503 SERVICE_UNAVAILABLE when the engine serves no aggregate. Right; ObjectQL serves one, and the message names the cause.
  • The answer's shape is unchanged. One value changes: a reply exactly 16 levels deep was counted (the old loop ran hop from 0 to 16 inclusive) and is not now (0 to 15). Right under ruling (a), and stated in the changeset and data-api.mdx.
  • The cursor's wire shape is unchanged ([createdAt, id]), and an old cursor decodes and is normalised to its millisecond. Right.
  • Public exports of @objectstack/plugin-audit: COMMENT_THREAD_ROOT_COLUMN and threadRootByRow added; CommentParticipantsBackfillReport and ThreadParticipantsReconciliation gain a required roots number; the exported type CommentThreadsEngine gains a required aggregate member. The first two are widenings. The third narrows a type for an in-process caller of queryCommentThreads that passes its own engine object; see N4.
  • CLI os migrate comment-participants: no flag changed; the human lines now say rows and name the roots among them, and the report gains roots. Right.

② Semver level

patch on @objectstack/plugin-audit and @objectstack/cli, with Clause-②: yes (widening) and Metadata-protocol: none on both the PR body and the changeset: right. Nothing a metadata author can write changes, so the kind is none and AGENTS.md gives patch; the sibling changeset for #39081 took the same level for the same kind of column. The CLI package is moved by the command's wording and report, so it belongs in the changeset. The card body still reads Clause-②: no; the claim comment and the PR supersede it (N5).

③ Boundary flags

  • Dev flags and open_questions: the report's open_questions is empty. Its one out-of-scope note, that the PostgreSQL cells are not measured in CI, is confirmed above. The N2 acceptance (a live-PG test with two threads 1 microsecond apart across a page edge) is in the tree (comment-threads-query.dogfood.test.ts), but its only run is the dev's local one. I read the keyset conditions against PostgreSQL semantics and found them sound (see ④), but no gate has measured them. This goes to the seat as a note, not a finding against the diff.
  • Ruling (a), the 16-hop rule: followed. The stamp rule, the fallback walk and the participants rule share the same loop bound, and the docs say it.
  • Ruling (b), no count drops before the backfill: followed. The fallback counts every reply whose root is null, the integration test pins the page before, half-way through and after the backfill for two users, and the dogfood file repeats it on the real engine.
  • SQL push-down (Prime Directive 5). The fast path pushes down: one engine.aggregate grouped by (thread_root_id, author_id) with count and max, one read of the candidate repliers' newest replies, and id lists that are bounded by the page (at most the page's records and threads). No new unbounded id materialisation on a backfilled table. The fallback does materialise every unstamped reply on the page's records and walks them in the application, with id $in lists of the missing ancestors. A reason is given (those rows carry no root yet, ruling (b) requires them counted, and the changeset and docs say the read grows with them until the backfill), and it holds. Not graded above a nit; see N2.
  • The keeper's reconcile now writes one row per reply, where before it wrote one row per thread whose list differed. That is a new write fan-out on a request path, with no reason or bound given. See S1.

④ Design judgment

sys-comment.object.ts. The column, its header section and the index agree with the card and with the code that writes it. The header says a null on a reply means "not stamped yet" and that the next write to the discussion reconciles it; the second half is wider than the code (S2).

comment-participants.ts.

  • Forged root: cannot land (see ①). The create stamp also refuses a parent on another discussion (thread_id compared), so a reply on record B cannot be stamped into a thread on record A and inflate its count. The integration test pins that case as an orphan carrying its own id.
  • Concurrent creates and re-points: I walked both orders of "reply under P while P is re-pointed". In each, the reconcile that reads last sees both committed writes and writes the rule's answer, because every reply insert and every parent_id or thread_id update reconciles after its own write. A stale write from a slower reconcile is possible, as the header already says for lists, and the re-check pass covers the common case. A root left stale is repaired by the next reconcile of that discussion or by --apply, whose first walk visits every discussion that has a top-level comment.
  • A reply 16 deep under a stamped parent is stamped with the parent's root at create and corrected to its own id by the after-insert reconcile. The docstring says so. It is counted for that window only.
  • S1 (should-fix) — the reconcile's write fan-out is unbounded on a user's request. reconcileCommentThreadParticipants now rewrites every reply whose root differs, one single-id update at a time, each preceded by a read of updated_at, and the afterInsert hook awaits it. On an upgraded deployment that has not run the backfill, the first reply posted on a discussion with N old replies therefore performs N updates and N reads inside that user's request, and by the keeper's own header each system update of sys_comment is also recorded by the audit writer (a ledger row and an activity row; read from the header, not measured). The changeset and cli.mdx present this lazy stamping as a convenience and give no cost. Before this PR the same reconcile wrote at most the top-level comments whose list differed. Either bound the roots written per reconcile on the request path (leave the rest to the fallback and the backfill), or state the cost, including the audit rows the backfill itself writes per reply, in the changeset and cli.mdx. Two replies arriving together on such a discussion both do the full pass.

comment-participants-backfill.ts. The second walk (replies still carrying null) reaches a discussion with no top-level comment, and it is keyed by id, so rows leaving the match set as they are stamped do not disturb the paging. A read failure in the first walk stops the run and is counted. A dry run pages over every unstamped reply to find unseen discussions; that is reads only. It agrees with the docs and the CLI text. No finding.

comment-threads-query.ts.

  • Read as the caller: every find and the aggregate carry the request's context; the comment read gate lists aggregate among its read operations (READ_OPS), so the grouped count is gated as a list read is. The stamp is derived by the system over the whole discussion, while the old walk ran as the caller; comment visibility is decided per record, so the two agree for any reply the caller can read.
  • Counts: stamped groups and unstamped rows are disjoint ($in thread ids against $null), so nothing is counted twice in a half-backfilled table. The candidate rule (authors at or above the third-newest author's millisecond, ties kept) cannot lose a replier that the merged answer needs, because every unstamped reply is itself a candidate row.
  • Keyset on PostgreSQL: created_at below c, or from c to just under c plus 1 ms with a smaller id. Both bounds are millisecond text compared against microsecond storage, so the bucket is exact. The first read orders by microsecond; every millisecond above the edge is whole in it, and the edge millisecond is read again by id with the same threadWhere (cursor included), so the page's last id and the cursor agree. I could not construct a skip or a repeat with rows 1 microsecond apart, with three or more rows in one millisecond, or with a cursor already inside the edge millisecond. On SQLite the stored text is already at the millisecond and the same conditions reduce to the old ones.
  • Statement count on a backfilled page: threads, edge re-read (on every page that has a successor, not only when the millisecond is shared), grouped read, newest repliers, unstamped probe, names. That is six, constant in the reply count, which meets N1's acceptance. The claim's premise said at most five; the PR body says five plus the edge read. See N1.
  • S2 (should-fix) — three sentences promise more than the keeper does. The changeset says "the next comment written on a record also stamps that record's replies", cli.mdx says "and so does the next comment written on the same record", and the object header says "the next write to their record's discussion reconciles it". In the code a person's new top-level comment does not reconcile (afterInsert returns unless the row is a reply or the writer is system or preserveAudit), and neither does an edit of a comment's body (afterUpdate runs only when mentions, parent_id or thread_id is named). Only a new reply, such an update, or a delete does. Say "the next reply" (or list the three), in all three places. No count is wrong because of it, since the fallback still counts; the published text is.
  • N1 (nit) — data-api.mdx says both the count and the repliers "are taken with one grouped read"; the repliers need the second read, as the changeset says correctly. The edge re-read also runs whenever another page follows, which the docs' "may hold more threads" wording covers only loosely.
  • N2 (nit) — the fallback's ancestor read sends id $in lists as large as the number of distinct missing parents on the page's records, with no chunking in this file, and does not seed the walk with the page's own threads, which it already holds, so the first round always re-reads them. Transient (pre-backfill only) and reasoned in ③.
  • N3 (nit) — degenerate edges, none reachable by platform writes: the newest-repliers read is capped at ten rows per candidate in total, so many replies by one author in one thread in one millisecond can push another candidate out of the answer; if every row of the edge millisecond is deleted between the two reads and nothing sits above it, the page comes back empty with a null cursor although older threads exist; a row whose created_at cannot be parsed is dropped from the page silently. On PostgreSQL, repliers that tie inside one millisecond are now ordered by id where the old read ordered them by microsecond; the PR body says so, the changeset does not.
  • N4 (nit) — CommentThreadsEngine is an exported type and gains a required aggregate; a typed in-process caller with its own engine object stops compiling. The changeset does not mention it.
  • N5 (nit) — the card body still reads Clause-②: no; the claim and the PR say yes (widening). For the seat to correct on the card.

The CLI command (packages/cli/src/commands/migrate/comment-participants.ts): wording and report only; it agrees with the backfill and with cli.mdx, apart from the sentence in S2. No finding.

No must-fix. Two should-fix (S1, S2) and five nits.

Implemented-by: claude/project-thread-ovqx20
Reviewed-by: session_01WGufziM2GUsShZcjp6TiyD

VERDICT: PASS

…l stamps the backlog

The keeper's reconcile after a user's write corrected every reply of the
discussion to the root rule, so the first reply on a discussion with many
replies written before the column existed turned into one system update
(with its audit and activity rows) per old reply, inside the user's request.
It now corrects stamped roots and stamps only the rows the write wrote; the
backfill stamps the rest, and the threads read counts unstamped replies by
their chain until it has. Docs and the changeset say so, and no longer claim
that the next comment stamps a record's replies.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufziM2GUsShZcjp6TiyD
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@os-support-ai · os-support-ai · session_01WGufziM2GUsShZcjp6TiyD
Contract-review-claim: session_01WGufziM2GUsShZcjp6TiyD · head 2b906d9 · 2026-12-02T19:34Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 2b906d9bf66c2ebee3c9aa3d0166c6f9edf57e1d
Local-runs: none

Inputs read: this is the round-2 delta on the round-1 record at head 7e8c04ac (comment 7356253578). Read: the diff from 7e8c04ac to this head (one commit, 6 files, 85 lines added and 19 removed: the changeset, data-api.mdx, cli.mdx, comment-participants.ts, its unit test and sys-comment.object.ts), the surrounding code in the local tree at this head with read-only tools, and the check-runs on this head. The round-1 inputs stand for everything the commit does not touch. Nothing was built, run or changed.

Check-runs at read time: the run on this head had just started. Success: filter, Auto Label, Lint · scoped · tooling self-tests, Governed Surface Queue Guard, Check Documentation Links, PR-body guards, Check PR Size, Spec property liveness. In progress: Build Core, Build Docs, Plan Test Core shards (no Test Core shard had been created yet), every other Lint and Type Check family, Check Changeset, Dogfood Regression Gate, Test UI, Live E2E UI. Skipped: the UI jobs, the opt-in batteries, Temporal Conformance (live PG + MySQL). No run had failed. This record rests on the code read; the runs still open are the gate verdicts, and a red one overrides the PASS below. No job sets OS_TEST_POSTGRES_URL, as in round 1.

① Derived judgments

  • reconcileCommentThreadParticipants gains an optional stampOnly set of ids. It is an exported function, and the option is additive: a caller that passes nothing gets the round-1 behaviour (every unstamped reply stamped), which is what the backfill does. Right.
  • No other accept-set or public-surface change. The column, the read's body and answer, the cursor and the CLI are as judged in round 1.

② Semver level

Unchanged and right: patch on @objectstack/plugin-audit and @objectstack/cli, Clause-②: yes (widening), Metadata-protocol: none. The changeset now also states the required aggregate on CommentThreadsEngine, the 503 without one, and the id order of repliers tied in one millisecond.

③ Boundary flags

  • Ruling (b) still holds. The fix leaves more replies unstamped for longer (until the backfill), and every such reply is still counted: the threads read's fallback selects every reply on the page's records whose root is null and places it by following parent_id, whatever its neighbours carry. The keeper never writes null onto a reply, so "unstamped" and "counted by the fallback" remain the same set.
  • Ruling (a) is untouched.
  • SQL push-down: no change to any read. The write fan-out raised in round 1 is now bounded (see ④).
  • The PostgreSQL note from round 1 stands: no gate measures those cells.

④ Design judgment

S1: closed. A reconcile after a write now stamps an unstamped reply only when its id is among the rows that write wrote (writtenIds: the result's id, the previous row's id, the update target), and still corrects any stamped root that differs. A reply on a discussion with N old unstamped replies writes one root, not N. The re-check loop is not kept spinning by the backlog, because skipped rows are not counted in changed. The backfill passes no set and stamps everything. The new unit test pins all three (50 unstamped replies untouched, a wrong stamped root corrected, the new reply stamped, then 50 stamped by the backfill).

S2: closed. The changeset, cli.mdx and the sys-comment.object.ts header now say a later write stamps only the rows it wrote and the backfill stamps the rest, which is what the code does. The keeper's own header says the same.

N1: closed (data-api.mdx names the second read). N4: closed (in the changeset). N3: the tie order is now in the changeset and data-api.mdx; the three degenerate edges are unchanged and stay a nit. N2 and N5: unchanged, still nits.

Tried against the fix:

  • Re-point of a stamped reply with a mixed subtree: its stamped descendants are corrected (their stored root is not null), its unstamped ones stay null and the fallback walks them to the new thread. The count is right either way.
  • A top-level comment turned into a reply by an update of parent_id: its own root goes from null to a thread id, and it is in the written set through the update target or the previous row, so it is stamped. If neither is present (an update by condition), it stays null and is counted by the fallback. Its stamped descendants carry the old id and are corrected.
  • A reply turned into a top-level comment: its stored root is not null, so it is corrected to null on any reconcile.
  • Delete: the stamped children of the deleted comment are corrected to their own ids; unstamped children stay null, and the fallback finds no parent and counts them nowhere. Same answer.
  • Create under an unstamped parent: the create stamps null, and the after-insert reconcile stamps the new reply because its id is the result's.
  • An import that stores a thread's first comment after its replies: each reply was stamped with its own id by its own reconcile (parent not found), which is not null, so the later reconcile corrects it to the thread.
  • I found no way for a reply to hold null and go uncounted, and no way for the fix to leave a stamped root wrong where round 1 corrected it.

N6 (nit) — three internal comments still describe the round-1 behaviour: the comment-threads-query.ts header ("or until the next write to its record's discussion reconciles it"), the docstring of stampThreadRoots ("the after-insert reconcile ... brings it to the rule" is still true for the new reply, but reads as general), and the docstring of reconcileCommentThreadParticipants ("Bring every stored list and thread root", qualified only by the option's own comment). None is published text.

No must-fix, no should-fix. Nits open: N2, N3, N5, N6.

Implemented-by: claude/project-thread-ovqx20
Reviewed-by: session_01WGufziM2GUsShZcjp6TiyD

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

2026-12-02T20:08Z · Final green head for L1: 2b906d9bf66c2ebee3c9aa3d0166c6f9edf57e1d. Check-runs on it: 42 success, 17 skipped, 0 failure; mergeable, clean. +1404 / −245 across 26 files (under the 3,000 line). Claim 7353765626. Clause-②: yes (widening), Metadata-protocol: none. L2: r1 PASS on 7e8c04a (7356253578) with S1 and S2, fixed in 2b906d9; r2 delta PASS on this head (7356480731), S1 and S2 closed, no must-fix, no should-fix. dispatch-gates --ran on this head: 111 of 111, all exit 0. Dogfood 21 / 21 with a local PostgreSQL 16 (not measured in CI). os-dev report: #39142 comment 7355898722. L1 requested from osa-L1-a.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

L1 review: ACCEPT, on head 2b906d9

Verdict: ACCEPT. Fixes #39142. Not governed: 0 of 26 paths hit the register. Size is +1404/−245, under the per-PR line. At this head the checks read 44 success, 19 expected skip, 0 failed and 0 pending; the PR is mergeable and clean. l1-face is CLEAN: 13 items, none flagged. The changeset covers both published packages touched (@objectstack/plugin-audit and @objectstack/cli). The seat lands the PR.

The L2 owed, and on record

The paths decide no face, and the changeset's Clause-②: yes (widening) line, with no (narrowing) arm, gives the declaration face. That face owes a TIER_DEFAULT L2, and it is on record:

  • Round 1 PASS on 7e8c04ac (7356253578), with S1 and S2 open.
  • Round 2 delta PASS on this head (7356480731): S1 and S2 closed, no must-fix, no should-fix. Nits N2, N3, N5 and N6 stay open.

The delta covers exactly the one commit between the two heads: 2b906d9b, 6 files, +85/−19. I read that commit myself.

What was read

  • The S1 fix (comment-participants.ts).
    • A reconcile after a write now stamps an unstamped reply only if stampOnly names it. writtenIds builds that set from the result's id, the previous row's id and the update target.
    • A root that is already stamped is still corrected whatever the set says, so a re-point or a delete still moves the roots under it.
    • The backfill passes no set, so it stamps everything.
    • A skipped row is not counted in changed, so the backlog cannot keep the re-check loop spinning.
  • Ruling (b) still holds. After this fix more replies stay unstamped until the backfill. The keeper never writes null onto a reply, and the threads read's fallback counts every reply whose root is null. So no count drops. I agree with the delta's case list (re-point with a mixed subtree, top-level turned reply, reply turned top-level, delete, create under an unstamped parent, out-of-order import).
  • Ruling (a) is followed: a reply exactly 16 levels deep is no longer counted, and the changeset and data-api.mdx say so. That is the one outcome change. It was ruled before the build, and the L2 judged it.
  • Docs and changeset, read sentence by sentence against the code. The changeset, the data-api.mdx paragraphs, the cli.mdx table row and section, and system-context.mdx row 45a all match the diff:
    • a later write stamps only the rows it wrote;
    • the backfill stamps the rest;
    • the read counts unstamped replies by their chain until then;
    • repliers tied in one millisecond are ordered by id;
    • the read answers 503 without aggregate;
    • old cursors still read.
  • Fixes is right.
    • N1: after the backfill a page costs a bounded number of statements: one grouped aggregate by (thread_root_id, author_id), plus one read of the candidates' newest replies. Before the backfill, the fallback grows with the unstamped replies, which is what ruling (b) required. The changeset tells operators to run os migrate comment-participants --apply. The two-user integration test pins depth 3, the latest three distinct repliers, an orphaned reply, and a page before, half-way through and after the backfill.
    • N2: the live-PG case (two threads 1 µs apart across a page edge) is in the dogfood file. The report's reverse check is the strongest evidence available here: comment-threads-query.ts from main turns that case red on PostgreSQL while SQLite stays green, and both are green on the head.

Nits (not blocking)

  • N1. The 11 src/translations/*.objects.generated.ts files are not named in the claim's File surface. They are the generated labels for the new field on sys-comment.object.ts, which is named, and the i18n coverage gate requires them. The report lists them ("translations 10 locales") rather than as a breach. I don't read this as a breach in substance; I record it so nobody is surprised.
  • N2. The PostgreSQL cells are measured only on the dev's local PG 16 (dogfood 21/21). No CI job sets OS_TEST_POSTGRES_URL. This is the same note as the L2's, and it is not a finding against the diff.
  • N3. The claim asked for the L2 at the contract tier, and the card thread says the reviewer was served at that tier. The records' Served-tier: line reads TIER_DEFAULT, following the declaration face the recogniser reads. The line understates the tier rather than overstating it, and TIER_DEFAULT is what this face owes, so no action is needed.

Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

席位核对

ACCEPT — PR #39169 @ 2b906d9bf6 (Fixes #39142, Part of epic #39077; card thread of seat os-support-ai, claim 7353765626).

  • Reviews adopted: contract review r1 PASS 7356253578 (S1 and S2), then r2 delta PASS 7356480731 on this head, with S1 and S2 closed. L1 ACCEPT 7357473736 on this head.
  • What lands: sys_comment.thread_root_id is stamped at create and kept by the participants reconcile, and os migrate comment-participants backfills it. The threads read counts replies with one grouped aggregate plus one read of each candidate replier's newest reply. The cursor pages by millisecond bucket, then id, so two threads one microsecond apart on PostgreSQL are no longer skipped. A write stamps only the rows it wrote (S1).
  • Seat rulings held: (b) reply counts never drop to 0 before the backfill: replies with no root are counted by a bounded fallback, pinned before, half-way through and after the backfill, and the pin goes red with the fallback off. (a) A reply exactly 16 levels deep is no longer counted; this is stated in the changeset and in data-api.mdx.
  • Record corrections: this card's body still reads Clause-②: no. The claim and this PR say yes (widening) (a served column), and the PR's line governs (L2 N5). The 11 generated translation files are generator output that follows from the new column; the claim does not name them (L1 N1).
  • Not measured in CI: the live PostgreSQL cells; the local PG 16 run (21/21, 6 live) is named in the PR.

落地

reading value
check-governed-merges.mjs --pr 39169 NOT governed; 1,649 changed lines ≤ 3000
pr-state.mjs on 2b906d9b 44 success · 19 expected skip · 0 failed · 0 pending; mergeable_state clean
landing-k.mjs --pr 39169 K = 3 < 15
l1-face.mjs --pr 39169 CLEAN, 13 items read

Serial: #38924 (os-justin) shares content/docs/**; whichever lands later merges main. State change: ready for review + auto-merge, by the owning seat; on merge it closes #39142.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review December 2, 2026 20:18
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 3dc3983 Dec 2, 2026
64 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-ovqx20 branch December 2, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comments: the comment threads read counts replies without reading every reply, and its keyset holds at PostgreSQL microsecond precision

2 participants