-
Notifications
You must be signed in to change notification settings - Fork 12
Fix chat transcript replay and ordering #943
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
Changes from 5 commits
b0b810c
44c495c
e847057
75bac97
bda38f7
da55bf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2959,16 +2959,28 @@ function subscribeRemoteAppControlEvents( | |
| function subscribeAgentChatEvents( | ||
| cb: (payload: AgentChatEventEnvelope) => void, | ||
| pin?: OpenProjectBinding | null, | ||
| options?: { forcePinned?: boolean }, | ||
| ): () => void { | ||
| const removeLocal = agentChatEventFanout(cb); | ||
| if (pin && pin.key !== currentProjectBinding?.key) { | ||
| const forcePinned = Boolean(pin && options?.forcePinned === true); | ||
| const removeLocal = forcePinned ? () => undefined : agentChatEventFanout(cb); | ||
| if (pin && (forcePinned || pin.key !== currentProjectBinding?.key)) { | ||
| let cancelled = false; | ||
| let timer: ReturnType<typeof setTimeout> | null = null; | ||
| let cursor = 0; | ||
| let eventEpoch: string | null = null; | ||
| let replaySuppressed = pin.kind === "remote"; | ||
| const startedAtMs = pin.kind === "local" ? Date.now() : 0; | ||
| let consecutiveFailures = 0; | ||
| const seenLocalEventIds = new Set<number>(); | ||
| const dispatchPinnedLocalEvent = (event: RemoteRuntimeBufferedEvent): void => { | ||
| const eventTime = Date.parse(event.timestamp); | ||
| if ( | ||
| startedAtMs > 0 | ||
| && Number.isFinite(eventTime) | ||
| && eventTime < startedAtMs - 1_000 | ||
| ) { | ||
| return; | ||
| } | ||
| if (seenLocalEventIds.has(event.id)) return; | ||
| seenLocalEventIds.add(event.id); | ||
| while (seenLocalEventIds.size > 1_000) { | ||
|
|
@@ -2993,7 +3005,11 @@ function subscribeAgentChatEvents( | |
| const poll = async (): Promise<void> => { | ||
| let delay = REMOTE_RUNTIME_EVENT_IDLE_POLL_MS; | ||
| try { | ||
| const request = { cursor, limit: 200 }; | ||
| const request = { | ||
| cursor, | ||
| limit: 200, | ||
| ...(replaySuppressed && cursor === 0 ? { replay: false } : {}), | ||
| } satisfies RemoteRuntimeStreamEventsRequest; | ||
| const batch = await ipcRenderer.invoke( | ||
| pin.kind === "remote" | ||
| ? IPC.remoteRuntimeStreamEvents | ||
|
|
@@ -3016,12 +3032,14 @@ function subscribeAgentChatEvents( | |
| eventEpoch = batchEpoch; | ||
| if (epochChanged) { | ||
| cursor = 0; | ||
| replaySuppressed = pin.kind === "remote"; | ||
| delay = 0; | ||
| resetForEpochChange = true; | ||
| } | ||
| } | ||
| if (!resetForEpochChange) { | ||
| cursor = Number.isFinite(batch.nextCursor) ? Math.max(0, Math.floor(batch.nextCursor)) : cursor; | ||
| if (request.replay === false) replaySuppressed = false; | ||
| for (const event of batch.events ?? []) { | ||
| if (pin.kind === "local") { | ||
| dispatchPinnedLocalEvent(event); | ||
|
|
@@ -3162,12 +3180,17 @@ function subscribePinnedProjectRuntimeEvents<T>( | |
| let timer: ReturnType<typeof setTimeout> | null = null; | ||
| let cursor = 0; | ||
| let eventEpoch: string | null = null; | ||
| let replaySuppressed = true; | ||
| let consecutiveFailures = 0; | ||
|
|
||
| const poll = async (): Promise<void> => { | ||
| let delay = REMOTE_RUNTIME_EVENT_IDLE_POLL_MS; | ||
| try { | ||
| const request = { cursor, limit: 200 }; | ||
| const request = { | ||
| cursor, | ||
| limit: 200, | ||
| ...(replaySuppressed && cursor === 0 ? { replay: false } : {}), | ||
| } satisfies RemoteRuntimeStreamEventsRequest; | ||
| const batch = await ipcRenderer.invoke( | ||
| pin.kind === "remote" | ||
| ? IPC.remoteRuntimeStreamEvents | ||
|
|
@@ -3190,6 +3213,7 @@ function subscribePinnedProjectRuntimeEvents<T>( | |
| eventEpoch = batchEpoch; | ||
| if (epochChanged) { | ||
| cursor = 0; | ||
| replaySuppressed = true; | ||
| delay = 0; | ||
| resetForEpochChange = true; | ||
|
Comment on lines
3214
to
3218
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a pinned runtime reconnects with a different Useful? React with 👍 / 👎. |
||
| } | ||
|
|
@@ -3198,6 +3222,7 @@ function subscribePinnedProjectRuntimeEvents<T>( | |
| cursor = Number.isFinite(batch.nextCursor) | ||
| ? Math.max(0, Math.floor(batch.nextCursor)) | ||
| : cursor; | ||
| if (request.replay === false) replaySuppressed = false; | ||
| for (const event of batch.events ?? []) { | ||
| const payload = decode(event.payload); | ||
| if (!payload) continue; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.