fix(core): backfill missing blocks when git repo is incomplete (#9340)
When enable_git_memory_for_agent is called on an agent that already has the git-memory-enabled tag, it was returning early if the repo existed, even if the repo was missing blocks. Now checks if all blocks are present in the repo and backfills any missing ones. 🐾 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
@@ -361,7 +361,37 @@ class GitEnabledBlockManager(BlockManager):
|
|||||||
try:
|
try:
|
||||||
# Fast check: does the repo exist in backing storage?
|
# Fast check: does the repo exist in backing storage?
|
||||||
await self.memory_repo_manager.git.get_head_sha(agent_id=agent_id, org_id=actor.organization_id)
|
await self.memory_repo_manager.git.get_head_sha(agent_id=agent_id, org_id=actor.organization_id)
|
||||||
logger.info(f"Git memory already enabled for agent {agent_id}")
|
|
||||||
|
# Repo exists - check if all blocks are present
|
||||||
|
blocks = await self.get_blocks_by_agent_async(agent_id, actor)
|
||||||
|
repo_files = await self.memory_repo_manager.git.get_files(agent_id=agent_id, org_id=actor.organization_id, ref="HEAD")
|
||||||
|
|
||||||
|
# Check which blocks are missing from repo
|
||||||
|
missing_blocks = []
|
||||||
|
for block in blocks:
|
||||||
|
expected_path = f"memory/{block.label}.md"
|
||||||
|
if expected_path not in repo_files:
|
||||||
|
missing_blocks.append(block)
|
||||||
|
|
||||||
|
if missing_blocks:
|
||||||
|
logger.warning(
|
||||||
|
"Git memory repo exists but missing %d/%d blocks for agent %s; backfilling",
|
||||||
|
len(missing_blocks),
|
||||||
|
len(blocks),
|
||||||
|
agent_id,
|
||||||
|
)
|
||||||
|
# Commit missing blocks
|
||||||
|
for block in missing_blocks:
|
||||||
|
await self.memory_repo_manager.update_block_async(
|
||||||
|
agent_id=agent_id,
|
||||||
|
label=block.label,
|
||||||
|
value=block.value or "",
|
||||||
|
actor=actor,
|
||||||
|
message=f"Backfill {block.label} block",
|
||||||
|
)
|
||||||
|
logger.info(f"Backfilled {len(missing_blocks)} missing blocks for agent {agent_id}")
|
||||||
|
else:
|
||||||
|
logger.info(f"Git memory already enabled for agent {agent_id}")
|
||||||
return
|
return
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
|
|||||||
Reference in New Issue
Block a user