Skip to content

fix(chatbot): redraw record-citation chips after a reload; keep the cited-section scroll to new clicks - #37539

Queued
objectstack-fleet[bot] wants to merge 5 commits into
mainfrom
claude/project-thread-6hqn6k
Queued

objectstack-fleet[bot] wants to merge 5 commits into
mainfrom
claude/project-thread-6hqn6k

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Bill · project thread
Fixes #37487
Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:使用应用内 AI 的用户,刷新页面或重新打开对话后,回答下方的“引自记录”引用条仍然显示;从引用条打开记录后,再打开命令面板或编辑表单、返回,页面不再被拉回被引的那一节。
  • 为什么做:记录 AI 问询专题的引用条跟进卡,原先引用条只在回答当场可见,刷新就消失,无法回头核对出处。
  • 出错会怎样:引用条刷新后不显示,或页面多滚一次;记录和对话数据不受影响,撤回本次合并即可恢复原样。
  • 要你做什么:无。

What changes

Governing text: ruling Q1 on #37144 (draw the persisted, already-verified list; never verify it again); PR #37485 (merged 276174a) and its scope notes on #37487 (S4 on the card, S5 in 7190147175).

  • One allow-list of kept data parts (plugin-chatbot/src/toolResultParsers.ts): STORED_ANSWER_DATA_PARTS names the data parts a stored answer keeps through a rebuild, keyed by the message field that carries each between rebuilds: charts (data-chart, positional) and recordCitations (data-record-citations). storedAnswerParts(content, data) writes them (the charts through the existing chartAnswerParts, then the citations list as one part with the stream's part id). It stays in the eager /core closure, so the part type is spelled there, not imported from @objectstack/spec/ai; a test pins it to RECORD_CITATIONS_PART_TYPE.
  • Reader (plugin-chatbot/src/mapMessages.ts): storedAnswerData(parts) reads every kept part back (chartsFromParts + extractRecordCitations, the same RecordCitationsSchema parse a live part goes through). A refused list is no list.
  • The three rebuilds now go through those two: the /ai history rebuild hydratedMessagesToChatMessages (app-shell/src/console/ai/AiChatPage.tsx, reader), the message cache sanitizeChatMessagesForCache (app-shell/src/hooks/useChatConversation.ts, writer; CacheableChatMessage gains recordCitations), and the useObjectChat initialMessages store rebuild (plugin-chatbot/src/useObjectChat.ts, writer). The table names the kept parts; a further kept part takes three edits (the entry, its write in storedAnswerParts, its read in storedAnswerData).
  • S5 (app-shell/src/views/RecordDetailView.tsx, recordSectionAnchor.ts): the cited-section effect was keyed on the opened-state value or '', so any navigation that dropped history state re-ran it and scrolled back. Two parts:
    • within one mount, the key holds the last string value the state carried, replaced only when a new string arrives (state adjusted during render);
    • the booted console showed the record-form overlay (?form=) remounts the record page without the state, so a component-local memory is not enough. The page now keeps the section it last opened beside the component (claimCitedSectionOpen, { target: RECORD+ANCHOR, opened: CLICK }), claimed at the moment the page would move (focusRecordSection gains an optional mayScroll callback, asked right before scrolling, so an effect re-run before that does not spend it). A redraw at a section already opened marks it again and scrolls nothing. The memory is dropped once no record page has stayed mounted (a zero-delay check after unmount), so a later visit to the same link opens its section again.
  • Exports (Clause-②: yes (widening), per seat record 7193217253 S1; level stays patch): storedAnswerParts, STORED_ANSWER_DATA_PARTS and the types StoredAnswerData, StoredAnswerPart from @object-ui/plugin-chatbot/core and the root; storedAnswerData from the root. Named in the changeset.
  • Docs: the sentence "a conversation reloaded from history does not redraw them yet" in content/docs/frontend/plugins/plugin-chatbot.mdx and ui/packages/plugin-chatbot/README.md was made false by this change and is rewritten. Changeset .changeset/37487-citations-survive-reload.md (patch, @object-ui/plugin-chatbot, @object-ui/app-shell).

Read first, by risk:

  1. ui/packages/plugin-chatbot/src/toolResultParsers.ts: STORED_ANSWER_DATA_PARTS and storedAnswerParts.
  2. ui/packages/app-shell/src/views/RecordDetailView.tsx: claimCitedSectionOpen (module level, above the component) and the sectionOpened state and effect beside holdsRouteRecord.
  3. ui/packages/app-shell/src/hooks/useChatConversation.ts: sanitizeChatMessagesForCache.

Tests

  • app-shell/src/console/ai/__tests__/AiChatPage.recordCitationsReload-37487.test.tsx (6): server history and cache fallback each restore the chips the live answer draws (same quotes, same order; nothing fetched); a restored server answer re-caches with its list; CONTROL on both paths: a refused part (an alias key) draws nothing and is not cached.
  • plugin-chatbot/src/__tests__/useObjectChat.recordCitationsReload-37487.test.tsx (3): the initialMessages store rebuild draws the live chips; CONTROL: a refused list draws nothing (the store part is re-parsed, so the rebuild is no way round the contract); the allow-list entry equals the spec part type.
  • app-shell/src/views/RecordDetailView.citedSection-37365.test.tsx (+2, 8 total): after a chip click, a state-dropping replace (the useUrlOverlay shape) and a pushed overlay followed by Back do not scroll; a pushed overlay that remounts the page, and Back, marks the section again and does not scroll; CONTROL in both: a new click after them scrolls. afterEach waits one macrotask after cleanup() so the page's memory is dropped between cases. recordSectionAnchor.test.tsx unchanged, 18/18.
  • Ablation, shared allow-list: writer and reader of the citations entry disabled → the three positive path tests fail (3 failed, 6 passed), restored → 9/9. Ablation, S5 in-mount: the key read back off the state as before → that test fails (1 failed, 6 passed). Ablation, S5 remount: claimCitedSectionOpen always claims → the remount test fails (1 failed, 7 passed); restored → 8/8.

Acceptance notes

Verification

  • Local: pnpm run type-check in ui/packages/plugin-chatbot and ui/packages/app-shell, exit 0. The local whole-suite run of both packages (vitest run packages/plugin-chatbot/ packages/app-shell/) was stopped after 61 min with one failure, which was my own ablation edit made while it ran; the narrowing is declared, and CI's Test UI (all shards) is green on e2833f9. Rework head 40bb8ee (changeset, jsdoc only): CI check-runs 46 success, 10 skipped before this body edit; the PR-body guards rerun on the edit.
  • Two-minute check: pnpm --dir ui exec vitest run packages/app-shell/src/console/ai/__tests__/AiChatPage.recordCitationsReload-37487.test.tsx packages/plugin-chatbot/src/__tests__/useObjectChat.recordCitationsReload-37487.test.tsx, expected 9 passed.
  • S4 booted-console check, done on head 039bbc3 (the later head e2833f9 changes one test file only). Showcase app (objectstack dev --seed-admin) with the ui/ console dev server pointed at it, driven by Playwright at 1360x900 and as an iPhone 13. Injected, not produced: no producer emits the part before cloud 10c, so the run serves the conversation-history read (GET /api/v1/ai/conversations/ID) with an answer carrying a data-record-citations part, and, because this boot has no model, serves a one-agent catalog (GET /api/v1/ai/agents) so the assistant shows. The cited record is a Field Zoo record whose markdown, html and richtext bodies each hold a cited heading below several screens of text.
    • Chips drawn: 3 (the three quotes), desktop and phone. After a page reload: the same 3, same order.
    • A chip click opens /apps/com.example.showcase/showcase_field_zoo/record/ID?section=ANCHOR; the cited heading is the one marked and sits just under the sticky record header (top 89 px desktop, 45 px phone): contractor-scope (markdown), html-retention (html), rich-escalation (richtext).
    • Refused part (an alias key): 0 chips.
    • S5: scrolled back to the top of the record, opening the command palette (?palette=1, replace) and closing it leaves the page there; opening the record form (?form=ID, push) and Back leaves the page there (before the remount fix it scrolled back, which is how the remount was found). A probe on scrollIntoView records no call.
    • Screenshots: objectstack-seat5/ai-36996/shots-37487/ in the project files (9 images plus the script).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Utp6CY3qzEGtLEnwjFyRXG


Generated by Claude Code

…ection scroll to new clicks

The /ai history rebuild, the message cache and the useObjectChat store
rebuild now keep the data parts one allow-list names (charts and record
citations). The record section effect re-runs only when a new opened-state
value arrives, not on a navigation that drops the history state.

Claude-Session: https://claude.ai/code/session_01Utp6CY3qzEGtLEnwjFyRXG
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 26, 2026
…es not scroll back to the cited section

The browser check showed the record-form overlay remounts the record page
without the click's history state, so the cited-section effect ran again and
scrolled back. The page now remembers the section it last opened beside the
component, claimed when the page would move: a redraw at that section marks
it again and scrolls nothing. The memory is dropped once no record page is
mounted.

Claude-Session: https://claude.ai/code/session_01Utp6CY3qzEGtLEnwjFyRXG
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/l and removed size/m labels Nov 26, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head e2833f9 · 2026-11-26T13:12Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: TIER_DEFAULT
Head-sha: e2833f914872f06fe35da9f83d996a8127fbb209
Local-runs: none

Read: card #37487 (body; comments 7186889924, 7189270058, 7190147175, claim 7190899980, amendment 7191223613, os-dev report 7192922175), the PR body, git diff origin/main...pr-37539-x (15 files, +502/−27), the head's check-runs (all green: Type Check UI, Test UI 16/16 shards, Lint UI, Check Changeset, Build & E2E UI, Live E2E UI; the rest success or skipped, 0 failed), PR #37485's records 7186860933 and 7190126794 for the Clause-② precedent, and the area's L1 notes as one input. Nothing was built or run.

① Derived judgments

Accept set: unchanged, right. The citations list is read back through extractRecordCitations, which is the same RecordCitationsSchema parse a live part goes through. That schema is a strict object capped at RECORD_CITATIONS_MAX (20), and re-parsing a list that already parsed gives the same list. A refused list is not written to the cache and draws nothing. Nothing is verified again (ruling Q1). There is a control on each of the three paths.

Allow-list: keeps what a reload needs, drops nothing that was kept before. I checked all three paths against main. Each one gains something and loses nothing.

  • Cache writer: it used to write chartAnswerParts(content, charts). It now writes storedAnswerParts, which is that same output plus at most one data-record-citations part. User turns get the same text parts as before.
  • useObjectChat writer: same as the cache writer, with the reasoning part still appended after.
  • History reader: it used to run chartsFromParts. It now runs storedAnswerData, which returns the charts plus the citations.

The other data parts the mapper reads (data-build-progress, data-blueprint-progress) were not kept before this PR and are still not kept, so no reader loses anything a user saw. The share page (SharedRecordPage) also goes through hydratedMessagesToChatMessages. But aiMessageRowsToServerMessages turns an assistant row into text plus tool calls only, so no citations part reaches it and nothing changes there.

Module memory (S5): no leak, bounded, reset correctly. I read claimCitedSectionOpen and the counter of mounted record pages beside it.

  • It holds one slot ({ target, opened }) and one counter, so it cannot grow.
  • It can only hold back a scroll. It never causes one, and the mark always comes from the page's own candidates.
  • target is objectName:recordId plus the anchor. A different record or anchor never matches, so it can never give a second record the first one's section effect.
  • Each click id is unique (Date.now plus a counter). A real chip click always claims and scrolls.
  • It cannot leak across users or sessions. It lives only in this JS realm: a reload or a new tab starts empty. Sign-out unmounts the record page, and the zero-delay check then clears the slot.
  • A remount in the same commit keeps the slot, because the new mount's effect runs before the timer fires. Strict-mode double effects stay balanced.
  • focusRecordSection calls finish() before its single scroll, so asking mayScroll there cannot suppress a second scroll that the page needed.

Public surface: widened. That is right as a change, but it is declared wrong (S1).

  • New on @object-ui/plugin-chatbot, all absent on main:
    • root and ./core: storedAnswerParts, STORED_ANSWER_DATA_PARTS, and the types StoredAnswerData and StoredAnswerPart;
    • root only: storedAnswerData.
  • The package is published. It is not private, it has exports for . and ./core, and it sits in the fixed group with access: public.
  • @object-ui/app-shell is private, so its new CacheableChatMessage.recordCitations field is not public surface.

Pins guard the behaviour.

  • Allow-list: a pin ties the allow-list entry to RECORD_CITATIONS_PART_TYPE. Disabling the citations entry in writer and reader turns 3 tests red.
  • S5 in-mount: reading the key back off the state turns its test red.
  • S5 remount: making claimCitedSectionOpen always claim turns the remount test red.
  • Memory reset: there is no named pin, but it is held in effect. The setext case remounts ?section=scope after cleanup() plus one macrotask, and expects a scroll. Without the reset, that case would fail.

② Semver level

Changeset level: right. patch on @object-ui/plugin-chatbot and @object-ui/app-shell is correct: Metadata-protocol: none takes patch, and a non-protocol widening also ships patch (AGENTS.md, Post-Task Checklist step 3). The two packages are exactly the ones whose src the diff moves. Metadata-protocol: none is right, since no metadata author can write anything new.

S1 (must-fix) — Clause-②: no is wrong; it should read Clause-②: yes (widening).

  • The test is whether the change widens the accept set or the public surface. Five exports are new on a published package's root, and four of them also on ./core (① above).
  • The seat's precedent on PR feat(chatbot): draw verified record citations as chips that open the cited section #37485 graded a new optional member and a new reserved URL parameter as widening, under Clause-②: yes. A new named export is at least as public as either.
  • The amendment 7191223613 left the final line to this review, and the PR body says the same. A wrong no is an auditable false declaration.
  • Fix: put Clause-②: yes (widening) at line start in both the PR body and the changeset body. Name the new exports in the changeset body, as the package's own CHANGELOG did for chartsFromParts / chartAnswerParts. The level stays patch, and no ! is owed.

③ Boundary flags

  • open_questions: none.
  • The PR body's flag ("Clause-②: no kept, for the area to judge at L1"): answered by S1.
  • Out-of-scope finding, phone dock sheet covering the cited heading: carried by 37487 跟进:手机上点 AI 引用后,对话面板仍盖住被引用的段落 #37556 (open). Answered.
  • Out-of-scope finding, N6/N7 of 7190147175: escalated to area ai-36996. Their only carrier is 37365 跟进:刷新或重开对话后,AI 回答下方的引用消失 #37487, and Fixes #37487 closes it on merge. File a carrier card for them before this lands.
  • Deviations: answered.
    • The S4 run injected the history part and a one-agent catalog. The card allowed that (7186889924) and the PR says so.
    • Single-file reruns ran outside the verify lock. That is moot, because CI ran every family green on this head.
  • SQL push-down: not applicable. The diff reads no data and adds no query, id materialisation or join. It only reshapes parts that are already in memory.

Nits (no effect on correctness or the contract):

  • N1 (nit) — STORED_ANSWER_DATA_PARTS names the kept parts, but it does not drive the code.
    • storedAnswerData reads chartsFromParts and the spec constant, and chartAnswerParts writes its own 'data-chart' literal.
    • So "a part added to the allow-list is read wherever it is written" (jsdoc in mapMessages.ts) and "a further kept part is one entry in the allow-list" (PR body) both overstate it. Today a new kept part needs edits in three places.
    • The jsdoc in toolResultParsers.ts also cites storedAnswerParts.recordCitations-37487.test.ts, which does not exist. The pin is in useObjectChat.recordCitationsReload-37487.test.tsx.
  • N2 (nit) — The in-mount sectionOpened and the shared slot both outlive moves between records while a RecordDetailView stays mounted. Embedded drawer or split-pane views count as mounted too.
    • Effect: a stateless in-app link back to a section that was already opened would mark it but not scroll.
    • Today that is not reachable in the app: only chips write ?section=, and each one carries a fresh state value. Same as the area's L1 N1.

Implemented-by: claude/project-thread-6hqn6k
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: FAIL

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: e2833f914872f06fe35da9f83d996a8127fbb209
REWORK — L1, seat repo:objectstack#5

  1. Shape: open draft against main, Fixes #37487. 15 files, +502/−27. Not governed. No review face, so the declaration face applies at TIER_DEFAULT.
  2. Premise: one allow-list now governs stored data parts on all three rebuild paths. Each path keeps a superset of what main kept, so a reload loses nothing the user saw. The module-level section memory holds a single slot, is keyed by object, record id and anchor, cannot cause a scroll, and clears once no record page is mounted. The code holds.
  3. Gates: contract record 7193217253 reads FAIL, on a declaration only. CI on this head is green.
  4. Owed for the delta (prose and changeset only):
  5. Out of scope and where it went: 37487 跟进:手机上点 AI 引用后,对话面板仍盖住被引用的段落 #37556, plus the N6/N7 card to be filed.
  6. Next: push, then knock. The delta reads S1. After ACCEPT, area ai-36996 lands it.

…llow-list drives

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head 40bb8ee · 2026-11-26T13:46Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head 40bb8ee · 2026-11-26T13:59Z (re-record after the body-only fix)

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 40bb8ee4a17f20598279e6fcb4cc94d534a8d6c2
Local-runs: none

This record covers the same head as the earlier delta record, after a change to the PR body only. It replaces that record on this head.

I read the current PR body and every check-run on this head. Nothing was built or run.

① Derived judgments

The code is unchanged since the delta record: same head, and the two .ts hunks of the delta are jsdoc only. The accept set, the public surface, the S5 memory and the pins stand as judged in 7193217253.

N1: closed. The jsdoc in toolResultParsers.ts and mapMessages.ts now says the allow-list names the kept parts and takes three edits per new part. It cites the test file that holds the pin.

N2: accepted by the seat (REWORK 7193228908).

② Semver level

S1: closed.

  • Clause-②: yes (widening) stands at line start in the PR body and the changeset body.
  • Metadata-protocol: none stands.
  • The changeset names the five new exports.
  • patch on @object-ui/plugin-chatbot and @object-ui/app-shell is correct.
  • The newest Check Changeset run, job 139953755090 at 13:51Z, is green.

③ Boundary flags

S2: closed.

Check-runs on this head:

  • The newest run of every check name is green: 44 success and 12 skipped, with none failed or pending.
  • Of all 64 runs listed, the only non-green one is the superseded job 139952208807.

The PR body's check counts were refreshed.

Follow-up cards:

SQL push-down does not apply: the diff adds no query.

Implemented-by: claude/project-thread-6hqn6k
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: 40bb8ee4a17f20598279e6fcb4cc94d534a8d6c2
ACCEPT — L1, seat repo:objectstack#5

  1. Shape: open draft against main, Fixes #37487. 15 files. Not governed, no narrowing. Clause-②: yes (widening): @object-ui/plugin-chatbot gains five exports, named in the changeset (patch). Metadata-protocol: none.
  2. Premise: a single allow-list for stored data parts now covers all three rebuild paths, and each path keeps a superset of what main kept, so citations survive a reload. The module-level section memory is single-slot and keyed by object, record id and anchor. It is cleared once no record page is mounted.
  3. Gates: contract record 7194188712 (same reviewer, same head, after the body-only fix) reads PASS: S1, N1 and S2 are closed. On this head the newest run of every check is green, including PR-body guards (job 139953753736). The red job 139952208807 is the superseded earlier run.
  4. Accepted deviations: N2 (the section memory outlives moves between records while the page stays mounted; no in-app path reaches it).
  5. Out of scope and where it went: 37487 跟进:引用定位在同名标题与空段落两个边角的处理 #37562 (N6/N7), 37487 跟进:手机上点 AI 引用后,对话面板仍盖住被引用的段落 #37556 (phone dock sheet).
  6. Landing terms: ungoverned, default tier, no narrowing. Area ai-36996 lands it with --land.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc

Landing: ACCEPT 7194202614 (same-head contract record 7194188712, PASS) at head 40bb8ee4a.

Probe Reading
Check-runs on head 49 success, 14 skipped, 0 in progress; 1 failure is PR-body guards job 139952208807 (13:46Z), superseded on the same head by job 139953753736, success at 13:49Z after a body-only patch
Governed / size check-governed-merges --pr 37539: NOT governed, 529 changed lines ≤ 3000; mergeable_state clean

Status: ready + auto-merge (merge queue). On MERGED, #37487 closes by Fixes; #37562 carries N6/N7 of scope note 7190147175; #37556 (phone dock sheet, card thread in flight) carries the class-a finding.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 26, 2026 14:05
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 26, 2026
Any commits made after this event will not be merged.

This branch has not been deployed

No deployments
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/l 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.

37365 跟进:刷新或重开对话后,AI 回答下方的引用消失

2 participants