Fix git-memory context preview parsing (#9414)
* fix(core): handle git memory label prefix collisions in filesystem view Prevent context window preview crashes when a block label is both a leaf and a prefix (e.g. system/human and system/human/context) by rendering a node as both file and directory. Add regression test. 👾 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta <noreply@letta.com> * fix(core): parse git-backed core memory in context window preview ContextWindowCalculator.extract_system_components now detects git-backed memory rendering (<memory_filesystem> and <system/...> tags) when <memory_blocks> wrapper is absent, so core_memory is populated in the context preview. Add regression tests. 👾 Generated with [Letta Code](https://letta.com) Co-Authored-By: Letta <noreply@letta.com> --------- Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
committed by
Caren Thomas
parent
ca32311b9a
commit
2ffef0fb31
@@ -223,3 +223,33 @@ def test_current_files_open_counts_truthy_only():
|
||||
m = Memory(agent_type=AgentType.react_agent, blocks=[], file_blocks=[fb1, fb2, fb3])
|
||||
out = m.compile(sources=[src], max_files_open=10)
|
||||
assert "- current_files_open=1" in out
|
||||
|
||||
|
||||
def test_compile_git_memory_filesystem_handles_leaf_directory_collisions():
|
||||
"""Git memory filesystem rendering should tolerate label prefix collisions.
|
||||
|
||||
Example collisions:
|
||||
- leaf at "system" and children under "system/..."
|
||||
- leaf at "system/human" and children under "system/human/..."
|
||||
|
||||
These occur naturally in git-backed memory where both index-like blocks and
|
||||
nested blocks can exist.
|
||||
"""
|
||||
|
||||
m = Memory(
|
||||
agent_type=AgentType.letta_v1_agent,
|
||||
git_enabled=True,
|
||||
blocks=[
|
||||
Block(label="system", value="root", limit=100),
|
||||
Block(label="system/human", value="human index", limit=100),
|
||||
Block(label="system/human/context", value="context", limit=100),
|
||||
],
|
||||
)
|
||||
|
||||
out = m.compile()
|
||||
|
||||
# Should include the filesystem view and not raise.
|
||||
assert "<memory_filesystem>" in out
|
||||
assert "system/" in out
|
||||
assert "system.md" in out
|
||||
assert "human.md" in out
|
||||
|
||||
Reference in New Issue
Block a user