Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
439cf2c
Keep failed sends visible in conversation on unary RPC transport errors
Fei2411 Dec 4, 2026
2977d47
Harden failed-send reconciliation, retry locking, and RPC delivery cl…
Fei2411 Dec 4, 2026
31173b5
Merge remote-tracking branch 'origin/dev' into fix/2299-rework-r2
Fei2411 Dec 4, 2026
e7210f1
Fix group rpcId receipts, legacy replay dedup, queue durability, send…
Fei2411 Dec 4, 2026
92d7ea6
Require durable requestId receipts, retry failed-send lazy chunk, and…
Fei2411 Dec 4, 2026
07d3b4f
Merge remote-tracking branch 'origin/dev' into fix/2299-rework-r2
Fei2411 Dec 4, 2026
5bbf720
Persist group ledger before inbox dequeue, unify ledger durability ev…
Fei2411 Dec 4, 2026
609fc66
Merge remote-tracking branch 'origin/dev' into fix/2299-rework-r5
Fei2411 Dec 5, 2026
e4a33f7
Hand off group inbox-to-ledger ownership atomically across DSH turns …
Fei2411 Dec 5, 2026
b45c381
Harden group inbox handover, pending dispatch recovery, and pre-step …
Fei2411 Dec 5, 2026
4e5832a
Merge origin/dev into fix/2299-rework-r5 and regenerate contracts
Fei2411 Dec 5, 2026
8006526
Merge remote-tracking branch 'origin/dev' into fix/2299-rework-r5
Fei2411 Dec 5, 2026
ec53081
Deduplicate ledger group dispatches on member receipt and persist sto…
Fei2411 Dec 5, 2026
d3de5df
Enforce cancellation and fail-closed receipt verification at group le…
Fei2411 Dec 5, 2026
ff2d62b
Harden parked room ledger wake recheck and add backoff retry for unre…
Fei2411 Dec 5, 2026
912e502
Release room ledger recovery claim and retry after opening round failure
Fei2411 Dec 5, 2026
89b74c3
Require persisted member receipt before marking group ledger dispatched
Fei2411 Dec 5, 2026
75d7ad0
Require persisted native user/message before room supersede or member…
Fei2411 Dec 5, 2026
8138b46
Share ledger dispatch identity and persist stop across provisional ro…
Fei2411 Dec 5, 2026
0736a27
fix(ds-bot): decouple room supersede from member dispatch and bind pe…
Fei2411 Dec 5, 2026
91e14da
fix(ds-bot): hand off orphaned roomInbox posts on native turn exit an…
Fei2411 Dec 5, 2026
db37d00
fix(ds-bot): guarantee ledger prompt text, persist before roomInbox d…
Fei2411 Dec 5, 2026
5f9b1bc
fix(ds-bot): reconstruct failed ledger handovers per session, persist…
Fei2411 Dec 5, 2026
5db17ab
fix(groups): reconstruct rolled-back native turns from persisted even…
Fei2411 Dec 5, 2026
57d3603
fix(groups): handle unstarted/unknown relay crashes with identity ded…
Fei2411 Dec 5, 2026
41bc542
fix(groups): recover unfinished async group_relay rounds per member a…
Fei2411 Dec 5, 2026
9d7c403
fix(groups): bind round ownership to exact anchors/identities and res…
Fei2411 Dec 5, 2026
87d9570
fix(groups): enforce per-message userIdentities over shared relay anchor
Fei2411 Dec 5, 2026
30951cc
fix(groups): preserve persisted session-reference snapshots across ro…
Fei2411 Dec 5, 2026
ba19e94
fix(groups): isolate reference rounds bidirectionally and resolve eve…
Fei2411 Dec 5, 2026
a01e1cb
fix(groups): enforce unified reference-round isolation across drainRo…
Fei2411 Dec 5, 2026
ca440f2
fix(groups): hand over orphaned laterPosts user entries when ledger r…
Fei2411 Dec 5, 2026
8586269
fix(groups): bind reconstructed laterPosts user entries in-place to p…
Fei2411 Dec 5, 2026
1d5d037
fix(groups): preserve bound laterPosts FIFO across consecutive openin…
Fei2411 Dec 5, 2026
9a31eb0
fix(groups): hold FIFO behind unready head and cancel in-flight Bot c…
Fei2411 Dec 5, 2026
8be78b9
fix(groups): hold partial head FIFO, abort opening before call creati…
Fei2411 Dec 5, 2026
85d9ab9
fix(groups): enforce pending-head barrier, drain bot-only suffix, and…
Fei2411 Dec 5, 2026
7c1652c
fix(ds-bot): enforce pending-head FIFO on postToRoom/holdForNextRound…
Fei2411 Dec 5, 2026
d742f7b
fix(ds-bot): guard partial in-flight heads, keep completed room claim…
Fei2411 Dec 5, 2026
d6dc092
fix(ds-bot): tighten room handoff admission, cold FIFO recovery, and …
Fei2411 Dec 6, 2026
2006932
fix(ds-bot): preserve in-flight and cold-rebuild room FIFO barriers a…
Fei2411 Dec 6, 2026
3d49a4c
fix(ds-bot): guard concurrent unpersisted rebuilds and abort mixed st…
Fei2411 Dec 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Require durable requestId receipts, retry failed-send lazy chunk, and…
… preserve Classic trace state
  • Loading branch information
