Skip to content

Commit ac14a74

Browse files
fix(app-shell): count the record discussion reaction read's batches against the row budget as one read (#39342)
Fixes #39313 Clause-②: no Metadata-protocol: none ## 维护者速读 - 设了单次读取行数上限的部署上,超过 100 条评论的记录,列表页评论栏和手机评论页对表情回应的判断改为与记录页一致:整串评论的表情回应合计超上限时都不显示,合计没超时都显示。 - 属于记录评论专题,替这类部署上的用户解决「同一条记录的表情回应在记录页被拒、在列表页却显示」的不一致。 - 只影响这类部署上评论超过 100 条且表情回应接近上限的记录;最坏情况是多发一次只取一行的读取,或表情回应不显示而评论照常显示,改动可直接撤回。 - 无 ## What changes On a deployment with `OS_DATA_QUERY_ROW_BUDGET`, the record page payload (`readReactions` in `packages/rest/src/record-page-routes.ts`) counts every id chunk's reaction rows against the budget, so the thread's reactions together past the budget refuse the `reactions` part. The client's direct read (`readCommentReactionRows` in `ui/packages/app-shell/src/views/useRecordDiscussion.ts`, used by the list-page comments column, the phone comments page and every comment read the payload does not serve) reads the thread in batches of `REACTION_READ_COMMENT_IDS` (100) comment ids, in parallel, each batch its own query, so the door judged each batch alone. A thread over 100 comments whose reactions together were past the budget, with no batch past it, showed its reactions there and none on the record page. Premise re-read on `main` at 6b2e596 (includes #39308 and #39309): holds as the card states. The fix keeps the batches parallel and adds the one thing the door could not see: when more than one batch answered rows, the client asks the door its own budget rule of the whole walk, with one read of the last answering batch at `$skip` = (rows read together) minus 1 and `$top` = 1. The door judges `$skip` plus `$top` against the budget before it runs anything (`planQueryReadWindow`), so it refuses exactly when the rows together are past the budget, the same rule `budgetRefusalOfWalk` applies server side. The client never learns or infers the budget number; the door's `QUERY_ROW_BUDGET_EXCEEDED` rejects the read, as a page past the budget already does, and the caller shows the comments without reactions, as the payload's refused part does. A `400` that is not the budget's leaves the rows standing (as a later page's does in `readEveryPage`); a failure or a refusal rejects. Cost: one extra one-row GET, only for a thread whose reactions span more than one 100-comment batch. No new client or server surface, and the data door's budget means the same for every other consumer. `record-page-routes.ts` is unchanged: the payload already applies the rule; its test file gains the twin table. Files edited: - `ui/packages/app-shell/src/views/useRecordDiscussion.ts` - `ui/packages/app-shell/src/views/useRecordDiscussion.test.tsx` - `packages/rest/src/record-page-routes.test.ts` - `.changeset/39313-reaction-read-budget-one-walk.md` (`@object-ui/app-shell` patch) Read first: 1. `readCommentReactionRows` in `useRecordDiscussion.ts`: the walk read and its catch (which verdicts reject, which leave rows standing). Highest risk: the `$skip` arithmetic (rows read together minus 1, `$top` 1). 2. The new `#39313` describe in `useRecordDiscussion.test.tsx`: the door double filters by `comment_id` `$in` and applies the page/budget rule per query. 3. The `[#39313]` describe in `record-page-routes.test.ts`: the same case table against the payload. ## Tests Both doors are pinned with one case table (150 comments, so two client batches; reactions on comment 1 and comment 101; budget 10): rows together past the budget with no batch past it (6 + 6), with and without a page size of 4, are declined on both; rows that fit exactly (5 + 5, and 6 + 4 paged) are shown on both; one batch past the budget (11 + 0, 0 + 11 paged) is declined on both. One more client test pins the walk read's window (`[11, 1]` for 6 + 6) and that a thread whose reactions sit in one batch sends none. <details><summary>Local runs at fb3b009</summary> - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/app-shell/src/views/useRecordDiscussion.test.tsx packages/app-shell/src/views/ObjectView.phoneCommentsPage-39086.test.tsx`: 2 files, 40 passed. - The seven `RecordDetailView.*` suites that read `sys_comment_reaction`: 7 files, 71 passed. - `pnpm --filter @objectstack/rest exec vitest run --maxWorkers=2 src/record-page-routes.test.ts`: 60 passed (the 6 new `[#39313]` cases confirmed by `-t 39313 --reporter=verbose`: 6 passed, 54 skipped). - `@object-ui/app-shell` `type-check` (src + `tsconfig.test.json`): exit 0, after building its dependency closure. `@objectstack/rest` `typecheck` (tsc + check:test-typecheck): exit 0. - Ablation (committed first, `scripts/ablation-replace.mjs`, anchor `if (answering.length > 1) {` replaced by `if (answering.length > 1 && false) {`, landed x1 to x0, blob 6a0a093 to b8619467): 3 failed, 21 passed; the two "rows together past the budget, no batch past it" cases and the walk-window test went red. Restored: blob equals HEAD, `git diff HEAD` empty. </details> ## Acceptance notes - Observation C (read, not measured): the reaction read gate's candidate pre-scan (`computeReactionVisibilityFilter` in `packages/plugins/plugin-audit/src/comment-access-hooks.ts`, `READ_SCAN_LIMIT` = 2,000) reads at most 2,000 reaction rows of the read's `where` in the caller's order, under system context, and narrows the read to `comment_id` in the comments those rows name. A comment none of whose reactions falls in those first 2,000 rows is filtered out, fail closed, with one warn line. Its own comment says a comment feed "never hits this", but one 100-comment client batch or one 500-id payload chunk with more than 2,000 reaction rows does, and the two doors hit it at different sizes. It bites only with no budget or a budget over 2,000. Not changed here (outside this card's file surface); reported to the seat. - The walk read returns at most one row, which is not used. ## Verification Two-minute check: `pnpm --dir ui exec vitest run packages/app-shell/src/views/useRecordDiscussion.test.tsx -t 'past one reaction batch'`, expect 7 passed. Gates: `node scripts/pm/dispatch-gates.mjs --ran` over the 68 derived commands at fb3b009: 66 run with exit 0, 2 NOT MEASURED (exit 3, prerequisite not met: `check-plugin-teardown-shape.mjs --self-test` needs an unshallowed clone; `check:dual-build-cjs-loads` needs every package's `dist`). `overlap-check.mjs`: clean against origin/main 170f9f8, 0 PR heads. Every other family is CI's. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c99c8a5 commit ac14a74

