fix(agent): stop title generation from outliving its run - #3517
Open
taciturnaxolotl wants to merge 1 commit into
Open
fix(agent): stop title generation from outliving its run#3517taciturnaxolotl wants to merge 1 commit into
taciturnaxolotl wants to merge 1 commit into
Conversation
Run spawned GenerateTitle on a detached context and never joined it, and
neither did CancelAll, which only waits on activeRequests. So the goroutine
outlived whoever started it and wrote to an already-closed database:
ERROR Failed to save session title and usage error="sql: database is closed"
Track it in a WaitGroup, join it in Run (after the busy state and run context
are released, so cancel stays responsive) and in CancelAll, and bound
generation at 60s so a stalled request cannot pin the goroutine forever.
taciturnaxolotl
force-pushed
the
title-lifetime
branch
from
August 7, 2026 15:29
df6bae8 to
9b06a9e
Compare
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.
The title goroutine had no owner.
RunspawnedGenerateTitleon a detached context and never joined it, and neither didCancelAll, which only waits onactiveRequests. So it outlived whoever started it and wrote to an already-closed database:Easiest repro is quitting while the first answer in a new session is still streaming: the session keeps its placeholder title. It also fires constantly in tests.
It's tracked now in a WaitGroup.
Runjoins it after the busy state and run context are already released, so cancel stays as responsive as before, andCancelAlldrains the same group before shutdown closes the db. Generation is also bounded at 60s, since on a detached context a stalled request pinned the goroutine for the life of the process.