posit-dev / posit-dev/querychat
[Python] Add automatic connection `cleanup`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 212
- Forks
- 29
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 27
Description
Summary
This issue tracks the implementation of automatic connection cleanup in QueryChat for Python, building on the R implementation discussed in PR #164.
Background
PR #164 adds a cleanup parameter to QueryChat's R implementation with automatic cleanup behavior when:
- A connection is created by QueryChat (e.g., for a data frame)
- The QueryChat object is used within a Shiny app session via
on_stop()/onStop()callbacks
Problem Statement
Python's Shiny framework does not yet have an equivalent of R's shiny::onStop() callback mechanism that allows for application-level cleanup. This prevents us from:
- Automatically cleaning up connections when QueryChat exits a Shiny app
- Keeping the R/Python cleanup logic in sync
- Providing consistent behavior across both implementations
Key Considerations
- Connection Ownership: Only clean up connections that QueryChat created or explicitly manages, not connections provided by users, unless the QueryChat object is created inside a Shiny app context
- Safety First: Avoid destructive actions when a connection is used outside of a Shiny app context
- Predictable Behavior: Simple, clear rules about when cleanup happens (not relying on
interactive()or other implicit signals) - Consistency: R and Python implementations should follow similar logic
Next Steps
- Implement
on_stop()in Shiny for Python (equivalent to R'sshiny::onStop()) - Once available, add Python support for automatic cleanup with similar logic to the R implementation
- Document when and how cleanup occurs for users
Related
- PR #164 (R implementation)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Python cleanup requirements in this issue and the related R implementation in PR #164. Investigate whether Python Shiny provides the required on_stop() lifecycle hook, then identify the QueryChat Python cleanup entry points and tests. Done means safe ownership rules, Shiny-session cleanup, R/Python consistency, and user documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100