Skip to content

fix(python): clarify Boxlite context manager#961

Open
G4614 wants to merge 1 commit into
mainfrom
g4614/pol-102-boxlite-context-manager
Open

fix(python): clarify Boxlite context manager#961
G4614 wants to merge 1 commit into
mainfrom
g4614/pol-102-boxlite-context-manager

Conversation

@G4614

@G4614 G4614 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Make native Boxlite support async context management and reject sync context-manager usage with a SyncBoxlite hint.

Test plan:

  • cargo fmt --all
  • sdks/python/.venv/bin/python -m py_compile sdks/python/tests/test_box_management_mock.py
  • BOXLITE_DEPS_STUB=1 cargo check -p boxlite-python
  • Not rerun on debug host after splitting; the same context-manager paths passed on debug host before the split in fix(python): align SDK errors and metadata #954

Summary by CodeRabbit

  • New Features

    • Added async context-manager support for the Python runtime via async with.
    • Async context managers now shut down the underlying runtime automatically on exit.
  • Bug Fixes

    • Using the async context manager with with now raises a clear error directing users to the correct synchronous API.
    • Attempting to use the runtime after exiting the async context now raises an informative error.
  • Tests

    • Added pytest coverage for both sync-misuse and async lifecycle/shutdown behavior.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9bd25096-9519-491f-a75f-a51f83289949

📥 Commits

Reviewing files that changed from the base of the PR and between 39cc257 and df025ad.

📒 Files selected for processing (2)
  • sdks/python/src/runtime.rs
  • sdks/python/tests/test_box_management_mock.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • sdks/python/tests/test_box_management_mock.py
  • sdks/python/src/runtime.rs

📝 Walkthrough

Walkthrough

PyBoxlite now supports asynchronous context management, shuts down on async exit, and rejects synchronous context-manager entry with guidance to use SyncBoxlite. Tests cover both entry modes and post-shutdown behavior.

Changes

Python context management

Layer / File(s) Summary
Context-manager hooks and validation
sdks/python/src/runtime.rs, sdks/python/tests/test_box_management_mock.py
PyBoxlite implements asynchronous entry and exit hooks, rejects synchronous entry, and tests runtime shutdown and related errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PythonCaller
  participant PyBoxlite
  participant Runtime
  PythonCaller->>PyBoxlite: async with runtime
  PyBoxlite-->>PythonCaller: return runtime from __aenter__
  PythonCaller->>PyBoxlite: exit async context
  PyBoxlite->>Runtime: shutdown(None)
  PyBoxlite-->>PythonCaller: return false
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks the required Summary/Changes/How to verify sections and only provides a test plan. Rewrite it using the template headings: Summary, Changes, How to verify, and optional Risks / rollout.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately highlights the Boxlite context-manager change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch g4614/pol-102-boxlite-context-manager

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@G4614
G4614 force-pushed the g4614/pol-102-boxlite-context-manager branch from 5061964 to 39cc257 Compare July 14, 2026 12:54
@G4614
G4614 marked this pull request as ready for review July 20, 2026 11:35
@G4614
G4614 requested a review from a team as a code owner July 20, 2026 11:35
@boxlite-agent

boxlite-agent Bot commented Jul 20, 2026

Copy link
Copy Markdown

📦 BoxLite review — couldn't complete

claude exited 1

stdout:
{"is_error":true,"duration_api_ms":0,"num_turns":1,"stop_reason":"stop_sequence","session_id":"a2cb7a8a-db60-44cd-b815-b328cfde4f9f","total_cost_usd":0,"usage":{"input_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":0,"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"inference_geo":"","iterations":[],"speed":"standard"},"modelUsage":{},"permission_denials":[],"terminal_reason":"api_error","fast_mode_state":"off","subtype":"success","api_error_status":403,"result":"Your organization has disabled Claude subscription access for Claude Code · Use an Anthropic API key instead, or ask your admin to enable access","type":"result","duration_ms":1021,"uuid":"2daa06cf-862d-4224-9f9a-8ee4e2374f60"}

stderr:
<empty>

powered by BoxLite

@G4614
G4614 enabled auto-merge July 20, 2026 11:35
@G4614
G4614 force-pushed the g4614/pol-102-boxlite-context-manager branch 2 times, most recently from 39cc257 to 0d21b1f Compare July 23, 2026 08:45
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.

1 participant