posit-dev / posit-dev/querychat

[Python] Add automatic connection `cleanup`

Open
#170 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. A connection is created by QueryChat (e.g., for a data frame)
  2. 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

  1. 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
  2. Safety First: Avoid destructive actions when a connection is used outside of a Shiny app context
  3. Predictable Behavior: Simple, clear rules about when cleanup happens (not relying on interactive() or other implicit signals)
  4. Consistency: R and Python implementations should follow similar logic

Next Steps

  1. Implement on_stop() in Shiny for Python (equivalent to R's shiny::onStop())
  2. Once available, add Python support for automatic cleanup with similar logic to the R implementation
  3. Document when and how cleanup occurs for users

Related

  • PR #164 (R implementation)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.