Repository navigation
Python: Retain Hyperlight cached tool identities - #8598
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The existing sandbox-entry field invariant test must allow the new tools field to avoid failing.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Retains original Hyperlight tool identities for the lifetime of cached sandbox configurations, preventing cache-key identity reuse.
Changes:
- Stores the original tool tuple in each sandbox cache entry.
- Adds lifecycle and replacement regression tests.
| File | Description |
|---|---|
python/packages/hyperlight/tests/hyperlight/test_hyperlight_codeact.py |
Tests tool retention, cleanup, replacement, and run snapshots. |
python/packages/hyperlight/agent_framework_hyperlight/_execute_code_tool.py |
Retains tools in cached sandbox entries. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): aa68e6dd5a01
Model: gpt-5.6-sol-fast
Overview
The PR addresses identity reuse directly by retaining each cached entry's original tool tuple, with focused weak-reference and replacement tests covering the intended lifetime semantics. Existing locking, run snapshots, and disposal paths preserve cache behavior. However, the new dataclass field violates an existing architectural regression test, leaving the Hyperlight package suite failing.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/hyperlight/agent_framework_hyperlight/_execute_code_tool.py
* Python: Retain Hyperlight cached tool identities * Python: Update Hyperlight sandbox entry invariant

Motivation & Context
Hyperlight sandbox cache keys use each managed tool's object identity, but cached callbacks retain copies rather than the original objects. After a tool is removed or replaced, its original identity could therefore be released while the corresponding sandbox entry remained cached, allowing a later tool identity to select the prior entry.
Retaining the original tools with the cached entry keeps those identity-based keys unique for the full lifetime of the sandbox configuration.
Description & Review Guide
FunctionToolsubclasses._SandboxEntryis the narrowest lifetime fix and that the tests preserve existing run-snapshot and identity semantics.Related Issue
Fixes #8597
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.