From 0a6c9291c4b96c2d9bfe9a645d0f1a56a29fce99 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 02:56:36 +0000 Subject: [PATCH 1/4] fix(app-shell): read a record's whole discussion past a data page cap; judge a phone thread gone by its root Claude-Session: https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK Co-authored-by: Claude --- .../src/views/objectViewCommentsPage.tsx | 55 ++++++++++++++++--- .../src/views/useRecordDiscussion.ts | 47 +++++++++++++++- 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/ui/packages/app-shell/src/views/objectViewCommentsPage.tsx b/ui/packages/app-shell/src/views/objectViewCommentsPage.tsx index 8c7952cd49b..5cc7b254bfc 100644 --- a/ui/packages/app-shell/src/views/objectViewCommentsPage.tsx +++ b/ui/packages/app-shell/src/views/objectViewCommentsPage.tsx @@ -239,7 +239,12 @@ function ViewCommentThreadPage({ threadTitle={recordName ? { label: recordName, onPress: () => onOpenRecord(thread.recordId) } : undefined} onEngage={engage} /> - + )} @@ -247,19 +252,53 @@ function ViewCommentThreadPage({ } /** - * The named thread is not in its record's discussion once that is read - * (deleted, here or elsewhere, or a stale link): back to the cards, rather - * than the record's own list of threads. + * The named thread is gone (deleted, here or elsewhere, or a stale link): + * back to the cards, rather than the record's own list of threads. + * + * Gone is judged by the thread's own top-level comment, read by its id, and + * asked only once the record's discussion is read without it: a discussion + * the deployment serves only in part may lack a thread that exists. The + * comment answers gone when no row comes back, or the row is not a top-level + * comment of this record's discussion. A refused or failed read says nothing + * about the thread, so the page stays. */ -function ThreadGone({ threadId, onGone }: { threadId: string; onGone: () => void }) { +function ThreadGone({ + threadId, + discussionId, + dataSource, + onGone, +}: { + threadId: string; + /** The record's discussion key, `object:recordId`, as `sys_comment.thread_id` stores it. */ + discussionId: string; + dataSource: DataSource; + onGone: () => void; +}) { const { threads, loading, denied, failed } = useRecordComments(); - const gone = !loading && !denied && !failed && !threads.some((candidate) => String(candidate.root.id) === threadId); + const absent = !loading && !denied && !failed && !threads.some((candidate) => String(candidate.root.id) === threadId); const goneRef = useRef(onGone); goneRef.current = onGone; useEffect(() => { - if (gone) goneRef.current(); - }, [gone]); + if (!absent) return undefined; + let live = true; + Promise.resolve(dataSource.findOne('sys_comment', threadId)).then( + (row) => { + if (live && !isThreadRoot(row, discussionId)) goneRef.current(); + }, + () => undefined, + ); + return () => { + live = false; + }; + }, [absent, threadId, discussionId, dataSource]); return null; } +/** `row` is a top-level comment of the discussion `discussionId`. */ +function isThreadRoot(row: unknown, discussionId: string): boolean { + if (!row || typeof row !== 'object') return false; + const { thread_id: discussion, parent_id: parent } = row as { thread_id?: unknown; parent_id?: unknown }; + return String(discussion) === discussionId && (parent == null || parent === ''); +} + export default ObjectViewCommentsPage; diff --git a/ui/packages/app-shell/src/views/useRecordDiscussion.ts b/ui/packages/app-shell/src/views/useRecordDiscussion.ts index 8ffa68f5705..1e85f90fe35 100644 --- a/ui/packages/app-shell/src/views/useRecordDiscussion.ts +++ b/ui/packages/app-shell/src/views/useRecordDiscussion.ts @@ -406,6 +406,51 @@ async function readCommentReactionRows( return answers.flatMap((res) => (Array.isArray(res?.data) ? res.data : [])); } +/** + * A record's whole discussion from `sys_comment` (`thread_id` is the + * record's `object:id` key), oldest first, as one `{ data }` answer. + * + * A deployment with a data page size (`OS_DATA_DEFAULT_PAGE_SIZE` / + * `OS_DATA_MAX_PAGE_SIZE`) answers a read that names no page with its first + * page and `hasMore`; the discussion is every comment, including the newest + * and every thread that starts past that page (a surface that opens a thread + * by its id judges it gone from these rows). So while the answer says there + * is more, the next page is read, each the size the first page was + * (never over the deployment's maximum) and starting where the rows read so + * far end. With no page size the first answer is the whole discussion, read + * once, as before. + * + * A later page that fails (a 5xx, a network failure) or is refused fails the + * whole read, as the first page's would: a discussion missing comments it + * cannot name is not the discussion. A later page the server declines for a + * reason no retry changes (a `400`: the deployment's row budget stops any read + * that walks this deep) ends the paging, and the pages read stand: the reader + * sees as much of the discussion as the deployment serves anyone. + */ +async function readRecordComments( + dataSource: Pick>, 'find'>, + threadId: string, +): Promise<{ data: unknown[] }> { + const query = { $filter: { thread_id: threadId }, $orderby: { created_at: 'asc' as const } }; + const first = await dataSource.find(COMMENT_OBJECT, query); + const rows: unknown[] = Array.isArray(first?.data) ? [...first.data] : []; + if (first?.hasMore !== true || rows.length === 0) return { data: rows }; + const pageSize = rows.length; + for (;;) { + let page: Awaited>; + try { + page = await dataSource.find(COMMENT_OBJECT, { ...query, $top: pageSize, $skip: rows.length }); + } catch (err) { + if (feedReadVerdictOf(err) === 'answered') break; + throw err; + } + const data: unknown[] = Array.isArray(page?.data) ? page.data : []; + rows.push(...data); + if (page?.hasMore !== true || data.length === 0) break; + } + return { data: rows }; +} + /** * Reaction rows grouped per comment into the `{ emoji: userIds[] }` shape the * `sys_comment.reactions` column stores, so both stores reach the screen @@ -617,7 +662,7 @@ export function useRecordDiscussion({ }; const commentsRead: Promise<{ data?: any[]; reactionRows?: Array> | null }> = - served ?? dataSource.find('sys_comment', { $filter: { thread_id: threadId }, $orderby: { created_at: 'asc' } }); + served ?? readRecordComments(dataSource, threadId); return commentsRead .then(async (res: any) => { recordVerdict('answered'); From 7b9d7c681b02217f81410d04f6320191c49b794b Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 03:03:21 +0000 Subject: [PATCH 2/4] test(app-shell): pin a phone thread past the first page of its record discussion Claude-Session: https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK Co-authored-by: Claude --- ...bjectView.phoneCommentsPage-39086.test.tsx | 76 +++++++++++++++++-- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/ui/packages/app-shell/src/views/ObjectView.phoneCommentsPage-39086.test.tsx b/ui/packages/app-shell/src/views/ObjectView.phoneCommentsPage-39086.test.tsx index 1eb1a96f7ed..ba7773423a5 100644 --- a/ui/packages/app-shell/src/views/ObjectView.phoneCommentsPage-39086.test.tsx +++ b/ui/packages/app-shell/src/views/ObjectView.phoneCommentsPage-39086.test.tsx @@ -167,20 +167,40 @@ afterEach(() => { try { window.localStorage.removeItem(VIEW_COMMENTS_OPEN_KEY); } catch { /* none */ } }); -function mount(opts: { enable?: Record; door?: boolean; search?: string; discussion?: unknown[]; threads?: unknown } = {}) { +function mount(opts: { + enable?: Record; + door?: boolean; + search?: string; + discussion?: unknown[]; + threads?: unknown; + /** The deployment's data page size: a read naming no `$top` gets this many rows and `hasMore`. */ + pageCap?: number; +} = {}) { const object = taskObject(opts.enable); const i18n = createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false }); const queryCommentThreads = vi.fn(async () => opts.threads ?? THREADS); const discussion = opts.discussion ?? DISCUSSION; - const find = vi.fn(async (resource: string) => { + const find = vi.fn(async (resource: string, params?: { $top?: number; $skip?: number }) => { if (resource === 'tracker_task') return { data: ROWS, total: ROWS.length }; - if (resource === 'sys_comment') return { data: discussion }; + if (resource === 'sys_comment') { + if (opts.pageCap === undefined) return { data: discussion }; + const skip = params?.$skip ?? 0; + const top = params?.$top ?? opts.pageCap; + if (top > opts.pageCap) throw Object.assign(new Error('HTTP 400 MAX_RECORDS_EXCEEDED'), { status: 400 }); + const data = discussion.slice(skip, skip + top); + return { data, total: discussion.length, hasMore: skip + data.length < discussion.length }; + } return { data: [] }; }); + // The comment by its id, as the data door answers it: `null` once it is deleted. + const findOne = vi.fn(async (resource: string, id: string) => + resource === 'sys_comment' + ? (discussion as Array<{ id: string }>).find((row) => row.id === id) ?? null + : null); const create = vi.fn(async (_resource: string, data: Record) => ({ ...data })); const dataSource = { find, - findOne: vi.fn(async () => null), + findOne, create, update: vi.fn(async () => ({})), delete: vi.fn(async () => ({})), @@ -207,7 +227,7 @@ function mount(opts: { enable?: Record; door?: boolean; search? , ); - return { queryCommentThreads, find, create }; + return { queryCommentThreads, find, findOne, create }; } const settle = () => act(async () => { @@ -407,3 +427,49 @@ describe('objectstack#39086 — the phone list page comments page', () => { expect(new URLSearchParams(href().split('?')[1]).get('comments')).toBe(''); }); }); + +/** + * objectstack#39195 — on a deployment with a data page size, a record's + * discussion is read past its first page, and a thread is judged gone by its + * own top-level comment, never by its absence from a page. + */ +describe('objectstack#39195 — a thread past the first page of its record discussion', () => { + /** Three threads on `tracker_task:t1`, oldest first; `c3` starts past a two-row page. */ + const LONG_DISCUSSION = [ + ...DISCUSSION, + { id: 'c2', thread_id: 'tracker_task:t1', author_id: 'u3', author_name: 'Linus', body: 'Second thread', parent_id: null, created_at: '2026-12-02T10:00:00Z', is_resolved: false }, + { id: 'c3', thread_id: 'tracker_task:t1', author_id: 'u2', author_name: 'Grace', body: 'Third thread', parent_id: null, created_at: '2026-12-02T11:00:00Z', is_resolved: false }, + { id: 'r3', thread_id: 'tracker_task:t1', author_id: 'u3', author_name: 'Linus', body: 'Late reply', parent_id: 'c3', created_at: '2026-12-02T11:05:00Z' }, + ]; + + it('opens a thread that starts past the first page, with its replies, and stays on it', async () => { + const { find } = mount({ search: '?comments=c3&commentsRecord=t1', discussion: LONG_DISCUSSION, pageCap: 2 }); + await waitFor(() => expect(threadPage()?.getAttribute('data-comments-page')).toBe('thread'), { timeout: 5000 }); + await waitFor(() => expect(threadPage()!.querySelector('[data-comment-id="r3"]')).not.toBeNull(), { timeout: 5000 }); + expect(threadPage()!.textContent).toContain('Third thread'); + await settle(); + expect(threadPage()?.getAttribute('data-comments-page')).toBe('thread'); + expect(new URLSearchParams(href().split('?')[1]).get('comments')).toBe('c3'); + // Read page after page, each the first page's size, from where the rows read end. + const pages = find.mock.calls + .filter(([resource]) => resource === 'sys_comment') + .map(([, params]) => [params?.$skip, params?.$top]); + expect(pages).toEqual(expect.arrayContaining([[undefined, undefined], [2, 2], [4, 2]])); + }); + + it('still falls back to the cards for a deleted thread, judged by its own comment', async () => { + const { findOne } = mount({ search: '?comments=c9&commentsRecord=t1', discussion: LONG_DISCUSSION, pageCap: 2 }); + await waitFor(() => expect(document.querySelector('[data-view-comment-card="c1"]')).not.toBeNull(), { timeout: 5000 }); + await waitFor(() => expect(threadPage()).toBeNull(), { timeout: 5000 }); + expect(page()!.getAttribute('data-view-comments-page')).toBe('list'); + expect(new URLSearchParams(href().split('?')[1]).get('comments')).toBe(''); + expect(findOne).toHaveBeenCalledWith('sys_comment', 'c9'); + }); + + it('falls back to the cards for a link that names a reply, not a thread', async () => { + mount({ search: '?comments=r3&commentsRecord=t1', discussion: LONG_DISCUSSION, pageCap: 2 }); + await waitFor(() => expect(document.querySelector('[data-view-comment-card="c1"]')).not.toBeNull(), { timeout: 5000 }); + await waitFor(() => expect(threadPage()).toBeNull(), { timeout: 5000 }); + expect(new URLSearchParams(href().split('?')[1]).get('comments')).toBe(''); + }); +}); From c31010f19cf5f223cb605186c503cf263bcb39b2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 03:04:07 +0000 Subject: [PATCH 3/4] test(app-shell): pin that a thread the row budget keeps out of the read is not reported gone Claude-Session: https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK Co-authored-by: Claude --- .../ObjectView.phoneCommentsPage-39086.test.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ui/packages/app-shell/src/views/ObjectView.phoneCommentsPage-39086.test.tsx b/ui/packages/app-shell/src/views/ObjectView.phoneCommentsPage-39086.test.tsx index ba7773423a5..bf6fcf69ac0 100644 --- a/ui/packages/app-shell/src/views/ObjectView.phoneCommentsPage-39086.test.tsx +++ b/ui/packages/app-shell/src/views/ObjectView.phoneCommentsPage-39086.test.tsx @@ -175,6 +175,8 @@ function mount(opts: { threads?: unknown; /** The deployment's data page size: a read naming no `$top` gets this many rows and `hasMore`. */ pageCap?: number; + /** The deployment's row budget: a read whose `$skip` plus `$top` walks past it is refused with a 400. */ + rowBudget?: number; } = {}) { const object = taskObject(opts.enable); const i18n = createI18n({ defaultLanguage: 'en', detectBrowserLanguage: false }); @@ -187,6 +189,9 @@ function mount(opts: { const skip = params?.$skip ?? 0; const top = params?.$top ?? opts.pageCap; if (top > opts.pageCap) throw Object.assign(new Error('HTTP 400 MAX_RECORDS_EXCEEDED'), { status: 400 }); + if (opts.rowBudget !== undefined && skip + top > opts.rowBudget) { + throw Object.assign(new Error('HTTP 400 QUERY_ROW_BUDGET_EXCEEDED'), { status: 400 }); + } const data = discussion.slice(skip, skip + top); return { data, total: discussion.length, hasMore: skip + data.length < discussion.length }; } @@ -466,6 +471,16 @@ describe('objectstack#39195 — a thread past the first page of its record discu expect(findOne).toHaveBeenCalledWith('sys_comment', 'c9'); }); + it("does not report gone a thread the deployment's row budget keeps out of the read", async () => { + const { findOne } = mount({ search: '?comments=c3&commentsRecord=t1', discussion: LONG_DISCUSSION, pageCap: 2, rowBudget: 2 }); + await waitFor(() => expect(findOne).toHaveBeenCalledWith('sys_comment', 'c3'), { timeout: 5000 }); + await settle(); + // The page stays on the thread's record, not back on the cards. + expect(threadPage()).not.toBeNull(); + expect(page()!.getAttribute('data-view-comments-page')).toBe('thread'); + expect(new URLSearchParams(href().split('?')[1]).get('comments')).toBe('c3'); + }); + it('falls back to the cards for a link that names a reply, not a thread', async () => { mount({ search: '?comments=r3&commentsRecord=t1', discussion: LONG_DISCUSSION, pageCap: 2 }); await waitFor(() => expect(document.querySelector('[data-view-comment-card="c1"]')).not.toBeNull(), { timeout: 5000 }); From a020f36008e5aa36d5ee03206f01a6ab7e166669 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 03:18:46 +0000 Subject: [PATCH 4/4] chore: changeset for the phone thread past the first page Claude-Session: https://claude.ai/code/session_01Utp6Ca2yTZZiHWkyVgD2oK Co-authored-by: Claude --- .changeset/39195-thread-past-first-page.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .changeset/39195-thread-past-first-page.md diff --git a/.changeset/39195-thread-past-first-page.md b/.changeset/39195-thread-past-first-page.md new file mode 100644 index 00000000000..de33a274d61 --- /dev/null +++ b/.changeset/39195-thread-past-first-page.md @@ -0,0 +1,12 @@ +--- +'@object-ui/app-shell': patch +--- + +fix(console): a comment thread past the first page of its record's discussion opens, and is not reported gone + +Clause-②: no +Metadata-protocol: none + +On a deployment with a data page size (`OS_DATA_DEFAULT_PAGE_SIZE` / `OS_DATA_MAX_PAGE_SIZE`), a record's discussion is now read past its first page: while the comment read answers `hasMore`, the next page is read, each the size of the first. The record page (when it reads the discussion itself) and both list comment surfaces now show the record's newest comments and every thread, not only the oldest page. A later page that fails fails the read as before; a later page refused with a `400` (the deployment's row budget) ends the paging and the pages read are shown. + +On the phone list page's comments page, a thread is reported gone, and the page goes back to the cards, only when its own top-level comment, read by its id, is missing or is not a top-level comment of that record. A thread the record's discussion read could not reach stays open. A deleted thread, or a link that names a reply, still goes back to the cards.