fix(context-engine): clone plugin engines per agent - #62374
fix(context-engine): clone plugin engines per agent#62374stephenschoettler wants to merge 1 commit into
Conversation
Supersedes #42683 (same title, by @the3asic) — this is the current-main replacement preserving that PR's contract direction, and it goes further by giving engines with locks/DB handles a way to construct an isolated runtime rather than relying on |
|
Thanks for rebuilding the clone contract against current main. I found no blocking correctness issue. Current main still takes the general-plugin singleton path through Automated hermes-sweeper review. |
GottZ
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Summary
Two PRs address the process-wide context-engine state issue. #42683 introduced opt-in per-agent cloning but retained shared-instance aliasing by default and only handled hard-close teardown; #62374 rebuilds the contract on current main, preserves deepcopy isolation by default, rejects unsafe aliases, supports non-copyable engines, and covers both soft eviction and hard close.
Related pull requests
- #42683 [closed]
duplicate— (+194/-8) — superseded by #62374: #42683 established the per-agent clone and ownership direction, but its default clone returns the registered singleton and its teardown only runs on close. Despite the keep_open review on #42683, that same review identifies these gaps and explicitly recommends the rebuilt #62374 approach; #42683 therefore remains relevant as the original implementation and attribution source. - #62374
related— (+151/-40) — keep open with a salvage path: retain the explicit clone hook, deepcopy default, template-alias rejection, ownership-gated idempotent shutdown in both release_clients() and close(), and the associated isolation/lifecycle tests. This agrees with the MAINTAINER-BOT keep_open verdict, while adding the cross-PR finding that #62374 supersedes #42683 and resolves the two deficiencies identified in #42683's review.
Duplicates
#42683 and #62374 implement substantially the same per-agent context-engine cloning contract; #62374 is the current-main replacement and #42683 is the superseded predecessor.
Suggested consolidation
Keep #62374 open with the concrete salvage path of preserving its isolated clone contract and dual lifecycle teardown; close #42683 as duplicate of and superseded by #62374. No merge recommendation is made: the available evidence supports retaining #62374's implementation for further maintainer handling, while #42683's default aliasing and missing soft-eviction teardown make it the inferior duplicate.
Complex graph
flowchart LR
classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
classDef best stroke-width:3px,stroke:#b45309
classDef target stroke-width:3px,stroke:#4338ca
subgraph Dup42683 ["PRs duplicating each other"]
P42683["PR #42683 (closed)"]
P62374["PR #62374 (open)"]
end
class P42683 closed
class P62374 open
class P62374 target
click P42683 "https://github.com/NousResearch/hermes-agent/pull/42683"
click P62374 "https://github.com/NousResearch/hermes-agent/pull/62374"
Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed (state tag in the node label).
Cross-PR triage: Reviewed 2 pull requests and 0 issues in this complex. Each diff was read against this issue; Assessment working set: 24 kB of PR diffs, 5 kB of issue/PR text, 5 kB of discussion (8 comments), 0 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.
What does this PR do?
Adds an explicit per-agent clone contract for process-wide context-engine plugin templates and closes owned clone resources when an agent is closed or softly evicted. This is a current-main replacement for stale/conflicting #42683 and preserves the original contract direction proposed there by @the3asic.
Current main already deep-copies general-plugin context engines to prevent #42449's shared-singleton mutation. That fails for engines with locks, database handles, or other non-copyable runtime state.
ContextEngine.clone_for_agent()keeps deepcopy as the default while allowing those engines to construct an isolated runtime explicitly.Related Issue
Related: #42449. Supersedes #42683.
Type of Change
Changes Made
agent/context_engine.pyclone_for_agent()with a deepcopy default for backward-compatible isolation.agent/agent_init.pyNone, exceptions, and template aliases with safe built-in fallback.run_agent.pytests/agent/test_context_engine.pytests/run_agent/test_plugin_context_engine_init.pyHow to Test
Run focused and relevant lifecycle validation:
Result:
66 passed, 0 failed.Run changed-file checks:
Result: all passed.
Manual exercise: not run against a live third-party context engine; focused tests exercise the real
AIAgentinitialization and soft-eviction lifecycle with a lock-holding custom clone engine.Validation Status
Checklist
pytest tests/ -qsuite run locally.Screenshots / Logs
N/A; code-only lifecycle change.