Skip to content

Python: Retain Hyperlight cached tool identities - #8598

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
eavanvalkenburg:hyperlight-callback-cache-assessment
Sep 21, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
eavanvalkenburg:hyperlight-callback-cache-assessment

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

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

  • What are the major changes? Cached Hyperlight sandbox entries now retain their original tool tuple. Deterministic weak-reference tests cover tool removal, clearing, same-name replacement, entry discard, and registry shutdown. A replacement test also covers value-equal, unhashable FunctionTool subclasses.
  • What is the impact of these changes? Replacement tools select their own sandbox configuration while existing run-scoped snapshots continue to use their original configuration. Original tools become collectible once the corresponding entry is removed.
  • What do you want reviewers to focus on? Please verify that retaining tools on _SandboxEntry is the narrowest lifetime fix and that the tests preserve existing run-snapshot and identity semantics.

Related Issue

Fixes #8597

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Merged via the queue into microsoft:main with commit fd31b3e Sep 21, 2026
42 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the hyperlight-callback-cache-assessment branch September 21, 2026 15:10
ZedingZhang (ZedingZhang) pushed a commit to ZedingZhang/agent-framework that referenced this pull request Sep 29, 2026
* Python: Retain Hyperlight cached tool identities

* Python: Update Hyperlight sandbox entry invariant

This branch was previously deployed

1 inactive deployment
github-app-auth — e00a7c97 Deployed Sep 21, 2026 by eavanvalkenburg via add_label #23466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Retain Hyperlight tool identities for cached sandboxes

3 participants