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
fix(groups): enforce pending-head barrier, drain bot-only suffix, and…
… cancel inbox user sends on stop
  • Loading branch information
Fei2411 committed Dec 5, 2026
commit 85d9ab92a62160cceea40b5d5eb881d96361f464
123 changes: 120 additions & 3 deletions ds-bot/src/host/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -2449,7 +2449,25 @@ export function install(rt) {
}
return created
}
const findRoomLedgerRpc = (roomId, rpcId) => findRoomLedgerHandover(roomId, { rpcId })
const findRoomLedgerRpc = (roomId, rpcId) => {
const handover = findRoomLedgerHandover(roomId, { rpcId })
if (handover.persisted === true) return handover
const trimmedRpcId = typeof rpcId === 'string' ? rpcId.trim() : ''
if (typeof roomId === 'string' && roomId !== '' && trimmedRpcId !== '') {
const book = bookOf(roomId)
if (typeof rt.ledger?.hasBook !== 'function' || rt.ledger.hasBook(book)) {
const records = rt.ledger?.records?.(book) ?? []
for (let i = records.length - 1; i >= 0; i -= 1) {
const rec = records[i]
if (rec?.event !== 'dispatched' || rec.all !== true || rec.cancelled !== true) continue
if (typeof rec.rpcId !== 'string' || rec.rpcId.trim() !== trimmedRpcId) continue
const persisted = typeof rt.ledger.isPersisted === 'function' ? rt.ledger.isPersisted(book, rec) === true : true
if (persisted) return { found: true, persisted: true, cancelled: true, record: rec }
}
}
}
return handover
}
const roomLedgerGen = roomId => (
typeof roomId === 'string' && roomId !== ''
? (rt.ledger?.persistedGen?.(bookOf(roomId)) ?? 0) + (sessionClaimedGen.get(roomId) ?? 0)
Expand All @@ -2468,7 +2486,7 @@ export function install(rt) {
? message.source.rpcId.trim()
: undefined
if (inboxId === undefined && rpcId === undefined) continue
if (findRoomLedgerHandover(room.id, { inboxId, rpcId }).persisted !== true) continue
if (findRoomLedgerHandover(room.id, { inboxId, rpcId }).persisted !== true && !isRoomIdentityCancelled(room, { inboxId, rpcId })) continue
if (agent.inbox.remove(message.id) === true) removed += 1
}
}
Expand Down Expand Up @@ -6322,6 +6340,43 @@ export function install(rt) {
// A post whose line landed after its round closed waits here for the next round, which
// opens right away when nothing else is running. The line is already on the book, so the
// post carries `logged` and the relay says it without numbering it again.
const hasBlockingPendingLedgerHead = (room, incomingPosts = []) => {
if (room === undefined || disposed || rt.deletingRooms?.has(room.id) || rt.readOnly?.() !== undefined) return false
const incomingSeqs = new Set()
const incomingKeys = new Set()
for (const post of incomingPosts) {
if (Number.isInteger(post?.ledgerDispatchSeq)) incomingSeqs.add(post.ledgerDispatchSeq)
if (Number.isInteger(post?.logged)) incomingSeqs.add(post.logged)
if (post?.botId === undefined && post?.kickoff !== true) {
for (const k of roomIdentityKeysOf({ inboxId: post?.messageId, rpcId: post?.rpcId })) incomingKeys.add(k)
}
}
const pending = pendingRoomLedgerDispatches(room)
if (pending.some((item) => {
const rec = item.record
if (incomingSeqs.has(rec.seq)) return false
const recKeys = roomIdentityKeysOf({ inboxId: rec.messageId, rpcId: rec.rpcId })
if (recKeys.some(k => incomingKeys.has(k))) return false
return true
})) return true
if (pendingColdRoomReconstructions.has(room.id)) {
if ((laterPosts.get(room.id)?.length ?? 0) > 0) return true
const liveSession = liveSessionOf(rt.sessionOfRoom(room))
const events = typeof liveSession?.snapshotEvents === 'function' ? liveSession.snapshotEvents() : undefined
if (Array.isArray(events) && events.length > 0) {
const unhandled = collectUnhandledNativeRoomTurns(events, { includeOpenTurn: false, includeAsyncRelayed: true })
for (const turn of unhandled) {
const keys = roomIdentityKeysOf({ inboxId: turn.inboxId, rpcId: turn.rpcId })
if (keys.length === 0) continue
if (keys.some(k => incomingKeys.has(k))) continue
if (isRoomIdentityCancelled(room, { inboxId: turn.inboxId, rpcId: turn.rpcId })) continue
return true
}
}
}
return false
}

const holdForNextRound = async (room, posts) => {
const gen = roomStopGen.get(room.id) ?? 0
const stamped = posts.map(post => (post && typeof post === 'object' && !Number.isInteger(post.stopGen) ? { ...post, stopGen: gen } : post))
Expand Down Expand Up @@ -6549,6 +6604,11 @@ export function install(rt) {
laterPosts.set(room.id, [...(laterPosts.get(room.id) ?? []), ...posts])
return
}
if (hasBlockingPendingLedgerHead(room, posts)) {
laterPosts.set(room.id, [...(laterPosts.get(room.id) ?? []), ...posts])
schedulePendingRoomLedgerRetry(room.id)
return
}
const left = laterPosts.get(room.id) ?? []
laterPosts.delete(room.id)
startRound(room, [...left, ...posts], resolvedAgent)
Expand Down Expand Up @@ -6813,6 +6873,10 @@ export function install(rt) {
if (roomHealthy) {
const remainingLater = laterPosts.get(room.id) ?? []
if (!openingFailed && remainingLater.length > 0 && runningRound(room.id) === undefined && !finalizing.has(room.id)) {
if (hasBlockingPendingLedgerHead(room, remainingLater)) {
schedulePendingRoomLedgerRetry(room.id)
return
}
laterPosts.delete(room.id)
startRound(room, remainingLater, agent)
return
Expand Down Expand Up @@ -7368,7 +7432,10 @@ export function install(rt) {
const running = runningRound(room.id)
if (running !== undefined) await joinRound(room, running, queued, exec.agent)
else if (finalizing.has(room.id)) laterPosts.set(room.id, [...(laterPosts.get(room.id) ?? []), ...queued])
else {
else if (hasBlockingPendingLedgerHead(room, queued)) {
laterPosts.set(room.id, [...(laterPosts.get(room.id) ?? []), ...queued])
schedulePendingRoomLedgerRetry(room.id)
} else {
const left = laterPosts.get(room.id) ?? []
laterPosts.delete(room.id)
startRound(room, [...left, ...queued], exec.agent, exec.callId, anchor)
Expand Down Expand Up @@ -8789,6 +8856,22 @@ export function install(rt) {
for (const byRoom of inflightDequeuedPosts.values()) {
for (const post of byRoom.get(room.id) ?? []) collectUserPostCancel(post)
}
const liveRoomAgent = ctx.get?.('agents')?.get?.(rt.sessionOfRoom(room))
if (liveRoomAgent?.inbox !== undefined) {
for (const laneName of ['nextStep', 'nextTurn']) {
for (const message of Array.from(liveRoomAgent.inbox[laneName] ?? [])) {
if (message?.source?.kind !== 'user') continue
const inboxId = typeof message.id === 'string' && message.id !== '' ? message.id : undefined
const rpcId = typeof message.source?.rpcId === 'string' && message.source.rpcId.trim() !== ''
? message.source.rpcId.trim()
: undefined
if (inboxId === undefined && rpcId === undefined) continue
const matchedSeq = findMatchingRoomLedgerDispatchRecord(room.id, { inboxId, rpcId })?.seq
if (Number.isInteger(matchedSeq)) collectSeq(matchedSeq, { inboxId, rpcId })
else collectIdentityCancel({ inboxId, rpcId })
}
}
}
// Also cancel any live room-session user turn whose original ledger append rolled back
// (no ledger row in `records` and no `tool/call` / `assistant/message` yet), so `stop-room-work`
// before live or cold reconstruction commits cannot be undone on subsequent recovery.
Expand Down Expand Up @@ -8853,6 +8936,9 @@ export function install(rt) {
if (kept.length > 0) rt.roomInbox.set(room.id, kept)
else rt.roomInbox.delete(room.id)
}
if (cancelled > 0 && liveRoomAgent !== undefined) {
pruneCommittedRoomInbox(room, liveRoomAgent)
}
return cancelled
}

Expand Down Expand Up @@ -9163,13 +9249,42 @@ export function install(rt) {
clearPendingRoomLedgerRetry(room.id)
return 0
}
const drainIdleLaterPostsIfUnblocked = () => {
if (
runningRound(room.id) !== undefined
|| finalizing.has(room.id)
|| inFlightRecoveredDispatches.has(room.id)
|| hasPendingRoomLedgerWork(room)
) return 0
const idleLater = laterPosts.get(room.id)
if (!Array.isArray(idleLater) || idleLater.length === 0) return 0
const liveLater = idleLater.filter(post => !isPostStoppedByRoomGen(room, post))
laterPosts.delete(room.id)
if (liveLater.length === 0) return 0
const currentGen = roomStopGen.get(room.id) ?? 0
const runnable = currentGen > 0
? liveLater.filter(post => !Number.isInteger(post?.stopGen) || post.stopGen >= currentGen)
: liveLater
if (runnable.length === 0) {
laterPosts.set(room.id, liveLater)
return 0
}
if (runnable.length < liveLater.length) {
const runnableSet = new Set(runnable)
laterPosts.set(room.id, liveLater.filter(post => !runnableSet.has(post)))
}
clearPendingRoomLedgerRetry(room.id)
startRound(room, runnable, agent ?? ctx.get?.('agents')?.get?.(rt.sessionOfRoom(room)))
return runnable.length
}
const initial = pendingRoomLedgerDispatches(room)
const hadUnpersistedSupersedes = hasUnpersistedRoomSupersedes(room.id)
if (initial.length === 0 && !hadUnpersistedSupersedes) {
if (hasPendingRoomLedgerWork(room)) {
schedulePendingRoomLedgerRetry(room.id)
} else if (!inFlightRecoveredDispatches.has(room.id)) {
clearPendingRoomLedgerRetry(room.id)
return drainIdleLaterPostsIfUnblocked()
}
return 0
}
Expand Down Expand Up @@ -9294,6 +9409,7 @@ export function install(rt) {
schedulePendingRoomLedgerRetry(room.id)
} else if (!inFlightRecoveredDispatches.has(room.id)) {
clearPendingRoomLedgerRetry(room.id)
return drainIdleLaterPostsIfUnblocked()
}
return 0
}
Expand Down Expand Up @@ -9369,6 +9485,7 @@ export function install(rt) {
schedulePendingRoomLedgerRetry(room.id)
} else if (pending.length === 0 && !inFlightRecoveredDispatches.has(room.id)) {
clearPendingRoomLedgerRetry(room.id)
return drainIdleLaterPostsIfUnblocked()
}
if (pending.length === 0) return 0
if (!hasDeferred) {
Expand Down
Loading
Loading