Skip to content

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

Description

@objectstack-fleet

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

立卡门类别:③ 专题子卡的后续(#39084 / PR #39135 的 L2 记录留下 N1、N2 两条 nit,座位修订 7347081374 裁定合并立一张卡)。Source: #39084
Part of #39077 · follow-up of #39084 (S3)
定级:area:data · Feature · priority:p2 (seat ruling 7347081374) · reach: a list whose page of threads has many replies; PostgreSQL rows whose created_at was written outside the driver

维护者速读

  • 列表页评论栏的「按当前视图取评论串」读取(Comments: one read returns the threads on the records a list filter selects, as the caller #39084)算每条讨论的回复数和最近回复人时,会把这一页记录上的所有回复都读出来在程序里数。回复很多时读得多、慢。
  • 另有一个边角:分页游标按毫秒比较创建时间,PostgreSQL 存的是微秒。平台自己写的时间都是毫秒,只有绕过驱动直接写库的行,才可能在翻页边界被漏掉一条。
  • 本卡两件一起做:让回复数和最近回复人由数据库算出来,并让游标在微秒精度下也不漏不重。

Scope and acceptance

  • Layer: server (plugin-audit, maybe platform-objects for a column) · area:data · Feature · size M · p2
  • N1 — reply counts without the in-app walk. Today readReplies (packages/plugins/plugin-audit/src/comment-threads-query.ts) reads every reply on the page's records, keyset-paged at REPLY_PAGE_SIZE = 1000, and threadExtras walks parent_id to each reply's thread root. The reason is that sys_comment stores no thread root: thread_id is per record, and a reply at depth 2+ names only its parent. That is unbounded reads per page, against AGENTS.md Prime Directive 5 (SQL first).
    • Scope: give each reply a stored thread root, which the platform writes the way Comments: a thread stores who took part, so 'threads involving me' filters in one query #39081 writes participants. Backfill it. Then count replies and pick the latest 3 distinct repliers with a grouped read by that root, as the caller.
    • Acceptance: one page costs a bounded number of statements whatever the reply count, and the answer is identical to today's for the same rows. A two-user test pins the reply count at depth 3, the latest-3-distinct order and an orphaned reply.
  • N2 — keyset at microsecond precision. The cursor compares created_at as the ISO text toISOString writes (milliseconds), while PostgreSQL timestamptz holds microseconds. Platform writes are stamped at milliseconds, so only a row written by the database default or outside the driver can sit between two cursor values and be skipped at a page edge.
    • Scope: either carry full precision in the cursor, or make the comparison truncate on both sides.
    • Acceptance: a live-PG test with two threads 1 µs apart across a page boundary answers both, once each.
  • Files it needs (read against the tree when building): packages/plugins/plugin-audit/src/comment-threads-query.ts and its tests, comment-participants.ts (the keeper pattern), packages/platform-objects/**/sys-comment.object.ts, packages/qa/dogfood/test/comment-threads-query.dogfood.test.ts (PG cells need OS_TEST_POSTGRES_URL, not measured in CI).
  • Clause-②: no — the answer's shape is unchanged.
  • Metadata-protocol: none

Dedupe: thread_root sys_comment, comment reply count thread root, keyset microsecond timestamptz (open issues) → only the epic #39077 and unrelated cards.

Activity

  1. objectstack-fleet commented on Dec 2, 2026

    @objectstack-fleet
    ContributorAuthor

    triage@os-warren · os-warren · session_01JQwxbZzZ2f5mzcvJbRrRNZ

    First touch · 2026-12-02T14:06Z

    定级:area:data · Feature · p2 · 回复很多的列表页读得多且慢;绕过驱动写入的 PostgreSQL 行可能在翻页边界漏一条 · 读码(#39084 L2 的 N1、N2)

  2. added
    domain:server
    pm:queue
    on Dec 2, 2026
  3. objectstack-fleet commented on Dec 2, 2026

    @objectstack-fleet
    ContributorAuthor

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

    Claim: card thread of seat repo:objectstack@os-support-ai, epic #39077 (list-page comments), follow-up of S3 (#39135)
    Session: session_01WGufzhPdWmTd47Fi2bKYZS
    Thread session: session_01WGufziM2GUsShZcjp6TiyD
    Account: os-support-ai
    Branch: claude/project-thread-ovqx20
    Domain: domain:server
    Seat: repo:objectstack@os-support-ai
    File surface: packages/plugins/plugin-audit/src/objects/sys-comment.object.ts, comment-participants.ts, comment-participants-backfill.ts, comment-threads-query.ts, index.ts, with their tests; packages/cli/src/commands/migrate/comment-participants.ts and its test; content/docs/deployment/cli.mdx, content/docs/api/data-api.mdx, content/docs/permissions/system-context.mdx (row 45a and the census); docs/audits/2026-08-tenant-audit-write-call-sites.counts/plugins/plugin-audit.md (regenerated only, never hand-edited); packages/qa/dogfood/test/comment-threads-query.dogfood.test.ts and comment-thread-participants.dogfood.test.ts; a changeset. Stop on breach; explain in the report.
    Container & model: M, mode:card-thread (built in the thread), model: TIER_DEFAULT, effort: high; contract-tier L2 at CONTRACT_REVIEW_TIER (served column); L1 by osa-L1-a.
    Clause-②: yes (widening): a new served, readonly, platform-written column sys_comment.thread_root_id
    Metadata-protocol: none
    Responsibility: n/a — follow-up card
    Premise: the threads read in #39135 counts replies and the newest repliers by reading every reply on the page. N1: a stored thread root, kept by the participants keeper in the same reconcile write and stamped from the parent at insert, lets the read count with one grouped aggregate run as the caller, plus one bounded read for the top-3 repliers (at most 5 statements per page). Backfill rides os migrate comment-participants --apply. N2: the read door folds PG timestamps to milliseconds, so the cursor pages by (millisecond bucket, id), with one extra bounded read of the boundary bucket.
    Seat rulings on the two deviations in the proposal:

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

    @objectstack-fleet
    ContributorAuthor

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

    {
      "issue": 39142,
      "status": "done",
      "branch": "claude/project-thread-ovqx20",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/39169",
      "session": "session_01WGufziM2GUsShZcjp6TiyD",
      "premise_still_valid": true,
      "summary": "Head 7e8c04ac (6 commits on main, 26 files, +1338/-245). N1: sys_comment.thread_root_id (read-only, platform-written, indexed): reply -> top-level id under the existing < 16 hop rule, own id when in no thread, null on a top-level comment; null on a reply = unstamped. beforeInsert stamps from the parent (one system $in read); the participants keeper's reconcile keeps roots in the same system write (updated_at kept, differing columns only), so re-point and delete move them; beforeUpdate strips it for non-system writers. Backfill: os migrate comment-participants also stamps roots (report.roots), second walk over discussions with unstamped replies reaches ones whose top-level comment is gone. Threads read: one engine.aggregate grouped by (thread_root_id, author_id) count(id)/max(created_at) + one read of candidates' newest replies, as the caller; 503 without aggregate. Ruling (b): unstamped replies counted by a bounded fallback (paged by id 1,000, ancestors level by level <= 16 rounds, as the caller); after backfill one empty read. Ruling (a): a reply exactly 16 deep no longer counted, stated in changeset + data-api.mdx. N2: keyset by ms bucket then id, truncation on both sides, plus one edge-bucket re-read ordered by id in the DB; old cursors decode. Docs data-api.mdx, deployment/cli.mdx, system-context.mdx row 45a; translations 10 locales; changeset patch plugin-audit + cli, Clause-2 yes (widening), Metadata-protocol none.",
      "tests": "plugin-audit 118 files / 1963 passed; cli migrate + 2 pins 90 files / 764 passed (8 skipped); dogfood comment-threads-query 21/21 with local PG 16 (6 live-postgres). Changed suites: comment-threads-query.test.ts 26, comment-participants.test.ts 22, comment-threads-query.integration.test.ts 8, comment-participants.integration.test.ts 12. Ablation: fallback disabled -> pre-backfill integration test red. Reverse: comment-threads-query.ts from origin/main -> live-postgres microsecond page-edge test red (one thread skipped), sqlite green; both green on head.",
      "gates": "dispatch-gates --ran at 7e8c04ac: 111 derived, 111 run, 0 NOT-MEASURED, 0 UNRUN. Four first exit 3 (prerequisites) cleared and rerun exit 0: plugin-teardown self-test (fetch), skill-examples, dual-build-cjs-loads, i18n-coverage (builds). Typecheck plugin-audit + cli exit 0 (incl. check:test-typecheck); eslint --max-warnings=0 on changed sources exit 0. PR check-runs: pending at report time.",
      "mcp_calls": "0",
      "api_writes": "2 — relay pr_create, this report comment",
      "classifier_refusals": [],
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "carrier: PR · noted, not filed: PostgreSQL cells not measured in CI (no job sets OS_TEST_POSTGRES_URL), as on #39135"
      ]
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:datadomain:serverpm:dispatchedpriority:p2

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions