Repository navigation
fix(native-chat): save every chat reply and tool output whole; bound only the copy sent to clients #29982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix(native-chat): save every chat reply and tool output whole; bound only the copy sent to clients #29982
Changes from 10 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
65fb070
fix(native-chat): save every chat reply and tool output whole; bound …
brennanb2025 f76af6b
test(native-chat): an over-budget history item is shortened and marke…
brennanb2025 7c5006c
fix(native-chat): format, keep the sink and projection under the line…
brennanb2025 f89b4ea
fix(chat): preserve complete writes and keep detail current
brennanb2025 9533770
test(chat): align final tail reservation with captured content
brennanb2025 e5ed387
Prototype source-batch journal ownership for Claude
brennanb2025 bdb49ab
Pin the resolved iterator promise in ownership experiment
brennanb2025 c796b9a
Revert "Pin the resolved iterator promise in ownership experiment"
brennanb2025 779d3f5
Revert "Prototype source-batch journal ownership for Claude"
brennanb2025 130ff37
Preserve large received chat content while pacing input
brennanb2025 b258506
Verify received chat writes wait for journal persistence
brennanb2025 3659455
Close test journal databases before removing temporary roots
brennanb2025 21c1b1f
Exercise item detail in the cross-version chat wire manifest
brennanb2025 a8b9136
Pin complete saved output and fitted client publication
brennanb2025 6b9151c
Exercise Pi exit retention with real journal write pressure
brennanb2025 9aba430
Settle terminal web test unmount before DOM teardown
brennanb2025 5455975
Reuse existing readers and contract support in session tests
brennanb2025 9f1f88a
Reuse measured chat item sizes in history pages
brennanb2025 fc3a597
fix(chat): derive page form type from reader contract
brennanb2025 a56e612
fix(chat): open phone user messages while loading full text
brennanb2025 e2b2dbd
test(native-chat): reuse imperative context provider construction
brennanb2025 f40c3e1
test(native-chat): format full-content disclosure fixture
brennanb2025 1888c65
ci: preserve unit shard diagnostics after a timeout
brennanb2025 87eec4c
ci: retain unit shard output when tests time out
brennanb2025 0b4991b
ci: expose unit shard watchdog and output stages
brennanb2025 a95ac75
Revert "ci: expose unit shard watchdog and output stages"
brennanb2025 abaa79e
Revert "ci: retain unit shard output when tests time out"
brennanb2025 c7ed2a3
Revert "ci: preserve unit shard diagnostics after a timeout"
brennanb2025 39e8f80
test: verify complete Claude tool output without large failure diffs
brennanb2025 2c810f2
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-ful…
brennanb2025 4b70297
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-ful…
brennanb2025 ee09041
Simplify reply extraction in cross-version session test
brennanb2025 2289a48
Restore full message recovery for grouped phone thoughts
brennanb2025 e53bf74
Target recovery button in grouped thought fixture
brennanb2025 bb39669
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-ful…
brennanb2025 f1fb1d8
Merge commit '7884f6e738decfa7ee0513ac7f6f19fd768c334e' into brennanb…
brennanb2025 dbe2e3c
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-ful…
brennanb2025 b03cd95
Merge current main into chat payload retention branch
brennanb2025 a63e3a4
test(native-chat): count agentSession.item alongside main's new struc…
brennanb2025 0c273b1
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-ful…
brennanb2025 460fb97
Merge remote-tracking branch 'origin/main' into brennanb2025/chat-ful…
brennanb2025 48f7115
fix(chat): reuse strict session subscription schema
brennanb2025 73f8ba9
test(chat): open Codex before checking received content
brennanb2025 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { createElement } from 'react' | ||
| import { act, create, type ReactTestRenderer } from 'react-test-renderer' | ||
| import { afterEach, expect, it, vi } from 'vitest' | ||
| import type { NativeChatMessage } from '../../../src/shared/native-chat-types' | ||
| import type { RpcClient } from '../transport/rpc-client' | ||
| import { MobileNativeChatItemSourceContext } from './mobile-native-chat-item-read' | ||
| import { useMobileNativeChatFullMessage } from './MobileNativeChatFullContent' | ||
|
|
||
| vi.mock('react-native', () => ({ | ||
| Pressable: 'Pressable', Text: 'Text', View: 'View', | ||
| StyleSheet: { create: (value: unknown) => value, hairlineWidth: 1 } | ||
| })) | ||
| const message: NativeChatMessage = { id: 'message', role: 'assistant', source: 'transcript', timestamp: 1, shortened: true, blocks: [{ type: 'text', text: 'head' }] } | ||
| // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: Only client identity is used; this fixture performs no RPC. | ||
| const first = {} as RpcClient | ||
| // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: Only client identity is used; this fixture performs no RPC. | ||
| const second = {} as RpcClient | ||
| let renderer: ReactTestRenderer | undefined | ||
| afterEach(() => { act(() => renderer?.unmount()) }) | ||
| function Probe() { return useMobileNativeChatFullMessage(message).showFull } | ||
|
|
||
| it.each(['client', 'session'] as const)('keeps a pending or failed request with its original %s owner', async (changed) => { | ||
| const pending = Promise.withResolvers<void>() | ||
| const oldLoad = vi.fn(() => pending.promise) | ||
| const newLoad = vi.fn(async () => {}) | ||
| const source = (client: RpcClient, sessionId: string, load: () => Promise<void>) => ({ | ||
| client, sessionId, messageDetail: { raw: () => message, state: () => 'available' as const, load } | ||
| }) | ||
| const render = (value: ReturnType<typeof source>) => createElement(MobileNativeChatItemSourceContext.Provider, { value }, createElement(Probe)) | ||
| await act(async () => { renderer = create(render(source(first, 'session', oldLoad))) }) | ||
| const button = () => renderer?.root.findByProps({ accessibilityRole: 'button' }) | ||
| await act(async () => { button()?.props.onPress() }) | ||
| expect(button()?.props.disabled).toBe(true) | ||
| await act(async () => { renderer?.update(render(source(changed === 'client' ? second : first, changed === 'session' ? 'other' : 'session', newLoad))) }) | ||
| expect(button()?.props.disabled).toBe(false) | ||
| await act(async () => { pending.reject(new Error('old host failed')); await pending.promise.catch(() => {}) }) | ||
| expect(JSON.stringify(renderer?.toJSON())).not.toContain("couldn't load") | ||
| await act(async () => { button()?.props.onPress() }) | ||
| expect(newLoad).toHaveBeenCalledOnce() | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { useContext, useEffect, useState } from 'react' | ||
| import { Pressable, Text, View } from 'react-native' | ||
| import { | ||
| truncateToolDetail, | ||
| MAX_TOOL_DETAIL_LENGTH | ||
| } from '../../../src/shared/native-chat-tool-summary' | ||
| import type { NativeChatMessage, NativeChatToolResultBlock } from '../../../src/shared/native-chat-types' | ||
| import type { AgentJournalBoundedPayload, AgentJournalItemBody } from '../../../src/shared/agent-session-journal-types' | ||
| import { styles } from './mobile-native-chat-message-styles' | ||
| import { | ||
| MobileNativeChatItemSourceContext, | ||
| readMobileNativeChatItem | ||
| } from './mobile-native-chat-item-read' | ||
|
|
||
| // "Show full output" and "Show full message": a row the phone was sent a head of, read whole from | ||
| // the host that keeps it. State is the row's own, so a live revision never fights it. | ||
|
|
||
| type Load = 'idle' | 'loading' | 'failed' | ||
|
|
||
| function ShowFull({ | ||
| label, | ||
| load, | ||
| onPress | ||
| }: { | ||
| label: string | ||
| load: Load | ||
| onPress: () => void | ||
| }): React.JSX.Element { | ||
| return ( | ||
| <Pressable | ||
| style={styles.showFull} | ||
| onPress={onPress} | ||
| disabled={load === 'loading'} | ||
| hitSlop={8} | ||
| accessibilityRole="button" | ||
| > | ||
| <Text style={styles.showFullText}> | ||
| {load === 'failed' ? `${label} — couldn't load, tap to retry` : label} | ||
| </Text> | ||
| </Pressable> | ||
| ) | ||
| } | ||
|
|
||
| function outputOf(body: AgentJournalItemBody | null): AgentJournalBoundedPayload | null { | ||
| if (body?.kind === 'tool-call') { | ||
| return body.output ?? null | ||
| } | ||
| return body?.kind === 'diff' ? body.patch : null | ||
| } | ||
|
|
||
| /** A tool's output in an opened line: its head, and the whole of it on request. */ | ||
| export function MobileNativeChatToolOutput({ | ||
| body | ||
| }: { | ||
| body: NativeChatToolResultBlock | ||
| }): React.JSX.Element { | ||
| const source = useContext(MobileNativeChatItemSourceContext) | ||
| const { output, isError, fullOutputItemId } = body | ||
| const client = source?.client, sessionId = source?.sessionId | ||
| const [expanded, setExpanded] = useState(false) | ||
| const [detail, setDetail] = useState<{ | ||
| body: typeof body; client: typeof client; sessionId: typeof sessionId; | ||
| full?: AgentJournalBoundedPayload; load: Load | ||
| } | null>(null) | ||
| useEffect(() => () => setDetail((held) => held?.body === body && held.client === client && held.sessionId === sessionId ? null : held), [body, client, sessionId]) | ||
| const current = detail?.body === body && detail.client === client && detail.sessionId === sessionId ? detail : null | ||
| const full = current?.full | ||
| const clipped = !full && (fullOutputItemId !== undefined || (!expanded && output.length > MAX_TOOL_DETAIL_LENGTH)) | ||
| const showFull = (): void => { | ||
| if (fullOutputItemId === undefined || source === null) { | ||
| setExpanded(true) | ||
| return | ||
| } | ||
| setDetail({ body, client, sessionId, load: 'loading' }) | ||
| const finish = (full?: AgentJournalBoundedPayload): void => { | ||
| setDetail((held) => held?.body === body && held.client === client && held.sessionId === sessionId ? { body, client, sessionId, full, load: full ? 'idle' : 'failed' } : held) | ||
| } | ||
| readMobileNativeChatItem(source, fullOutputItemId) | ||
| .then((item) => finish(item?.itemId === fullOutputItemId ? outputOf(item.body) ?? undefined : undefined)) | ||
| .catch(() => finish()) | ||
| } | ||
| return ( | ||
| <View> | ||
| <View style={[styles.toolResult, isError && styles.toolResultError]}> | ||
| <Text style={styles.mono}>{full ? full.head : expanded ? output : truncateToolDetail(output)}</Text> | ||
| </View> | ||
| {full?.truncated ? <Text style={styles.showFullText}>Showing {new TextEncoder().encode(full.head).length} of {full.byteLength} bytes.</Text> : null} | ||
| {clipped ? <ShowFull label="Show full output" load={current?.load ?? 'idle'} onPress={showFull} /> : null} | ||
| </View> | ||
| ) | ||
| } | ||
|
|
||
| /** `message` as drawn: whole once the reader asked for a reply the phone was sent shortened. */ | ||
| export function useMobileNativeChatFullMessage(message: NativeChatMessage): { | ||
| shown: NativeChatMessage | ||
| showFull: React.JSX.Element | null | ||
| } { | ||
| const source = useContext(MobileNativeChatItemSourceContext) | ||
| const detail = source?.messageDetail | ||
| const client = source?.client, sessionId = source?.sessionId | ||
| const raw = detail?.raw(message.id) | ||
| const [request, setRequest] = useState<{ raw: typeof raw; client: typeof client; sessionId: typeof sessionId; load: Load } | null>(null) | ||
| const load = request?.raw === raw && request?.client === client && request?.sessionId === sessionId ? request?.load ?? 'idle' : 'idle' | ||
| const state = detail?.state(message.id) | ||
| const showFull = (): void => { | ||
| setRequest({ raw, client, sessionId, load: 'loading' }) | ||
| const finish = (load: Load): void => setRequest((held) => held?.raw === raw && held?.client === client && held?.sessionId === sessionId ? { raw, client, sessionId, load } : held) | ||
| void detail?.load(message.id).then(() => finish('idle')).catch(() => finish('failed')) | ||
| } | ||
| return { | ||
| shown: message, | ||
| showFull: state === 'partial' ? <Text style={styles.showFullText}>Showing part of this message.</Text> | ||
| : state === 'available' ? <ShowFull label="Show full message" load={load} onPress={showFull} /> : null | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.