4 files changed

Lines changed: 214 additions & 2 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
fix(app-shell): a record discussion's reaction read counts the row budget over the whole thread, as the record page does
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On a deployment with a row budget (`OS_DATA_QUERY_ROW_BUDGET`), the record page payload refuses a discussion's reactions when the thread's reaction rows together are past the budget, while the list page's comments and the phone comments page read a thread of more than 100 comments in batches of 100 comment ids and let the budget judge each batch alone. So a thread whose reactions together were past the budget, with no batch past it, showed its reactions on those surfaces and none on the record page. Those surfaces now read the batches as one read: when more than one batch has reactions, the server is asked its own budget rule of the whole read (one extra one-row read), and rows together past the budget show the comments without reactions, as the record page does; reactions that fit are all shown, as before.

‎packages/rest/src/record-page-routes.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,55 @@ describe('[#39271] the discussion is the whole thread on a deployment with a dat
826826
expect(REACTION_READ_CHUNK_SIZE).toBeLessThan(1000);
827827
});
828828
});
829+
830+
// [#39313] The client's direct read (`readCommentReactionRows` in
831+
// `@object-ui/app-shell`) reads a thread's reactions in batches of 100
832+
// comment ids; its twin of this table is the `#39313` describe in
833+
// `useRecordDiscussion.test.tsx`. Both doors count the budget over the
834+
// thread's reaction rows together: rows together past it refuse the
835+
// reactions even when no 100-comment batch is past it alone.
836+
describe('[#39313] a thread past the client\'s 100-comment reaction batch: the budget bounds its reaction rows together', () => {
837+
const pad = (n: number) => String(n).padStart(3, '0');
838+
const THREAD = Array.from({ length: 150 }, (_, i) => ({
839+
id: `c-${pad(i + 1)}`,
840+
thread_id: 'account:a1',
841+
created_at: `2026-01-01T00:${pad(Math.floor((i + 1) / 60)).slice(1)}:${String((i + 1) % 60).padStart(2, '0')}Z`,
842+
}));
843+
const reactionsOn = (n: number, count: number) => Array.from({ length: count }, (_, i) => ({
844+
id: `r-${pad(n)}-${i}`,
845+
comment_id: `c-${pad(n)}`,
846+
emoji: '👍',
847+
user_id: `u-${i}`,
848+
created_at: `2026-01-02T00:${pad(n).slice(1)}:${String(i).padStart(2, '0')}Z`,
849+
}));
850+
851+
// [label, page size, budget, reactions on comment 1 (the client's first batch), on comment 101 (its second), answered]
852+
it.each([
853+
['rows together past the budget, no batch past it', undefined, '10', 6, 6, false],
854+
['rows together past the budget, no batch past it, paged', '4', '10', 6, 6, false],
855+
['rows that fit the budget exactly across batches', undefined, '10', 5, 5, true],
856+
['rows that fit the budget exactly across batches, paged', '4', '10', 6, 4, true],
857+
['one batch past the budget', undefined, '10', 11, 0, false],
858+
['one batch past the budget, paged', '4', '10', 0, 11, false],
859+
] as const)('%s (page %s, budget %s, %s + %s rows): answered %s', async (_label, page, budget, first, second, answered) => {
860+
if (page) vi.stubEnv(DATA_DEFAULT_PAGE_SIZE_ENV, page);
861+
vi.stubEnv(DATA_QUERY_ROW_BUDGET_ENV, budget);
862+
// The comments are not under test: a page of 150 reads the thread in one answer.
863+
const reactions = [...reactionsOn(1, first), ...reactionsOn(101, second)];
864+
const door = pagingDoor({ sys_comment: THREAD, sys_comment_reaction: reactions });
865+
const { call } = boot({
866+
findData: async (req: any) => (req.object === 'sys_comment'
867+
? { object: req.object, records: THREAD, total: THREAD.length, hasMore: false }
868+
: door(req)),
869+
});
870+
const data = RecordPageResponseSchema.parse((await call({ discussion: true })).body.data);
871+
expect((data.discussion as any).comments).toHaveLength(150);
872+
expect((data.discussion as any).reactions).toEqual(answered
873+
? { records: expect.arrayContaining(reactions.map((row) => expect.objectContaining({ id: row.id }))) }
874+
: { error: { code: 'QUERY_ROW_BUDGET_EXCEEDED', status: 400, message: expect.any(String) } });
875+
if (answered) expect((data.discussion as any).reactions.records).toHaveLength(reactions.length);
876+
});
877+
});
829878
});
830879

