fix(scheduled-task): wait for session startup before giving up#165
Merged
Merged
Conversation
The executor treated a session missing from the status map (server has
not started it yet) the same as an idle session, so it gave up after
~6s (MAX_IDLE_POLLS_WITHOUT_RESULT * EXECUTION_POLL_INTERVAL_MS). The
finally block then deleted the temporary session while the server was
still inserting the first user message, which failed server-side with
"FOREIGN KEY constraint failed" and surfaced as a daily scheduled-task
failure ("finished without a completed assistant response").
Track whether the session has been observed active; only apply the
short idle deadline after activity is seen, and use a separate startup
grace before the server registers the session.
Fixes grinev#164
Owner
|
@xodmd45-ctrl thanks for contribution! |
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.
Fixes #164.
Problem
waitForScheduledTaskResulttreated a session that is not yet in the status map (server has not started processing the prompt) the same as a session that has gone idle:With
MAX_IDLE_POLLS_WITHOUT_RESULT = 3×EXECUTION_POLL_INTERVAL_MS = 2000, the executor gives up after only ~6s. AfterpromptAsync, OpenCode does not register the session insession.statusuntil it begins processing, which on a cold project instance routinely takes longer than 6s (measured: ~6.3s warm, ~23s cold first-of-day).When the executor gives up, the
finallyblock deletes the temporary session while the server is still inserting the first user message, producing a server-sideFOREIGN KEY constraint failed(message.session_id → session.id). This made scheduled tasks fail every day.Fix
Track whether the session has been observed active (
hasObservedActivity). Only apply the shortMAX_IDLE_POLLS_WITHOUT_RESULTdeadline after activity has been seen; before that, wait through a dedicated startup grace (MAX_STARTUP_POLLS_WITHOUT_ACTIVITY). A session that legitimately goes idle after working still fails fast as before.Tests
MAX_IDLE_POLLS_WITHOUT_RESULTwhile the session is absent from the status map, then succeeds once it becomes active.npm run build,npm run lint, andvitest runall pass (14/14 in this suite).Verified end-to-end against a live bot (
0.21.2+ opencode1.17.8,zai-coding-plan/glm-5.2): the scheduled task now reaches model streaming instead of failing with the FK error at ~6s.