fix(background-activity): address review on resync scope and stale subscribe responses

A directory subscribed by the stream but neither registered as a repo nor
remembered as a session directory was reconciled on subscribe but skipped on
resync, so a missed shell exit could leave the indicator stale. Pass the
stream's subscribed directories to onResync and reconcile their pending
actions and running shells alongside the tracked ones.

Subscribe responses that arrive after the connection was replaced or the
directory was unsubscribed could also apply snapshots to state the client no
longer owns. Ignore responses from a superseded connection and report only
directories still subscribed.

The stale-indicator e2e test now waits for the successful unsubscribe response
and asserts the subscribe responses succeeded instead of sleeping.
This commit is contained in:
Chris Scott committed 2026-10-15 10:18:06 -04:00
1 parent 74a2f6fb6e
commit 1b2665bd2b
5 files changed
+131 -26

No files matched your search

+7 -6
View File
@@ -76,9 +76,9 @@ function createUnregisteredDirectory(name: string): string {
return directory
}
function waitForDirectorySubscription(page: Page, directory: string) {
function waitForDirectorySubscription(page: Page, directory: string, endpoint = '/api/sse/subscribe') {
return page.waitForResponse((response) =>
response.url().includes('/api/sse/subscribe') && (response.request().postData() ?? '').includes(directory),
response.url().includes(endpoint) && (response.request().postData() ?? '').includes(directory),
)
}
@@ -206,15 +206,16 @@ test.describe('session background activity', () => {
await page.goto(`/repos/${repo.id}/sessions/${sessionId}`)
await expect(page.getByPlaceholder('Send a message...')).toBeVisible()
await subscribed
expect((await subscribed).ok()).toBe(true)
const shellId = await startBackgroundShell(request, directory, sessionId)
createdShells.push({ directory, id: shellId })
await expect(backgroundIndicator(page)).toBeVisible()
const unsubscribed = waitForDirectorySubscription(page, directory, '/api/sse/unsubscribe')
await navigateWithinApp(page, '/')
await page.waitForTimeout(3_000)
expect((await unsubscribed).ok()).toBe(true)
await removeShell(request, directory, shellId)
await page.waitForTimeout(3_000)
await navigateWithinApp(page, `/repos/${repo.id}/sessions/${sessionId}`)
@@ -231,14 +232,14 @@ test.describe('session background activity', () => {
await page.goto(`/repos/${repo.id}/sessions/${sessionId}`)
await expect(page.getByPlaceholder('Send a message...')).toBeVisible()
await subscribedToSource
expect((await subscribedToSource).ok()).toBe(true)
const subscribedToTarget = waitForDirectorySubscription(page, target)
await requireOk(
await request.post(`/api/opencode/api/session/${sessionId}/move`, { data: { directory: target } }),
'move session',
)
await subscribedToTarget
expect((await subscribedToTarget).ok()).toBe(true)
const shellId = await startBackgroundShell(request, target, sessionId)
createdShells.push({ directory: target, id: shellId })