Repository navigation
fix(app-shell): a merged tool result must not rewrite an approval state - #9291
Conversation
Instrument-first: these pins are written against the UNMODIFIED tree, so the "defect present" arm of the ablation is a real commit rather than an injected mutation. Expected to be RED at this commit and green at the next one. Three things land here: * merge-level pins in `useChatConversation.test.ts` — a merged pending-approval result must reach `approval-requested`, an already-approval part must survive the merge, an error result must still win, and a dangling `input-streaming` call with an ORDINARY result must STILL collapse to `output-available` (the load-bearing half of the rewrite, pinned so the narrowing cannot widen). * the objectui#8442 reading pin in `AiChatPage.hydration.test.ts`, turned over IN PLACE with the reason stated at the site. It asserted the defective behaviour on purpose so that fixing it would meet a red line here. * a new end-to-end pin that hydrates real server rows and then drives the REAL `useHitlInChat` over them, so "indexable" is measured by the id reaching the request rather than by restating the hook's predicate. Part of objectui#9233 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ
`mergeToolResultsInto` overwrote the tool part's `state` on every merge:
target.state = isError ? 'output-error' : 'output-available';
The server persists conversations in ModelMessage format — a tool CALL on the
assistant row, its RESULT on a separate `tool` row — so this merge step runs on
the main rehydration path, and it ran unconditionally. A pending approval
therefore reached `hydratedMessagesToChatMessages` as Completed, and the
awaiting-approval card in `ChatbotEnhanced` (gated on `approval-requested`) never
rendered. The operator got no Approve / Reject card at all, even though
`useHitlInChat` had the id and `decide()` was live.
The rewrite itself is load-bearing and stays: it is how a dangling
`input-streaming` / `input-available` becomes Completed instead of spinning
forever. Narrowed to the one statement the defect needs — a merged result must
not rewrite an APPROVAL state:
* a merged result carrying the HITL pending envelope promotes to
`approval-requested`;
* a part that already declares `approval-requested` / `approval-responded`
keeps it;
* an error result still wins over both;
* everything else terminalizes exactly as before.
Those arms are the live mapper's (`mapMessages.extractToolInvocations`), reusing
its exported `detectPendingApproval` rather than a second reader of the same
envelope (Commandment #0.1). `@object-ui/plugin-chatbot` is already a static
member of this package's barrel closure, so no package edge and no eager bundle
weight is added.
Part of objectui#9233
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ
Level justified by measurement in the changeset body, not by intuition: no exported signature, type or declaration key moved, nothing an author authored today stops rendering, and `approval-requested` was already a declared member of the tool-state union. One value on one hydration path changes, in the direction of an affordance appearing where it was supposed to. Part of objectui#9233 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ
✅ Console Performance Budget
The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it. 📦 Bundle Size Report
Size Limits
|
Contract review — PR objectui#9291 @ head
|
| check | reading |
|---|---|
CI at 8d4d06a29 |
36/36 settled — 0 failing, 0 pending |
--pair 9291 |
✓ PR #9291 / card #9233 — both carriers agree |
| production diff | one statement, in mergeToolResultsInto, plus the import that feeds it |
| the narrow statement held | ✓ read in the code, not the report: baseState is the old expression unchanged; approval only applies when baseState !== 'output-error' ⇒ error still wins; a plain result on a dangling input-streaming still terminalizes |
| ⛔ two faces left alone | ✓ useChatConversation.ts:381 (objectui#9232) and both ChatbotEnhanced gate expressions — untouched |
| No-Touch zone | ✓ not touched |
⭐ "The live mapper's own reader, not a second predicate" — verified rather than accepted
This is the Commandment #0.1 claim the whole design rests on, so I read it at source:
packages/plugin-chatbot/src/mapMessages.ts:171 export function detectPendingApproval(
packages/plugin-chatbot/src/mapMessages.ts:664 const pending = detectPendingApproval(result);
packages/plugin-chatbot/src/index.tsx:366 detectPendingApproval,
⇒ the function the hydration path now calls is literally the one the live mapper calls, three lines apart in the same file. Not a copy that agrees today — the same symbol. That is the difference between converging a dialect and seeding a second one.
⭐ The eager-weight claim: CI answered what the seat could not
The seat declared Bundle Analysis NOT MEASURED (it needs a full turbo run build, and the shared verify lock was never acquired — two 540 s queue-timeouts). That was the right call rather than a dressed-up green. ⭐ But it is also the one claim a new top-level import most needs checked, so I looked at what CI actually did: Bundle Analysis — success on this head, alongside Docs Route Eager Closure Check and Pre-Install Import Graph Check, both green.
I also read the closure by hand, because the hook has more importers than AiChatPage — ChatDock.tsx and StudioAiCopilot.tsx both use it, and it is re-exported from hooks/index.ts and the top-level index.ts. The claim still holds: the package's exports map is only "." and "./styles.css", and that barrel already re-exports AiChatPage, which already imports @object-ui/plugin-chatbot statically. ⇒ no consumer reachable through a supported entry gains an edge it did not have. peerDependency with no dependencies entry — that is the pre-existing arrangement for every other import of it in this package, so this adds nothing new, and check:phantom-deps and Pre-Install Import Graph Check are the repo's own judges of it. Both green.
⭐ The pin turnover is the model for how this should be done
AiChatPage.hydration.test.ts:334-342 asserted output-available — today's defective reading, pinned deliberately by objectui#8442 so the fixing card would meet a red line instead of a stale sentence. It is turned over in place, and the replacement comment says so in as many words:
objectui#8442 pinned the defective reading rather than describing it, precisely so the card that fixed it would meet a red line here instead of a stale sentence. This is that red line, paid.
⛔ Not deleted, ⛔ not routed around, and the next reader learns why it flipped without opening a card.
⭐ The end-to-end pin measures "indexable", it does not restate it
The new AiChatPage.approvalRehydration.test.tsx drives the real useHitlInChat over the real hydrated messages and then asserts the request that actually goes out:
expect(url).toBe('http://localhost:3004/api/v1/ai/pending-actions/pa_44/approve')
expect(globalThis.fetch).toHaveBeenCalledTimes(1)
⭐ That second line is the non-vacuity check, and the comment beside it names exactly why it is there — "an unindexed invocation never calls fetch at all". A pin that only asserted "no crash" would have passed against the defect. Both halves of an actionable approval — the id and the state — are now pinned in one file, which is what stops them drifting apart again.
The two arms declared as NOT controls are correctly declared
The error-wins arm and the dangling-input-streaming-still-collapses arm read the same on both sides of the change. The seat named them as guards against the narrowing widening into "stop rewriting the state" rather than offering them as evidence. ⭐ That is the honest use of a row that cannot fire, and it is the guard this card most needed — the load-bearing collapse is the thing a careless fix would have broken.
Ablation
Pin-first, so the "defect present" arm is the real base tree — no mutation to prove, no restore leg to get wrong. 291a116b0 (pins only): Tests 5 failed | 21 passed. All five were assertion failures on the state value (expected 'output-available' to be 'approval-requested'), ⛔ never a module or import failure ⇒ the control lit, and lit for the reason under test. d3c184f07 (fix added): 26 passed.
Changeset
Level argued by measurement. ⛔ major unavailable by construction.
NOT MEASURED, correctly declared
check:readme-exports returned exit 1 naming packages this diff never touched, with "its type entry ./dist/index.d.ts is not on disk — run pnpm build first" ⇒ prerequisite not met, read as NOT MEASURED rather than a failed measurement. Both attempts to get the closure build through the shared verify lock timed out at 540 s (holder: another seat's 7-package vitest, held 1056 s at the second attempt).
Carriers
Cleared in one stroke on both limbs — PR objectui#9291 and card objectui#9233 — each read back.
Generated by Claude Code
|
Fixes #9233
What was wrong
toUIMessages'mergeToolResultsInto(packages/app-shell/src/hooks/useChatConversation.ts) overwrote the tool part'sstateon every merge:The server persists conversations in ModelMessage format — a tool CALL on the assistant row, its RESULT on a separate
toolrow — so this merge is the main rehydration path, and it ran unconditionally. A pending approval was terminalized beforehydratedMessagesToChatMessagesever saw it,ChatbotEnhanced'sisAwaitingApprovalgate (which readsstate === 'approval-requested') never opened, and the operator got no Approve / Reject card at all after a reload — even though objectui#8442 had already made the id indexable anddecide()was live.The fix, and what it deliberately does NOT do
⛔ Not "stop rewriting the state". The rewrite is load-bearing: collapsing a dangling
input-streaming/input-availableinto a terminal state is why it exists, and without it a reloaded conversation shows every tool "Running" forever. The change is the one narrow statement — a merged result must not rewrite an APPROVAL state:approval-requested;approval-requested/approval-respondedkeeps it;Those arms are the live mapper's own (
mapMessages.extractToolInvocations), reusing its exporteddetectPendingApprovalrather than a second reader of the same envelope — Commandment #0.1, and the reason that detector was exported in the first place.@object-ui/plugin-chatbotis already a static member of this package's barrel closure (index.tsre-exportsAiChatPage, which imports it), so this adds no package edge and no eager bundle weight.Two faces were left alone on purpose:
useChatConversation.ts:381belongs to objectui#9232, and the two gate expressions inChatbotEnhancedare correct — the defect was in thestatefed to them.The pin that was supposed to turn over, turned over
AiChatPage.hydration.test.tsassertedexpect(tool?.state).toBe('output-available')— the defective reading, pinned on purpose by objectui#8442 so that a card correcting it would meet a red line instead of a stale sentence. It is flipped in place, with the reason stated at the site. It was not deleted and not routed around.Instrument: the pins were written BEFORE the code
So the "defect present" arm is the real base tree, not an injected mutation — no marker count to prove, no restore leg to get wrong. Two commits, one command, one variable:
291a116b0(pins only)Test Files 3 failed (3)·Tests 5 failed | 21 passed (26)d3c184f07(fix added)Test Files 3 passed (3)·Tests 26 passed (26)All five failures on the first arm were assertion failures on the state value (
expected 'output-available' to be 'approval-requested'), never a module or import failure — so the control lit, and it lit for the reason under test.The three assertions that read the same on both arms are named as such rather than offered as controls: the error-wins arm, the dangling-
input-streaming-still-collapses arm, and theuseHitlInChatindexing half. The first two are guards against the narrowing widening into "stop rewriting the state"; the third already worked before this PR (objectui#8442) and is pinned beside the state so the two halves of an actionable approval can never drift apart again.The new end-to-end pin drives the real
useHitlInChatover the real hydrated messages and asserts the id reaches the request URL — "indexable" measured, not restated as a copy of the hook's predicate.Verification
Measured on the final commit
8d4d06a29.pnpm exec vitest run packages/app-shell/ packages/plugin-chatbot/Test Files 733 passed (733)·Tests 7188 passed | 1 skipped (7189)· wrapperVERDICT command-exit 0pnpm --filter @object-ui/app-shell type-check(tsc --noEmit && tsc -p tsconfig.test.json)VERDICT command-exit 0— the second half covers the test files, so the new pins are type-checked, not merely runpnpm --filter @object-ui/app-shell lintnode scripts/check-changeset-presence.mjspnpm changeset:checkmajor, fixed group intactcheck:control-bytes·check:new-line-citations·check:vi-mock-specifiers·check:vi-mock-inherit·check:vi-mock-override-shape·check:test-path-roots·check:phantom-deps·check:unused-deps·check:esm-specifiers·check:self-import·check:unreferenced-sources·check:changeset-claims·check:pre-install-import-graphPrerequisite first:
pnpm turbo run build --filter='@object-ui/app-shell^...'(28 tasks, exit 0). Before it,type-checkfailed only withTS2307: Cannot find module '@object-ui/*'— unbuilt workspacedist, read as NOT MEASURED, not as a red gate.Lint narrowing, declared with its three pieces of evidence. The package-scoped
eslintrun above is a narrowing of the repo-wide lint, and the narrowing is itself measured: ① the population comes from eslint's own config, not a guess — a repo-wideeslint .enumerated 4892 files; ② that count is read from--format json, not from prose; ③ this repo's eslint config declares noparserOptions.project/projectService, so linting is not type-aware and a change insidepackages/app-shellcannot move the verdict on any file outside it. Repo-widepnpm lint(turbo run lint) remains CI's run.Declared NOT MEASURED locally, left to CI:
Bundle Analysis(check:eager-closure+check:eager-locale-catalogues+check:sdui-registration-pins) needs a full console build; the argument that it should not move is the barrel-closure one above, and it is an argument, not a measurement.check:readme-exports,check:published-distandcheck:node-esm-loadall reported the unbuilt-distprerequisite and are likewise CI's.Blast radius beyond the package. No call site, rendered node or declaration key moved — one value on one internal code path — so no census or prose figure is implicated. Verified by grep:
mergeToolResultsIntoappears nowhere outside this package's own sources and the files in this diff, and no doc, example or app carries prose about the rehydrated approval state.Acceptance notes
useChatConversation.ts:381(the cache-write direction) is objectui#9232's, not touched; objectui#8426 is not a blocker.needs:contract-reviewis hung on both this PR and the card — raising a gate cannot fail open. Clearing either limb is the PM's.🤖 Generated with Claude Code
https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ
Generated by Claude Code