Fei2411 committed Dec 4, 2026
commit 92d7ea6940233f9c955c74ec37e0fe29e454f2c0
248 changes: 232 additions & 16 deletions app/test/failed-send-recovery.test.mjs

Large diffs are not rendered by default.

268 changes: 268 additions & 0 deletions app/test/lazy-boundaries-and-styles.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,271 @@ test('createRetryableLazy.preload renders synchronously on first mount, deduplic
container.remove()
}
})

test('PR #3128 R3 P2-1: failed-send-bar-lazy reloads chunk after initial import failure on ChatErrorBoundary Retry and direct remount', async () => {
const React = await import('react')
const { createRoot } = await import('react-dom/client')
const { installMiniDom } = await import('./mini-dom.mjs')
installMiniDom()
globalThis.IS_REACT_ACT_ENVIRONMENT = true

// Bundle the real failed-send-bar-lazy.js + ChatErrorBoundary with an injectable dynamic import hook
// so we can deterministically fail the first chunk load and succeed on retry/remount.
const { outputFiles } = await build({
stdin: {
contents: `
export { FailedSendBar } from './ui/src/lazy-client/failed-send-bar-lazy.js'
export { ChatErrorBoundary } from './ui/src/error-boundary.js'
`,
resolveDir: appDir,
loader: 'js',
},
bundle: true,
format: 'cjs',
platform: 'browser',
write: false,
logLevel: 'silent',
external: ['react', 'react-dom'],
plugins: [{
name: 'inject-failed-send-bar-import',
setup(bundler) {
bundler.onResolve({ filter: /ds-bot\/src\/client\/error-boundary\.js$/ }, () => ({
path: 'error-boundary-stub',
namespace: 'stub',
}))
bundler.onLoad({ filter: /^error-boundary-stub$/, namespace: 'stub' }, () => ({
contents: 'export const renderCardErrorFallback = () => null',
loader: 'js',
}))
bundler.onLoad({ filter: /failed-send-bar-lazy\.js$/ }, (args) => {
const src = readFileSync(args.path, 'utf8')
const patched = src.replace(
"() => import('../failed-send-bar.js')",
'() => globalThis.__TEST_LOAD_FAILED_SEND_BAR__()',
)
assert.notEqual(patched, src, 'expected dynamic import in failed-send-bar-lazy.js')
return { contents: patched, loader: 'js' }
})
},
}],
})

let loadCalls = 0
let shouldFail = true
let retriedEntries = []
const RealFailedSendBar = ({ items, onRetry }) => React.createElement(
'div',
{ className: 'dsb-failed-bar', 'data-failed-sends': '' },
items.map(item => React.createElement(
'button',
{ key: item.id, type: 'button', className: 'dsb-failed-retry', onClick: () => onRetry?.(item) },
`Retry ${item.text}`,
)),
)
globalThis.__TEST_LOAD_FAILED_SEND_BAR__ = () => {
loadCalls += 1
if (shouldFail) return Promise.reject(new Error(`chunk load failed #${loadCalls}`))
return Promise.resolve({ FailedSendBar: RealFailedSendBar })
}

const modExports = {}
const mod = { exports: modExports }
new Function('require', 'module', 'exports', outputFiles[0].text)(
(id) => {
if (id === 'react') return React
throw new Error(`Unexpected require: ${id}`)
},
mod,
modExports,
)
const { FailedSendBar, ChatErrorBoundary } = mod.exports

const container = document.createElement('div')
document.body.appendChild(container)
const root = createRoot(container)
const origErr = console.error
console.error = () => {}
try {
const failedItem = { id: 'f1', text: 'unsent msg', items: [], phase: 'delivered-unknown' }
const ComposerShell = () => React.createElement(
'div',
{ className: 'composer-shell' },
React.createElement(FailedSendBar, { items: [failedItem], onRetry: item => retriedEntries.push(item.id) }),
React.createElement('textarea', { className: 'composer-input', defaultValue: 'draft' }),
)

// 1. First mount fails chunk load -> ChatErrorBoundary catches and shows Retry button.
await React.act(async () => {
root.render(React.createElement(ChatErrorBoundary, { name: 'composer', variant: 'compact' }, React.createElement(ComposerShell)))
await new Promise(r => setTimeout(r, 20))
})
assert.equal(loadCalls, 1)
assert.equal(container.querySelector('.composer-input'), null, 'boundary should show fallback while failed')
const retryBtn = container.querySelector('button')
assert.ok(retryBtn && /Retry/i.test(retryBtn.textContent), 'ChatErrorBoundary should offer Retry')

// 2. Chunk becomes available -> click Retry on ChatErrorBoundary -> remounts, reloads chunk, restores input & FailedSendBar!
shouldFail = false
await React.act(async () => {
clickEl(retryBtn)
await new Promise(r => setTimeout(r, 20))
})
assert.equal(loadCalls, 2, 'ErrorBoundary Retry must re-invoke chunk loader')
assert.ok(container.querySelector('.composer-input'), 'composer input must be restored after Retry')
const failedRetryBtn = container.querySelector('.dsb-failed-retry')
assert.ok(failedRetryBtn, 'FailedSendBar must render after Retry succeeds')
await React.act(async () => { clickEl(failedRetryBtn) })
assert.deepEqual(retriedEntries, ['f1'], 'FailedSendBar Retry action must remain functional')

// 3. Also verify direct unmount + remount without ErrorBoundary.onRetry reloads after failure.
FailedSendBar.reset()
shouldFail = true
const callsBeforeDirect = loadCalls
await React.act(async () => {
root.render(React.createElement(ChatErrorBoundary, { name: 'direct', variant: 'compact' },
React.createElement(FailedSendBar, { items: [failedItem] })))
await new Promise(r => setTimeout(r, 20))
})
assert.equal(loadCalls, callsBeforeDirect + 1)
await React.act(async () => { root.render(null) })
shouldFail = false
await React.act(async () => {
root.render(React.createElement(FailedSendBar, { items: [failedItem] }))
await new Promise(r => setTimeout(r, 20))
})
assert.equal(loadCalls, callsBeforeDirect + 2, 'direct remount after failure must reload chunk')
assert.ok(container.querySelector('.dsb-failed-bar'))
} finally {
console.error = origErr
delete globalThis.__TEST_LOAD_FAILED_SEND_BAR__
await React.act(async () => { root.unmount() })
container.remove()
}
})