831880
describe('[#28737] the timeline part is the 动态 stream\'s size, counted by the caller\'s own reads', () => {

‎ui/packages/app-shell/src/views/useRecordDiscussion.test.tsx‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,124 @@ describe('useRecordDiscussion — a paged discussion against the row budget', ()
465465
expect(result.current.commentsVerdict).toBeUndefined();
466466
});
467467
});
468+
469+
/**
470+
* objectstack#39313 — the reaction read of a thread longer than one reaction
471+
* batch (100 comment ids, `REACTION_READ_COMMENT_IDS`) is one logical read
472+
* against the row budget, as the record page payload reads it (the payload's
473+
* twin of this table is the `[#39313]` describe in
474+
* `packages/rest/src/record-page-routes.test.ts`): the budget bounds the
475+
* thread's reaction rows together. Rows together past the budget, with no
476+
* single batch past it, leave the comments without reactions, as the
477+
* payload's refused `reactions` part does; rows that fit are all shown.
478+
*/
479+
describe('useRecordDiscussion — reactions of a thread past one reaction batch, against the row budget', () => {
480+
type Query = { $filter?: { thread_id?: string; comment_id?: { $in?: string[] } }; $top?: number; $skip?: number };
481+
const COMMENTS = 150;
482+
const pad = (n: number) => String(n).padStart(3, '0');
483+
const comment = (n: number) => ({
484+
id: `c-${pad(n)}`, thread_id: `${OBJECT_NAME}:a`, author_id: 'u2', author_name: 'Grace',
485+
body: `Comment ${n}`, created_at: `2026-01-01T${pad(Math.floor(n / 60)).slice(1)}:${String(n % 60).padStart(2, '0')}:00Z`,
486+
});
487+
/** `count` reactions on comment `n`, each from its own user. */
488+
const reactionsOn = (n: number, count: number) => Array.from({ length: count }, (_, i) => ({
489+
id: `r-${pad(n)}-${i}`, comment_id: `c-${pad(n)}`, user_id: `u-${i}`, emoji: '👍',
490+
created_at: `2026-01-02T10:${pad(n).slice(1)}:${String(i).padStart(2, '0')}Z`,
491+
}));
492+
493+
/**
494+
* The data door's read limits (`planQueryReadWindow`), per query: a read
495+
* naming no `$top` gets `pageSize` rows (the whole set with no page size);
496+
* `$skip` plus `$top` past `budget` is refused, never run; a whole-set read
497+
* longer than the budget is refused whole. Reactions are filtered by their
498+
* `comment_id` `$in`.
499+
*/
500+
function makeDoor({ pageSize, budget }: { pageSize?: number; budget: number }, reactions: Array<Record<string, unknown>>) {
501+
const refuse = () =>
502+
Object.assign(new Error('QUERY_ROW_BUDGET_EXCEEDED'), { code: 'QUERY_ROW_BUDGET_EXCEEDED', httpStatus: 400 });
503+
const page = (rows: Array<Record<string, unknown>>, query: Query) => {
504+
const skip = query.$skip ?? 0;
505+
const top = query.$top ?? pageSize;
506+
if (top === undefined) {
507+
if (skip + rows.length > budget) throw refuse();
508+
return { data: rows.slice(skip), total: rows.length, hasMore: false };
509+
}
510+
if (pageSize !== undefined && top > pageSize) {
511+
throw Object.assign(new Error('MAX_RECORDS_EXCEEDED'), { code: 'MAX_RECORDS_EXCEEDED', httpStatus: 400 });
512+
}
513+
if (skip + top > budget) throw refuse();
514+
const data = rows.slice(skip, skip + top);
515+
return { data, total: rows.length, hasMore: skip + data.length < rows.length };
516+
};
517+
return {
518+
find: vi.fn(async (object: string, query: Query) => {
519+
// The comments are the whole thread: only the reaction read is under test.
520+
if (object === 'sys_comment') return { data: Array.from({ length: COMMENTS }, (_, i) => comment(i + 1)) };
521+
if (object === 'sys_comment_reaction') {
522+
const ids = query.$filter?.comment_id?.$in ?? [];
523+
return page(reactions.filter((row) => ids.includes(String(row.comment_id))), query);
524+
}
525+
return { data: [] };
526+
}),
527+
create: vi.fn(async (_object: string, data: Record<string, unknown>) => data),
528+
update: vi.fn(async () => ({})),
529+
delete: vi.fn(async () => true),
530+
};
531+
}
532+
533+
async function read(ds: unknown) {
534+
const { result } = renderHook(() => useRecordDiscussion(inputFor(ds, 'a')), { wrapper });
535+
await act(async () => {
536+
await result.current.readComments(null);
537+
});
538+
await waitFor(() => expect(result.current.items).toHaveLength(COMMENTS));
539+
return result;
540+
}
541+
542+
/** Every reaction count the read shows, by comment id. */
543+
const shownCounts = (items: readonly FeedItem[]) =>
544+
Object.fromEntries(items.filter((item) => item.reactions?.length).map((item) => [item.id, item.reactions!.map((r) => r.count)]));
545+
546+
// [label, page size, budget, reactions on comment 1 (first batch), on comment 101 (second batch), shown]
547+
it.each([
548+
['rows together past the budget, no batch past it', undefined, 10, 6, 6, false],
549+
['rows together past the budget, no batch past it, paged', 4, 10, 6, 6, false],
550+
['rows that fit the budget exactly across batches', undefined, 10, 5, 5, true],
551+
['rows that fit the budget exactly across batches, paged', 4, 10, 6, 4, true],
552+
['one batch past the budget', undefined, 10, 11, 0, false],
553+
['one batch past the budget, paged', 4, 10, 0, 11, false],
554+
] as const)('%s (page %s, budget %s, %s + %s rows): shown %s, as the payload answers', async (_label, pageSize, budget, first, second, shown) => {
555+
const ds = makeDoor({ pageSize, budget }, [...reactionsOn(1, first), ...reactionsOn(101, second)]);
556+
const result = await read(ds);
557+
// Both batches were read before the answer is judged.
558+
const batches = new Set(ds.find.mock.calls
559+
.filter(([o]) => o === 'sys_comment_reaction')
560+
.map(([, q]) => (q as Query).$filter?.comment_id?.$in?.[0]));
561+
expect([...batches].sort()).toEqual(['c-001', 'c-101']);
562+
const expected = shown
563+
? { ...(first ? { 'c-001': [first] } : {}), ...(second ? { 'c-101': [second] } : {}) }
564+
: {};
565+
await waitFor(() => expect(shownCounts(result.current.items)).toEqual(expected));
566+
// The comments stand either way: the reaction read's answer never takes them down.
567+
expect(result.current.commentsVerdict).toBeUndefined();
568+
// Never one read per comment: every reaction read names at most one batch of ids.
569+
for (const [object, query] of ds.find.mock.calls) {
570+
if (object === 'sys_comment_reaction') expect((query as Query).$filter?.comment_id?.$in?.length).toBeLessThanOrEqual(100);
571+
}
572+
});
573+
574+
it('asks the door its rule of the whole walk once, at the rows read together, and only past one answering batch', async () => {
575+
const ds = makeDoor({ budget: 10 }, [...reactionsOn(1, 6), ...reactionsOn(101, 6)]);
576+
await read(ds);
577+
await waitFor(() => expect(ds.find.mock.calls.filter(([o]) => o === 'sys_comment_reaction')).toHaveLength(3));
578+
const walk = ds.find.mock.calls.filter(([o]) => o === 'sys_comment_reaction')[2][1] as Query;
579+
expect([walk.$skip, walk.$top]).toEqual([11, 1]);
580+
581+
const single = makeDoor({ budget: 10 }, reactionsOn(1, 6));
582+
await read(single);
583+
await waitFor(() => expect(single.find.mock.calls.filter(([o]) => o === 'sys_comment_reaction')).toHaveLength(2));
584+
await act(async () => {});
585+
// One batch answered rows: its own read already judged them.
586+
expect(single.find.mock.calls.filter(([o, q]) => o === 'sys_comment_reaction' && (q as Query).$top === 1)).toHaveLength(0);
587+
});
588+
});

