Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/claim-answer-lost.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/board': patch
---

On Vercel's board, a write whose answer is lost on the way (the connection drops, so `fetch` throws) is sent again with the same operation ID and claim token, which the API answers as it did the first time. A `tasks claim` that landed is now the caller's, instead of failing with `network_error` while the task stays claimed until its lease runs out.
6 changes: 6 additions & 0 deletions packages/board/src/server/backend-vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,12 @@ export function createVercel(options: VercelOptions, environment: VercelEnvironm
})
} catch (error) {
if (error instanceof HttpError || (error instanceof Error && error.name === 'AbortError')) throw error
// An answer lost on the way may follow a write that landed: one the API can tell it has seen goes again, and is answered as it was.
if (attempt < RETRIES && repeatable && !init.signal?.aborted) {
await pause(retryWait(attempt, null), init.signal)
init.signal?.throwIfAborted()
continue
}
throw new HttpError(502, 'unreachable', `Vercel's API didn't answer: ${error instanceof Error ? error.message : String(error)}`)
}
if (response.status === 304 && kept) {
Expand Down
20 changes: 20 additions & 0 deletions packages/board/test/backend-vercel-tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,26 @@ describe("vercel()'s tasks", () => {
expect(seen).not.toMatch(/"token"|claimToken/)
})

it("asks again with the same operation and token when a write's answer is lost on the way, so a claim that landed is the caller's", async () => {
const api = fakeMessageboard()
const julian = handleOn(api)
const { task } = await julian.tasks.create('work', { text: 'migrate the table' })
let lost = false
const cut = handleOn(api, 'user:u_jb', {
answered: (request, response) => {
if (!request.path.endsWith('/claim') || lost) return response
lost = true
throw new TypeError('fetch failed')
},
})
const claim = await cut.as('claude').tasks.claim(task.id, { lease: 60 })
const [landed, retried] = cut.sent.filter((request) => request.path === `/tasks/${threadOf(task.id)}/claim`)
expect(retried!.body).toMatchObject({ operationId: landed!.body!.operationId, claimToken: landed!.body!.claimToken })
expect(claim).toMatchObject({ token: landed!.body!.claimToken, epoch: 1 })
expect((await julian.thread(task.id)).message.task).toMatchObject({ state: 'claimed', epoch: 1 })
await claim.complete('migrated')
})

it("sends a token its caller chose as the claim's, by ID and for the next ready task", async () => {
const RUN_TOKEN = 'r'.repeat(43)
const api = fakeMessageboard()
Expand Down