Skip to content

fix(agent): stop title generation from outliving its run - #3517

Open
taciturnaxolotl wants to merge 1 commit into
mainfrom
title-lifetime
Open

fix(agent): stop title generation from outliving its run#3517
taciturnaxolotl wants to merge 1 commit into
mainfrom
title-lifetime

Conversation

@taciturnaxolotl

@taciturnaxolotl taciturnaxolotl commented Aug 7, 2026

Copy link
Copy Markdown
Member

The title goroutine had no owner. Run spawned GenerateTitle on a detached context and never joined it, and neither did CancelAll, which only waits on activeRequests. So it outlived whoever started it and wrote to an already-closed database:

ERROR Failed to save session title and usage error="sql: database is closed"

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. Run joins it after the busy state and run context are already released, so cancel stays as responsive as before, and CancelAll drains 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant