fix(agent-teams): keep in-flight turns from failing when the store closes during shutdown - #412
Open
Ivancheng7 wants to merge 1 commit into
Open
Ivancheng7 wants to merge 1 commit into
Ivancheng7 wants to merge 1 commit into
Conversation
…ring shutdown AgentTeamStore.close() closes the SQLite connection while a turn may still be finalizing: the final card path calls enrichWithAgentTeams(), which reads findTeamForChat()/status(). After close those reads throw "The database connection is not open", so a turn that was already running when the process shut down is reported as task_error — precisely the turns a restart should let finish. - Track a closed flag; read accessors (listTeams/getTeam, and everything built on them) return "no data" instead of throwing; close() is idempotent. - enrichWithAgentTeams() skips enrichment once the store is closed and treats any remaining read failure as auxiliary, so the card still renders. - Tests: read accessors after close, idempotent close.
This branch has not been deployed
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
AgentTeamStore.close()closes the SQLite connection during shutdown, but a turn that was already running may still be finalizing its card. The final-card path callsenrichWithAgentTeams(), which readsfindTeamForChat()andstatus(). Once the connection is closed those reads throwThe database connection is not open, so the turn is reported astask_error— exactly the turns that were in flight when the process restarted, i.e. the ones a restart should let finish.Seen on a systemd-managed deployment: a
systemctl restartwindow is enough to fail whatever turn was running at that moment.Fix
AgentTeamStoretracks aclosedflag:listTeams()/getTeam()(and everything built on them) return "no data" after close instead of throwing;close()is idempotent;isClosed()is exposed for callers.enrichWithAgentTeams()skips enrichment once the store is closed, and treats any remaining read failure as auxiliary — the card renders without the team block instead of failing the turn.The narrow race between the
isClosed()check and the read remains (close() can land in between), which is why the caller treats a read failure as non-fatal rather than relying on the flag alone.Tests
tests/agent-team-store.test.tsadds: read accessors after close, idempotent close. The full local suite on this branch matchesupstream/main— no new failures.