Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

chore(core): add git push-to-sync timing logs (#10215)

Sarah Woodersa12af8e6eeb3
diff --git a/letta/server/rest_api/routers/v1/git_http.py b/letta/server/rest_api/routers/v1/git_http.py
index 9668cb49e..777284e72 100644
--- a/letta/server/rest_api/routers/v1/git_http.py
+++ b/letta/server/rest_api/routers/v1/git_http.py
@@ -20,6 +20,7 @@ successful `git-receive-pack`.
from __future__ import annotations
import asyncio
+import time
from typing import Dict, Iterable, Optional
import httpx
@@ -63,6 +64,8 @@ async def _sync_after_push(actor_id: str, agent_id: str) -> None:
GCS sync is handled by the memfs service. This function syncs the
block contents to PostgreSQL for caching/querying.
"""
+ started_at = time.perf_counter()
+
if _server_instance is None:
logger.warning("Server instance not set; cannot sync after push")
return
@@ -189,6 +192,14 @@ async def _sync_after_push(actor_id: str, agent_id: str) -> None:
except Exception:
logger.exception("Failed detaching removed blocks during post-push sync (agent=%s)", agent_id)
+ total_ms = (time.perf_counter() - started_at) * 1000
+ logger.info(
+ "post-push sync timing: agent=%s synced_blocks=%d total_ms=%.2f",
+ agent_id,
+ synced,
+ total_ms,
+ )
+
def _parse_agent_id_from_repo_path(path: str) -> Optional[str]:
"""Extract agent_id from a git HTTP path.
@@ -269,7 +280,7 @@ async def proxy_git_http(
# Resolve org_id from the authenticated actor + agent and forward to memfs.
agent_id = _parse_agent_id_from_repo_path(path)
- sync_after_push_context: tuple[str, str] | None = None
+ sync_after_push_context: tuple[str, str, float] | None = None
if agent_id is not None:
actor = await server.user_manager.get_actor_or_default_async(actor_id=headers.actor_id)
# Authorization check: ensure the actor can access this agent.
@@ -285,7 +296,7 @@ async def proxy_git_http(
# Defer post-push sync until after the upstream response stream has fully
# completed, so memfs has finished persisting refs/objects.
if request.method == "POST" and path.endswith("git-receive-pack"):
- sync_after_push_context = (actor.id, agent_id)
+ sync_after_push_context = (actor.id, agent_id, time.perf_counter())
logger.info(
"proxy_git_http: method=%s path=%s parsed_agent_id=%s actor_id=%s has_user_id_hdr=%s x_org_hdr=%s",
@@ -320,9 +331,25 @@ async def proxy_git_http(
await client.aclose()
if sync_after_push_context is not None and upstream.status_code < 400:
- actor_id, pushed_agent_id = sync_after_push_context
+ actor_id, pushed_agent_id, receive_pack_started_at = sync_after_push_context
+ stream_closed_ms = (time.perf_counter() - receive_pack_started_at) * 1000
+ logger.info(
+ "git-receive-pack completed stream: agent=%s stream_close_ms=%.2f",
+ pushed_agent_id,
+ stream_closed_ms,
+ )
+
+ sync_started_at = time.perf_counter()
try:
await _sync_after_push(actor_id, pushed_agent_id)
+ sync_ms = (time.perf_counter() - sync_started_at) * 1000
+ total_from_receive_pack_ms = (time.perf_counter() - receive_pack_started_at) * 1000
+ logger.info(
+ "git push->sync timing: agent=%s sync_ms=%.2f total_from_receive_pack_ms=%.2f",
+ pushed_agent_id,
+ sync_ms,
+ total_from_receive_pack_ms,
+ )
except Exception:
logger.exception("Failed to trigger deferred post-push sync (agent_id=%s)", pushed_agent_id)