test('PR #3128 R3 P2-2: classic-lazy ClassicPromptTrace keeps mounted after first open and preserves Older steps pagination & step selection across tab switches', async () => {
const React = await import('react')
const { createRoot } = await import('react-dom/client')
const { installMiniDom } = await import('./mini-dom.mjs')
installMiniDom()
globalThis.IS_REACT_ACT_ENVIRONMENT = true

const traceRequests = []
const origFetch = globalThis.fetch
globalThis.fetch = async (url, init) => {
const body = JSON.parse(init.body)
if (body.endpoint === 'session-trace') {
traceRequests.push(body.payload)
const beforeSeq = body.payload.beforeSeq
if (beforeSeq === 10) {
const chosen = body.payload.turn === 1 && body.payload.step === 1
? { turn: 1, step: 1 }
: { turn: 1, step: 2 }
return {
ok: true,
status: 200,
json: async () => ({
ok: true,
value: {
sessionId: 'classic-s1',
steps: [{ turn: 1, step: 1 }, { turn: 1, step: 2 }],
nextBeforeSeq: null,
selected: chosen,
prompt: { header: null, system: null, messages: [{ id: `m-${chosen.turn}-${chosen.step}`, role: 'user', content: [{ type: 'text', text: `older page turn ${chosen.turn} step ${chosen.step}` }] }], omitted: { header: false, system: false, messages: 0 } },
},
}),
}
}
return {
ok: true,
status: 200,
json: async () => ({
ok: true,
value: {
sessionId: 'classic-s1',
steps: [{ turn: 2, step: 1 }],
nextBeforeSeq: 10,
selected: { turn: 2, step: 1 },
prompt: { header: null, system: null, messages: [{ id: 'm-2-1', role: 'user', content: [{ type: 'text', text: 'latest page turn 2 step 1' }] }], omitted: { header: false, system: false, messages: 0 } },
},
}),
}
}
return { ok: true, status: 200, json: async () => ({ ok: true, value: {} }) }
}

const { ClassicPromptTrace } = await import('../ui/src/lazy-client/classic-lazy.js')
const container = document.createElement('div')
document.body.appendChild(container)
const root = createRoot(container)
const data = {
cursor: { subscribe: () => () => {}, getSnapshot: () => 20 },
}
const panelProps = { id: 'panel-trace', role: 'tabpanel' }

try {
// 1. Initially inactive -> returns null without fetching.
await React.act(async () => {
root.render(React.createElement(ClassicPromptTrace, { sessionId: 'classic-s1', data, active: false, panelProps }))
await new Promise(r => setTimeout(r, 20))
})
assert.equal(traceRequests.length, 0)
assert.equal(container.querySelector('.dsb-classic-trace'), null)

// 2. Open Prompt trace -> loads latest page (turn 2 step 1) with Older steps button.
await React.act(async () => {
root.render(React.createElement(ClassicPromptTrace, { sessionId: 'classic-s1', data, active: true, panelProps }))
await new Promise(r => setTimeout(r, 30))
})
assert.equal(traceRequests.length, 1)
assert.equal(traceRequests[0].beforeSeq, undefined)
assert.match(container.textContent, /latest page turn 2 step 1/)

// 3. Click "Older steps" -> loads page beforeSeq=10, then select Turn 1 · Step 1.
const olderBtn = Array.from(container.querySelectorAll('button')).find(b => b.textContent === 'Older steps')
assert.ok(olderBtn, 'Older steps button must be present')
await React.act(async () => {
clickEl(olderBtn)
await new Promise(r => setTimeout(r, 30))
})
assert.equal(traceRequests.at(-1).beforeSeq, 10)
assert.match(container.textContent, /older page turn 1 step 2/)

const stepSelect = container.querySelector('select')
assert.ok(stepSelect, 'Model step selector must be present')
await React.act(async () => {
stepSelect.value = '1:1'
stepSelect.dispatchEvent({ type: 'change', bubbles: true, target: stepSelect, currentTarget: stepSelect })
await new Promise(r => setTimeout(r, 30))
})
assert.equal(traceRequests.at(-1).beforeSeq, 10)
assert.equal(traceRequests.at(-1).turn, 1)
assert.equal(traceRequests.at(-1).step, 1)
assert.match(container.textContent, /older page turn 1 step 1/)

// 4. Switch back to Conversation (active: false) -> panel stays mounted (hidden), no reset!
await React.act(async () => {
root.render(React.createElement(ClassicPromptTrace, { sessionId: 'classic-s1', data, active: false, panelProps }))
await new Promise(r => setTimeout(r, 20))
})
const sectionHidden = container.querySelector('.dsb-classic-trace')
assert.ok(sectionHidden, 'ClassicPromptTrace must remain mounted when deactivated')
assert.equal(sectionHidden.hidden, true)

// 5. Switch back to Prompt trace (active: true) -> MUST preserve beforeSeq=10 and step 1:1 (NOT reset to latest page)!
const countBeforeReopen = traceRequests.length
await React.act(async () => {
root.render(React.createElement(ClassicPromptTrace, { sessionId: 'classic-s1', data, active: true, panelProps }))
await new Promise(r => setTimeout(r, 30))
})
assert.ok(traceRequests.length > countBeforeReopen)
assert.equal(traceRequests.at(-1).beforeSeq, 10, 'reopening Prompt trace must keep Older steps beforeSeq')
assert.equal(traceRequests.at(-1).turn, 1, 'reopening Prompt trace must keep selected turn')
assert.equal(traceRequests.at(-1).step, 1, 'reopening Prompt trace must keep selected step')
assert.match(container.textContent, /older page turn 1 step 1/)
} finally {
globalThis.fetch = origFetch
await React.act(async () => { root.unmount() })
container.remove()
}
})
1 change: 1 addition & 0 deletions app/test/mini-dom.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ class ElementMini extends NodeMini {
set src(value) { this.setAttribute('src', value) }
get title() { return this._attrs.get('title') ?? '' }
set title(value) { this.setAttribute('title', value) }
get options() { return this.localName === 'select' ? this.querySelectorAll('option') : undefined }
get tabIndex() {
if (this._attrs.has('tabindex')) {
const parsed = Number.parseInt(this._attrs.get('tabindex'), 10)
Expand Down
15 changes: 12 additions & 3 deletions app/ui/src/chat-transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ function useRoomChat(roomId, part, feed, keep, onUserMatch) {
const gen = useRef(0)
const hasLoaded = useRef(false)
const knownUserIds = useRef(new Set())
const knownDurableUserIds = useRef(new Set())
const onUserMatchRef = useRef(onUserMatch)
onUserMatchRef.current = onUserMatch

Expand Down Expand Up @@ -375,14 +376,21 @@ function useRoomChat(roomId, part, feed, keep, onUserMatch) {
for (const item of pageItems) {
if (item.kind !== 'user') continue
const key = userItemKey(item)
if (knownUserIds.current.has(key)) continue
const alreadySeen = knownUserIds.current.has(key)
const newlyDurable = item.durable === true && !knownDurableUserIds.current.has(key)
if (alreadySeen && !newlyDurable) continue
knownUserIds.current.add(key)
freshUsers.push(item)
if (item.durable === true) knownDurableUserIds.current.add(key)
freshUsers.push(alreadySeen ? { ...item, pendingAlreadyCleared: true } : item)
}
if (freshUsers.length > 0) onUserMatchRef.current?.(freshUsers, initial)
} else {
for (const item of pageItems) {
if (item.kind === 'user') knownUserIds.current.add(userItemKey(item))
if (item.kind === 'user') {
const key = userItemKey(item)
knownUserIds.current.add(key)
if (item.durable === true) knownDurableUserIds.current.add(key)
}
}
// Content added above the viewport would push the view down; keep its distance from the end.
if (scroller) keep.current = scroller.scrollHeight - scroller.scrollTop
Expand Down Expand Up @@ -427,6 +435,7 @@ function useRoomChat(roomId, part, feed, keep, onUserMatch) {
ready.current = Boolean(cached)
hasLoaded.current = false
knownUserIds.current.clear()
knownDurableUserIds.current.clear()
if (cached) {
setView(cached.view)
void loadRef.current(undefined, undefined, true, { incremental: false })
Expand Down
25 changes: 23 additions & 2 deletions app/ui/src/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,17 @@ export function Chat({ sessionId, team, registry, classic = false, onViewingSuba

const clearPendingUsers = useCallback((freshUsers, initial) => {
if (activeChatKeyRef.current) {
const durableUsers = Array.isArray(freshUsers) ? freshUsers.filter(item => item && item.fromQueue !== true) : []
if (durableUsers.length > 0) reconcileFailedSends(activeChatKeyRef.current, durableUsers, initial)
const durableUsers = Array.isArray(freshUsers)
? freshUsers.filter(item => item && item.fromQueue !== true && item.durable === true)
: []
if (durableUsers.length > 0) reconcileFailedSends(activeChatKeyRef.current, durableUsers)
}
setPending((list) => {
if (list.length === 0) return list
const next = list.slice()
const removed = []
for (const item of freshUsers) {
if (item?.pendingAlreadyCleared === true) continue
const itemRequestId = typeof item?.requestId === 'string' && item.requestId.trim() !== ''
? item.requestId.trim()
: (typeof item?.source?.rpcId === 'string' && item.source.rpcId.trim() !== '' ? item.source.rpcId.trim() : '')
Expand Down Expand Up @@ -417,6 +420,8 @@ export function Chat({ sessionId, team, registry, classic = false, onViewingSuba
...(summary?.sessionId ? { sessionId: summary.sessionId } : {}),
...(Number.isSafeInteger(summary?.seq) ? { seq: summary.seq } : {}),
...(summary?.requestId ? { requestId: summary.requestId } : {}),
...(summary?.durable === true ? { durable: true } : {}),
...(summary?.pendingAlreadyCleared === true ? { pendingAlreadyCleared: true } : {}),
}], initial)
}, [clearPendingUsers])

Expand Down Expand Up @@ -730,6 +735,22 @@ export function Chat({ sessionId, team, registry, classic = false, onViewingSuba
const activeChatId = hooks.useRoster(r => chatOfSession(r, composerSessionId)?.id ?? null)
const activeChatKey = activeChatId ?? composerSessionId
activeChatKeyRef.current = activeChatKey

useEffect(() => {
if (!feed || typeof feed.on !== 'function') return undefined
return feed.on((event, data) => {
if (event !== 'send-confirmed' || typeof data?.requestId !== 'string' || data.requestId.trim() === '') return
const reqId = data.requestId.trim()
const keys = new Set()
if (typeof data.chatId === 'string' && data.chatId !== '') keys.add(data.chatId)
if (typeof data.sessionId === 'string' && data.sessionId !== '') keys.add(data.sessionId)
if (activeChatKeyRef.current && (keys.has(activeChatKeyRef.current) || keys.has(composerSessionId) || keys.has(activeSessionId))) {
keys.add(activeChatKeyRef.current)
}
const receipt = [{ requestId: reqId, durable: true }]
for (const key of keys) reconcileFailedSends(key, receipt)
})
}, [feed, activeSessionId, composerSessionId])
const onWithdraw = useCallback(
text => withdrawQueuedText({ chatId: activeChatId, chatKey: activeChatKey, sessionId: composerSessionId, text }),
[activeChatId, activeChatKey, composerSessionId],
Expand Down
4 changes: 3 additions & 1 deletion app/ui/src/lazy-client/classic-lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export function ClassicSessionBar(props) {
return h(Suspense, { fallback: null }, h(LazyClassicSessionBar, props))
}
export function ClassicPromptTrace(props) {
if (!props?.active) return null
const everOpenedRef = useRef(false)
if (props?.active) everOpenedRef.current = true
if (!everOpenedRef.current) return null
return h(Suspense, { fallback: null }, h(LazyClassicPromptTrace, props))
}
export function ClassicStatsFooter(props) {
Expand Down
Loading
Loading