Skip to content

Make dynamic session deletion async, thread-safe, and session-rotating - #715

Merged
Facundo Santiago (santiagxf) merged 7 commits into
mainfrom
copilot/add-delete-method-for-sessions
Jun 18, 2026
Merged

Make dynamic session deletion async, thread-safe, and session-rotating#715
Facundo Santiago (santiagxf) merged 7 commits into
mainfrom
copilot/add-delete-method-for-sessions

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Session lifecycle control needed stronger guarantees when deleting after invocation: deletion should not block execution, must be safe under concurrent access, and must not keep using a deleted session identifier. This update tightens delete semantics for both Python REPL and Bash session tools.

  • Session deletion semantics

    • delete_session() now:
      • captures current session_id under lock
      • rotates to a new session_id immediately
      • dispatches delete of the captured ID asynchronously on a background daemon thread
    • This ensures subsequent calls cannot race on a stale/deleting session ID.
  • Concurrency safety

    • Added per-tool private lock for session_id access/mutation.
    • URL construction now reads session ID through lock-protected access to avoid concurrent read/write hazards.
  • Tool parity and correctness

    • Applied the same behavior to both SessionsPythonREPLTool and SessionsBashTool.
    • Updated Bash session_id default to Field(default_factory=...) so each instance gets a unique ID (not class-evaluated once).
  • Representative behavior

    tool = SessionsPythonREPLTool(
        pool_management_endpoint=POOL_MANAGEMENT_ENDPOINT,
        delete_session_after_invocation=True,
    )
    
    # On invoke/run:
    # 1) execute with current session_id
    # 2) schedule async delete of that session_id
    # 3) immediately rotate tool.session_id for next invocation
    result = tool.invoke("1 + 1")

Copilot AI changed the title [WIP] Add method to delete sessions after execution Add explicit session lifecycle controls to Dynamic Sessions tools Jun 17, 2026
Copilot AI changed the title Add explicit session lifecycle controls to Dynamic Sessions tools Add session_idle_timeout_seconds to SessionsPythonREPLTool and SessionsBashTool Jun 17, 2026
Copilot AI changed the title Add session_idle_timeout_seconds to SessionsPythonREPLTool and SessionsBashTool feat(dynamic-sessions): add explicit session close/delete support Jun 17, 2026
Copilot AI changed the title feat(dynamic-sessions): add explicit session close/delete support Add optional per-invocation session teardown for Dynamic Sessions tools Jun 18, 2026
Copilot AI changed the title Add optional per-invocation session teardown for Dynamic Sessions tools Make dynamic session deletion async, thread-safe, and session-rotating Jun 18, 2026
@santiagxf
Facundo Santiago (santiagxf) merged commit e53e43e into main Jun 18, 2026
11 checks passed
@santiagxf
Facundo Santiago (santiagxf) deleted the copilot/add-delete-method-for-sessions branch June 18, 2026 21:12
Facundo Santiago (santiagxf) pushed a commit that referenced this pull request Jun 23, 2026
This updates the `langchain-azure-dynamic-sessions` package metadata for
the next release and refreshes the README changelog entry for `1.0.3`.
The changelog wording now explicitly introduces
`delete_session_after_invocation`, explains its cleanup purpose, and
clarifies why the concurrency-safety changes were added.

- **Release metadata**
- Bump `langchain-azure-dynamic-sessions` from `1.0.2` to `1.0.3` in
`pyproject.toml`

- **Changelog**
  - Add a new `1.0.3` entry at the top of the README changelog
- Summarize the session cleanup improvement around
`delete_session_after_invocation`
- Capture the runtime dependency/security refreshes included in the
release

- **Wording refinement**
- Rework the `#715` release note so it leads with the new parameter,
states that it enables automatic session cleanup after each invocation,
and explains that async deletion plus immediate session ID rotation were
added to make that behavior safe under concurrent use

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
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.

2 participants