Skip to content

Add Proper Session Cleanup for the Ollama Client #10

Description

@Aryan27-max

Description

The Ollama client currently creates a persistent requests.Session() to improve request performance, but the session is never explicitly closed.

While this is generally acceptable for short-lived executions, it can lead to unnecessary resource usage during long-running watch mode sessions, repeated test runs, or future integrations where multiple client instances may be created.

Improve the client by implementing proper session lifecycle management.


Tasks

  • Add an explicit close() method to the Ollama client.
  • (Optional) Implement context manager support using __enter__() and __exit__().
  • Ensure the pipeline properly closes the session after execution.
  • Update unit tests to verify that sessions are cleaned up correctly.
  • Preserve the existing API and behavior for current users.

Files to Modify

  • llm/ollama.py
  • core/pipeline.py
  • tests/test_ollama.py

Suggested Implementation

Possible approaches include:

  • Implement a close() method that releases the underlying requests.Session.
  • Support usage such as:
with OllamaClient(...) as client:
    ...
  • Ensure watch mode and long-running processes clean up resources gracefully on exit.

Acceptance Criteria

  • The Ollama client exposes a close() method.
  • Session resources are released after use.
  • Context manager support is implemented (optional but encouraged).
  • The pipeline uses the cleanup mechanism where appropriate.
  • Unit tests verify session cleanup.
  • Existing functionality remains unchanged.

Difficulty

Easy


Estimated Time

~30 Minutes


Thank you for contributing to QWENTUS!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions