Sweep orphaned pending requests on startup and fire their webhooks#1487
Merged
Conversation
A server restart killed in-flight /repo/agent runs but left their .reqs files at "pending" forever, so pollers hung and webhookUrl callbacks never fired. Now startReq persists the caller's webhookUrl into the .reqs file, and a boot-time sweep flips still-pending files to failed, delivers the terminal webhook for any that registered one, and re-adopts surviving files into the eviction index so pre-restart files still churn out under MAX_REQS. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since #1482, request state survives restarts as
.reqs/<id>.jsonfiles — but only for runs that reached a terminal state. A restart mid-run left zombies:{"status":"pending"}forever; nothing resumed the run or marked it failed, soGET /progresspollers hung indefinitely.webhookUrlterminal callback never fired — delivery only happened from the in-process finish/fail path, and the URL wasn't persisted anywhere.startReqonly evicts ids in the in-memoryREQ_ORDER, which dies with the process.Fix
startReq(webhookUrl?)persists the caller's webhook URL into the.reqsfile (existing no-arg callers unaffected;checkReqstrips it so the/progressresponse shape is unchanged).sweepOrphanedReqs()(reqs.ts) runs at boot: flips still-pendingfiles to{status: "failed", error: "server restarted while request was in-flight"}and re-adopts all surviving files into the eviction index, oldest first, so pre-restart files churn out underMAX_REQSagain.sweepOrphanedRuns()(repo/index.ts) wraps the sweep and POSTs the standard terminal payload to each orphan's recorded webhook via the existing retryingpostTerminalWebhook. Invoked from theapp.listencallback.Verified
tsc --noEmitclean. Exercised the sweep against a tempREQS_DIRsimulating a restart: pending files (with and without webhook) flipped to failed and returned as orphans with the right webhook URLs, completed files untouched, freshstartReqwriteswebhookUrlto disk whilecheckReqomits it.Note: this covers process restarts; container restarts still need
REQS_DIRon a mounted volume for the files to survive at all.🤖 Generated with Claude Code