‎ui/packages/app-shell/src/views/useRecordDiscussion.ts‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,23 @@ async function readEveryPage(
509509
* bounds the rows one answer holds, not the reactions a batch of comments has.
510510
* Rows come oldest first, so each comment's emoji keep the order they were
511511
* first given in.
512+
*
513+
* The pages are one logical read, as the record page payload reads them
514+
* (`readReactions` in `@objectstack/rest`, which counts every id chunk's rows
515+
* against the deployment's row budget, `OS_DATA_QUERY_ROW_BUDGET`): the
516+
* budget bounds the thread's reaction rows together, not each page's. Each
517+
* page is its own query to the data door, which counts from its own offset 0,
518+
* so the door judged each page alone. When more than one page answered rows,
519+
* the door is asked its own rule of the whole walk: a read of the last such
520+
* page at `$skip` one short of every row read and `$top` 1, which the door
521+
* refuses, never runs, exactly when the rows together are past the budget
522+
* (its window, `$skip` plus `$top`, is their count). The budget is not served
523+
* to this client and is never inferred here: its refusal rejects the read, as
524+
* a page past it does, and the caller shows the comments without reactions,
525+
* as the payload's refused `reactions` part does. The row that read answers is
526+
* not used. A refusal for any other reason (a `400` that is not the budget's)
527+
* leaves the rows read standing, as a later page's does in
528+
* {@link readEveryPage}; a failure rejects.
512529
*/
513530
async function readCommentReactionRows(
514531
dataSource: Pick<DataSource<Record<string, unknown>>, 'find'>,
@@ -518,10 +535,25 @@ async function readCommentReactionRows(
518535
for (let i = 0; i < commentIds.length; i += REACTION_READ_COMMENT_IDS) {
519536
pages.push(commentIds.slice(i, i + REACTION_READ_COMMENT_IDS));
520537
}
538+
const filters = pages.map((ids) => ({ comment_id: { $in: ids } }));
521539
const answers = await Promise.all(
522-
pages.map((ids) => readEveryPage(dataSource, COMMENT_REACTION_OBJECT, { comment_id: { $in: ids } })),
540+
filters.map(($filter) => readEveryPage(dataSource, COMMENT_REACTION_OBJECT, $filter)),
523541
);
524-
return answers.flat();
542+
const rows = answers.flat();
543+
const answering = answers.map((answer, i) => (answer.length > 0 ? i : -1)).filter((i) => i >= 0);
544+
if (answering.length > 1) {
545+
try {
546+
await dataSource.find(COMMENT_REACTION_OBJECT, {
547+
$filter: filters[answering[answering.length - 1]],
548+
$orderby: { created_at: 'asc', id: 'asc' },
549+
$top: 1,
550+
$skip: rows.length - 1,
551+
});
552+
} catch (err) {
553+
if (feedReadVerdictOf(err) !== 'answered') throw err;
554+
}
555+
}
556+
return rows;
525557
}
526558

527559
/**

0 commit comments

Comments
 (0)