mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(native-chat): keep waiting live text when an opening sends none
This commit is contained in:
+7
-4
@@ -5,6 +5,12 @@ import type { SubscriberDeliveryPort } from './agent-session-subscriber-catch-up
|
||||
import { backgroundTaskFingerprint } from './agent-session-subscriber-frame-fields'
|
||||
import { emptyAgentSessionBatch } from './agent-session-empty-batch'
|
||||
|
||||
/** Live text goes only to a subscriber that has every journal row; one behind waits for catch-up. */
|
||||
export function subscriberAtHead(subscriber: Subscriber, journal: AgentSessionJournal): boolean {
|
||||
const cursor = journal.cursor()
|
||||
return subscriber.cursor.epoch === cursor.epoch && subscriber.cursor.sequence === cursor.sequence
|
||||
}
|
||||
|
||||
/** Ordinary equal-cursor items preserve the existing desktop and phone merge contract. */
|
||||
export async function publishSubscriberLiveText(
|
||||
port: SubscriberDeliveryPort,
|
||||
@@ -23,10 +29,7 @@ export async function publishSubscriberLiveText(
|
||||
}
|
||||
const cursor = journal.cursor()
|
||||
for (const subscriber of subscribers) {
|
||||
if (
|
||||
subscriber.cursor.epoch !== cursor.epoch ||
|
||||
subscriber.cursor.sequence !== cursor.sequence
|
||||
) {
|
||||
if (!subscriberAtHead(subscriber, journal)) {
|
||||
continue
|
||||
}
|
||||
await port.emit(
|
||||
|
||||
+8
-4
@@ -21,7 +21,7 @@ import {
|
||||
type SubscriberDeliveryPort
|
||||
} from './agent-session-subscriber-catch-up'
|
||||
import type { SqlAgentSessionJournal as AgentSessionJournal } from '../../../agent-session-journal/journal-sql-store'
|
||||
import { publishSubscriberLiveText } from './agent-session-live-publications'
|
||||
import { publishSubscriberLiveText, subscriberAtHead } from './agent-session-live-publications'
|
||||
import { emptyAgentSessionBatch } from './agent-session-empty-batch'
|
||||
import { rememberLatestPerSession } from './structured-agent-session-activity-retention'
|
||||
import { resumeSubscriber } from './agent-session-stop-note-refresh'
|
||||
@@ -110,7 +110,7 @@ export class AgentSessionSubscribers {
|
||||
sessionId: input.sessionId,
|
||||
journal,
|
||||
fence: input.fence,
|
||||
items: this.sentLiveText(subscriber, input.sessionId),
|
||||
items: this.sentLiveText(subscriber, input.sessionId, journal),
|
||||
subscribers: [subscriber],
|
||||
hostNow
|
||||
})
|
||||
@@ -204,7 +204,7 @@ export class AgentSessionSubscribers {
|
||||
sessionId,
|
||||
journal,
|
||||
fence,
|
||||
items: this.sentLiveText(subscriber, sessionId),
|
||||
items: this.sentLiveText(subscriber, sessionId, journal),
|
||||
subscribers: [subscriber],
|
||||
hostNow
|
||||
})
|
||||
@@ -248,8 +248,12 @@ export class AgentSessionSubscribers {
|
||||
}
|
||||
|
||||
/** Live text an opening or snapshot sends itself counts against its subscriber's share. */
|
||||
private sentLiveText(subscriber: Subscriber, sessionId: string) {
|
||||
private sentLiveText(subscriber: Subscriber, sessionId: string, journal: AgentSessionJournal) {
|
||||
const items = this.hooks.readLiveText?.(sessionId) ?? []
|
||||
// Sending nothing leaves any waiting live text for after the subscriber catches up.
|
||||
if (items.length === 0 || !subscriberAtHead(subscriber, journal)) {
|
||||
return []
|
||||
}
|
||||
return this.lanes.of(subscriber).sendsLiveText(items) ? items : []
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -186,6 +186,14 @@ it('counts live text an opening sends once, not again for the copy waiting behin
|
||||
(publish) => publish(0, 3_000_000)
|
||||
)
|
||||
try {
|
||||
await vi.waitFor(() =>
|
||||
expect(pane.events).toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: 'batch',
|
||||
batch: expect.objectContaining({ items: [text] })
|
||||
})
|
||||
)
|
||||
)
|
||||
expect(pane.ends).toHaveLength(0)
|
||||
} finally {
|
||||
pane.release()
|
||||
|
||||
Reference in New Issue
Block a user