Conversation
Author
|
Superseded before review: the first head branch accidentally included two local planning-only commits. Reopening from a clean branch based directly on current main; production and test commit content is unchanged. |
This was referenced Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LCM engine clones currently construct a fresh set of SQLite-backed helpers. A clone therefore pays database initialization cost again and retains another set of SQLite file descriptors even though it is serving the same logical database as its prototype.
This change gives each clone family one reference-counted storage bundle while keeping mutable engine/session/model state clone-local. Independently constructed engines still own separate bundles, but bundles resolving to the same canonical database path share one in-process reentrant lock for helper construction, operations, backup/commit, and final teardown.
Fixes #463.
Why this is needed
Hermes creates engine clones for child agents. Before this change, ten retained clones added 60 file descriptors on the measured macOS checkout and spent roughly 100 ms constructing duplicate SQLite helper sets. That multiplication raises the risk of descriptor exhaustion and repeated schema/WAL setup under parallel child-agent workloads.
The ownership boundary is the important part of the fix:
This is complementary to #470's cleanup work. It does not replace #486's cross-process FTS bootstrap locking; the lock introduced here is process-local.
Implementation
_SharedStoragebundle for message store, summary DAG, lifecycle state, optional assertion store, and optional query-view store.clone_for_agent()and preserve clone-local runtime/model state.scripts/measure_clone_storage.pyfor reproducible before/after measurements against a selected checkout.Reproduced benchmark
Environment: macOS, Python from the active Hermes environment, 25 samples, 10 retained clones. The benchmark imports each selected checkout using
LCM_BENCH_REPO_ROOT.Commands:
Commits:
6b7dbb11708241c1ce9c759348509f9148b60e0f9fc02ffResults:
+60→05.877985 ms→0.198782 ms100.084453 ms→2.203067 ms6.731055 ms→7.368695 msRaw local receipts:
/private/tmp/lcm-storage-benchmark-final-base-20260804.json2bcd2a9430f2d63a5b4f7ef00a9386157a9475e27825d935c44e03d3d3c09c06/private/tmp/lcm-storage-benchmark-final-feature-20260804.jsonba969980fa6087ded140a811b1bcf91a2b725e9f64aae536f1484f7cc84a7626Verification
Green feature/affected gates:
tests/test_lcm_core.py::TestLCMEngineSharedStorage: 9 passedtests/test_lcm_engine.py: 751 passed, 1 skippedtests/test_lcm_core.pyexcluding one independently reproduced upstream failure: 316 passedtests/test_packaging_install.py: 38 passed in the grouped run before the known isolated baseline failure was reproducedtests/test_assertion_lifecycle_tools.py tests/test_assertion_store.py tests/test_query_view_store.py: 49 passedtests/test_lcm_core.py::TestLifecycleStateStore: 19 passedtests/test_assertion_store.py: 20 passedtests/test_query_view_store.py: 21 passedgit diff --check: passedFull-suite result:
mainfor pre-existing or load-sensitive tests. The observed failures were reproduced against pristine6b7dbb1, including strict wall-clock embedding deadlines, macOS/varversus/private/varcontainment assertions, trajectory token/chunk expectations, provider-routing behavior, and an isolated packaging registration test.Scope
This PR intentionally does not: