Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(eval): Fix commit emb token calculate, add time cost (#1609)
yeshion23333aa236743e498
diff --git a/benchmark/locomo/openclaw/eval.py b/benchmark/locomo/openclaw/eval.pyindex 4bc323da9..c24154ec2 100644--- a/benchmark/locomo/openclaw/eval.py+++ b/benchmark/locomo/openclaw/eval.py@@ -408,8 +408,8 @@ def reset_session(session_path: str, agent_id: str = "main") -> str | None:return None-def calculate_usage_from_jsonl(jsonl_filename: str, agent_id: str = "main") -> dict:- """Calculate token usage from archived JSONL file."""+def calculate_session_metrics_from_jsonl(jsonl_filename: str, agent_id: str = "main") -> dict:+ """Calculate token usage and rounds from archived JSONL file."""# Check if jsonl_filename is already a full pathif os.path.isabs(jsonl_filename) and os.path.exists(jsonl_filename):jsonl_full_path = jsonl_filename@@ -423,6 +423,7 @@ def calculate_usage_from_jsonl(jsonl_filename: str, agent_id: str = "main") -> d"cacheRead": 0,"cacheWrite": 0,"total_tokens": 0,+ "rounds": 0,}if not os.path.exists(jsonl_full_path):@@ -435,6 +436,7 @@ def calculate_usage_from_jsonl(jsonl_filename: str, agent_id: str = "main") -> dcontinueentry = json.loads(line)if entry.get("type") == "message" and entry.get("message", {}).get("role") == "assistant":+ usage["rounds"] += 1entry_usage = entry.get("message", {}).get("usage", {})usage["input_tokens"] += entry_usage.get("input", 0)usage["output_tokens"] += entry_usage.get("output", 0)@@ -686,10 +688,14 @@ def process_single_question(input_msg = f"Answer the question directly: {question}"jsonl_filename = ""+ elapsed_seconds = 0.0+ rounds = 0+ started_at = time.perf_counter()try:response, api_usage = send_message_with_retry(args.base_url, args.token, sample_id, input_msg, 2, args.agent_id, session_key)+ elapsed_seconds = time.perf_counter() - started_atprint(f" [{sample_idx}] A: {response[:60]}{'...' if len(response) > 60 else ''}", file=sys.stderr)# Get sessionFile path from sessions.json using session_key@@ -700,11 +706,14 @@ def process_single_question(if session_file_path:jsonl_filename = reset_session(session_file_path, args.agent_id)- # Calculate usage from JSONL file if available, otherwise use API usage+ # Calculate usage/rounds from JSONL file if available, otherwise use API usageif jsonl_filename and session_file_path:- # Use the directory from session_file_path and the archived filename- usage = calculate_usage_from_jsonl(os.path.join(os.path.dirname(session_file_path), jsonl_filename), args.agent_id)- print(f" [{sample_idx}] tokens (from JSONL): in={usage['input_tokens']} out={usage['output_tokens']} cacheRead={usage['cacheRead']} cacheWrite={usage['cacheWrite']} total={usage['total_tokens']}", file=sys.stderr)+ usage = calculate_session_metrics_from_jsonl(+ os.path.join(os.path.dirname(session_file_path), jsonl_filename),+ args.agent_id,+ )+ rounds = usage.pop("rounds", 0)+ print(f" [{sample_idx}] tokens (from JSONL): in={usage['input_tokens']} out={usage['output_tokens']} cacheRead={usage['cacheRead']} cacheWrite={usage['cacheWrite']} total={usage['total_tokens']} rounds={rounds}", file=sys.stderr)else:usage = {"input_tokens": api_usage.get("input_tokens", 0),@@ -713,9 +722,11 @@ def process_single_question("cacheWrite": api_usage.get("cacheWrite", 0),"total_tokens": api_usage.get("total_tokens", 0),}- print(f" [{sample_idx}] tokens (from API): in={usage['input_tokens']} out={usage['output_tokens']} cacheRead={usage['cacheRead']} cacheWrite={usage['cacheWrite']} total={usage['total_tokens']}", file=sys.stderr)+ rounds = 1 if response and not response.startswith("[ERROR]") else 0+ print(f" [{sample_idx}] tokens (from API): in={usage['input_tokens']} out={usage['output_tokens']} cacheRead={usage['cacheRead']} cacheWrite={usage['cacheWrite']} total={usage['total_tokens']} rounds={rounds}", file=sys.stderr)except Exception as e:+ elapsed_seconds = time.perf_counter() - started_atresponse = f"[ERROR] {e}"usage = {}jsonl_filename = ""@@ -731,6 +742,8 @@ def process_single_question("category": category,"evidence": evidence,"usage": usage,+ "elapsed_seconds": elapsed_seconds,+ "rounds": rounds,"jsonl_filename": jsonl_filename,}@@ -826,7 +839,7 @@ def save_record_to_csv(csv_path: str, record: dict) -> None:file_exists = os.path.exists(csv_path)fieldnames = ["sample_id", "sample_idx", "qi", "question", "expected",- "response", "category", "evidence", "input_tokens",+ "response", "category", "evidence", "elapsed_seconds", "rounds", "input_tokens","output_tokens", "cacheRead", "cacheWrite", "total_tokens","timestamp", "jsonl_filename", "result", "reasoning"]@@ -834,6 +847,8 @@ def save_record_to_csv(csv_path: str, record: dict) -> None:# Flatten usage fieldsflat_record = record.copy()usage = flat_record.pop("usage", {})+ flat_record["elapsed_seconds"] = f"{flat_record.get('elapsed_seconds', 0.0):.3f}"+ flat_record["rounds"] = flat_record.get("rounds", 0)flat_record["input_tokens"] = usage.get("input_tokens", 0)flat_record["output_tokens"] = usage.get("output_tokens", 0)flat_record["cacheRead"] = usage.get("cacheRead", 0)diff --git a/benchmark/locomo/openclaw/import_to_ov.py b/benchmark/locomo/openclaw/import_to_ov.pyindex 02d9d6578..2865b7fce 100644--- a/benchmark/locomo/openclaw/import_to_ov.py+++ b/benchmark/locomo/openclaw/import_to_ov.py@@ -153,6 +153,7 @@ def write_success_record("session","date_time","speakers",+ "elapsed_seconds","embedding_tokens","vlm_tokens","llm_input_tokens",@@ -172,6 +173,7 @@ def write_success_record("session": record["session"],"date_time": record.get("meta", {}).get("date_time", ""),"speakers": record.get("meta", {}).get("speakers", ""),+ "elapsed_seconds": f"{record.get('elapsed_seconds', 0.0):.3f}","embedding_tokens": record["token_usage"].get("embedding", 0),"vlm_tokens": record["token_usage"].get("vlm", 0),"llm_input_tokens": record["token_usage"].get("llm_input", 0),@@ -344,6 +346,7 @@ async def process_single_session(args: argparse.Namespace,) -> Dict[str, Any]:"""处理单个会话的导入任务"""+ started_at = time.perf_counter()try:# 根据参数决定是否使用 sample_id 作为 user_id 和 agent_iduser_id = str(sample_id) if not args.no_user_agent_id else None@@ -355,13 +358,14 @@ async def process_single_session(user_id=user_id,agent_id=agent_id,)+ elapsed_seconds = time.perf_counter() - started_attoken_usage = result["token_usage"]task_id = result.get("task_id")trace_id = result.get("trace_id", "")embedding_tokens = token_usage.get("embedding", 0)vlm_tokens = token_usage.get("vlm", 0)print(- f" -> [COMPLETED] [{sample_id}/{session_key}] embed={embedding_tokens}, vlm={vlm_tokens}, task_id={task_id}, trace_id={trace_id}",+ f" -> [COMPLETED] [{sample_id}/{session_key}] elapsed={elapsed_seconds:.3f}s, embed={embedding_tokens}, vlm={vlm_tokens}, task_id={task_id}, trace_id={trace_id}",file=sys.stderr,)@@ -372,6 +376,7 @@ async def process_single_session("session": session_key,"status": "success","meta": meta,+ "elapsed_seconds": elapsed_seconds,"token_usage": token_usage,"embedding_tokens": embedding_tokens,"vlm_tokens": vlm_tokens,@@ -385,7 +390,8 @@ async def process_single_session(return resultexcept Exception as e:- print(f" -> [ERROR] [{sample_id}/{session_key}] {e}", file=sys.stderr)+ elapsed_seconds = time.perf_counter() - started_at+ print(f" -> [ERROR] [{sample_id}/{session_key}] elapsed={elapsed_seconds:.3f}s, {e}", file=sys.stderr)traceback.print_exc(file=sys.stderr)# Write error recorddiff --git a/benchmark/locomo/openclaw/run_full_eval.sh b/benchmark/locomo/openclaw/run_full_eval.shindex 9429e7b2d..92be8d953 100755--- a/benchmark/locomo/openclaw/run_full_eval.sh+++ b/benchmark/locomo/openclaw/run_full_eval.sh@@ -94,8 +94,6 @@ if [ "$SKIP_IMPORT" = false ]; thenpython "$SCRIPT_DIR/import_to_ov.py" --no-user-agent-id --input "$INPUT_FILE" $FORCE_INGEST_ARG $SAMPLE_ARGfi- echo "导入完成,等待 1 分钟..."- sleep 60elseecho "[1/5] 跳过导入数据..."fidiff --git a/benchmark/locomo/openclaw/stat_judge_result.py b/benchmark/locomo/openclaw/stat_judge_result.pyindex 63816e004..b734970e0 100644--- a/benchmark/locomo/openclaw/stat_judge_result.py+++ b/benchmark/locomo/openclaw/stat_judge_result.py@@ -62,6 +62,10 @@ def process_qa_results(input_path: str) -> list[str]:total_cache_read_tokens = 0 # cacheReadtotal_output_tokens = 0 # output_tokenstotal_input_tokens = 0 # no_cache + cacheRead+ total_elapsed_seconds = 0.0+ min_elapsed_seconds = None+ max_elapsed_seconds = None+ elapsed_rows = 0valid_rows = 0with open(input_path, "r", encoding="utf-8", newline="") as f:@@ -94,6 +98,31 @@ def process_qa_results(input_path: str) -> list[str]:except (ValueError, TypeError):pass+ # 统计耗时(仅在字段存在且可解析时计入,避免缺失值按 0 拉低均值)+ try:+ elapsed_raw = row.get("elapsed_seconds")+ if elapsed_raw is None:+ continue+ elapsed_text = str(elapsed_raw).strip()+ if not elapsed_text:+ continue++ elapsed_seconds = float(elapsed_text)+ total_elapsed_seconds += elapsed_seconds+ min_elapsed_seconds = (+ elapsed_seconds+ if min_elapsed_seconds is None+ else min(min_elapsed_seconds, elapsed_seconds)+ )+ max_elapsed_seconds = (+ elapsed_seconds+ if max_elapsed_seconds is None+ else max(max_elapsed_seconds, elapsed_seconds)+ )+ elapsed_rows += 1+ except (ValueError, TypeError):+ pass+total_graded = correct + wrongaccuracy = correct / total_graded if total_graded > 0 else 0.0@@ -102,6 +131,7 @@ def process_qa_results(input_path: str) -> list[str]:avg_cache_read = total_cache_read_tokens / valid_rows if valid_rows > 0 else 0.0avg_output = total_output_tokens / valid_rows if valid_rows > 0 else 0.0avg_total_input = total_input_tokens / valid_rows if valid_rows > 0 else 0.0+ avg_elapsed_seconds = total_elapsed_seconds / elapsed_rows if elapsed_rows > 0 else 0.0return ["=== Judge Result Statistics (excluding category=5) ===",@@ -110,6 +140,11 @@ def process_qa_results(input_path: str) -> list[str]:f"Correct: {correct:,}",f"Wrong: {wrong:,}",f"Accuracy: {accuracy:.2%}",+ f"\nElapsed time (QA):",+ f" Total elapsed seconds: {total_elapsed_seconds:,.3f}",+ f" Avg elapsed seconds: {avg_elapsed_seconds:,.3f}",+ f" Min elapsed seconds: {(min_elapsed_seconds or 0.0):,.3f}",+ f" Max elapsed seconds: {(max_elapsed_seconds or 0.0):,.3f}",f"\nToken usage (QA):",f" Total no-cache tokens (input_tokens): {total_no_cache_tokens:,}",f" Total cacheRead tokens: {total_cache_read_tokens:,}",diff --git a/bot/vikingbot/agent/loop.py b/bot/vikingbot/agent/loop.pyindex 210b2cb87..32c9cdfbb 100644--- a/bot/vikingbot/agent/loop.py+++ b/bot/vikingbot/agent/loop.py@@ -4,6 +4,7 @@ from __future__ import annotationsimport asyncioimport json+import reimport timefrom contextlib import AsyncExitStackfrom pathlib import Path@@ -492,7 +493,9 @@ class AgentLoop:# Handle slash commandsis_group_chat = msg.metadata.get("chat_type") == "group" if msg.metadata else Falseif is_group_chat:- cmd = msg.content.replace(f"@{msg.sender_id}", "").strip().lower()+ cmd = msg.content+ cmd = re.sub(r'^\[[^\]]+\]:\s*', '', cmd)+ cmd = cmd.replace(f"@{msg.sender_id}", "").strip().lower()else:cmd = msg.content.strip().lower()if cmd == "/new":diff --git a/openviking/session/compressor.py b/openviking/session/compressor.pyindex 5d61f0669..c8edd24ab 100644--- a/openviking/session/compressor.py+++ b/openviking/session/compressor.py@@ -17,6 +17,7 @@ from openviking.server.identity import RequestContextfrom openviking.storage import VikingDBManagerfrom openviking.storage.viking_fs import get_viking_fsfrom openviking.telemetry import get_current_telemetry+from openviking.telemetry.request_wait_tracker import get_request_wait_trackerfrom openviking_cli.session.user_id import UserIdentifierfrom openviking_cli.utils import get_logger@@ -116,6 +117,8 @@ class SessionCompressor:queue_manager = get_queue_manager()semantic_queue = queue_manager.get_queue(queue_manager.SEMANTIC, allow_create=True)+ telemetry = get_current_telemetry()+ request_wait_tracker = get_request_wait_tracker()for parent_uri, changes in self._pending_semantic_changes.items():changes_dict = {@@ -132,8 +135,11 @@ class SessionCompressor:agent_id=ctx.user.agent_id,role=ctx.role.value,changes=changes_dict,+ telemetry_id=telemetry.telemetry_id,)await semantic_queue.enqueue(msg)+ if msg.telemetry_id:+ request_wait_tracker.register_semantic_root(msg.telemetry_id, msg.id)logger.info(f"Enqueued semantic generation for {parent_uri} with changes: "f"added={len(changes['added'])}, modified={len(changes['modified'])}, "@@ -162,6 +168,7 @@ class SessionCompressor:from openviking_cli.utils.config import get_openviking_configsemantic = get_openviking_config().semantic+ request_wait_tracker = get_request_wait_tracker()vectorize_text = memory.get_vectorization_text()if vectorize_text and len(vectorize_text) > semantic.memory_chunk_chars:@@ -184,11 +191,19 @@ class SessionCompressor:chunk_memory.set_vectorize(Vectorize(text=chunk))chunk_msg = EmbeddingMsgConverter.from_context(chunk_memory)if chunk_msg:- await self.vikingdb.enqueue_embedding_msg(chunk_msg)+ enqueued = await self.vikingdb.enqueue_embedding_msg(chunk_msg)+ if enqueued and chunk_msg.telemetry_id:+ request_wait_tracker.register_embedding_root(+ chunk_msg.telemetry_id, chunk_msg.id+ )# Always enqueue the base record (uses abstract as vector text)embedding_msg = EmbeddingMsgConverter.from_context(memory)- await self.vikingdb.enqueue_embedding_msg(embedding_msg)+ enqueued = await self.vikingdb.enqueue_embedding_msg(embedding_msg)+ if enqueued and embedding_msg.telemetry_id:+ request_wait_tracker.register_embedding_root(+ embedding_msg.telemetry_id, embedding_msg.id+ )logger.info(f"Enqueued memory for vectorization: {memory.uri}")self._record_semantic_change(memory.uri, change_type, parent_uri=memory.parent_uri)diff --git a/openviking/session/memory/memory_updater.py b/openviking/session/memory/memory_updater.pyindex 4c8bf5dde..ebc065c58 100644--- a/openviking/session/memory/memory_updater.py+++ b/openviking/session/memory/memory_updater.py@@ -27,6 +27,7 @@ from openviking.session.memory.utils import (from openviking.storage.viking_fs import get_viking_fsfrom openviking.telemetry import tracerfrom openviking.utils.time_utils import parse_iso_datetime+from openviking.telemetry.request_wait_tracker import get_request_wait_trackerfrom openviking_cli.exceptions import NotFoundErrorfrom openviking_cli.utils import get_logger@@ -500,6 +501,7 @@ class MemoryUpdater:returnviking_fs = self._get_viking_fs()+ request_wait_tracker = get_request_wait_tracker()# Collect all URIs to vectorize (skip .overview.md and .abstract.md - they are handled separately)uris_to_vectorize = []@@ -544,7 +546,11 @@ class MemoryUpdater:# Convert to embedding msg and enqueueembedding_msg = EmbeddingMsgConverter.from_context(memory_context)if embedding_msg:- await self._vikingdb.enqueue_embedding_msg(embedding_msg)+ enqueued = await self._vikingdb.enqueue_embedding_msg(embedding_msg)+ if enqueued and embedding_msg.telemetry_id:+ request_wait_tracker.register_embedding_root(+ embedding_msg.telemetry_id, embedding_msg.id+ )logger.debug(f"Enqueued memory for vectorization: {uri}")except Exception as e:diff --git a/openviking/session/session.py b/openviking/session/session.pyindex a9da3d441..c05a8646e 100644--- a/openviking/session/session.py+++ b/openviking/session/session.py@@ -17,6 +17,7 @@ from openviking.core.namespace import canonical_session_urifrom openviking.message import Message, Partfrom openviking.server.identity import RequestContext, Rolefrom openviking.telemetry import get_current_telemetry, tracer+from openviking.telemetry.request_wait_tracker import get_request_wait_trackerfrom openviking.utils.time_utils import get_current_timestampfrom openviking_cli.session.user_id import UserIdentifierfrom openviking_cli.utils import get_logger, run_async@@ -30,6 +31,7 @@ if TYPE_CHECKING:logger = get_logger(__name__)_ARCHIVE_WAIT_POLL_SECONDS = 0.1+_PHASE2_QUEUE_WAIT_TIMEOUT_SECONDS = 1800.0@dataclass@@ -535,12 +537,14 @@ class Session:from openviking.service.task_tracker import get_task_trackerfrom openviking.storage.transaction import get_lock_managerfrom openviking.telemetry import OperationTelemetry, bind_telemetry+ from openviking.telemetry.registry import register_telemetry, unregister_telemetrytracker = get_task_tracker()memories_extracted: Dict[str, int] = {}active_count_updated = 0telemetry = OperationTelemetry(operation="session_commit_phase2", enabled=True)+ request_wait_tracker = get_request_wait_tracker()archive_index = self._archive_index_from_uri(archive_uri)redo_task_id: Optional[str] = None@@ -563,96 +567,119 @@ class Session:returntracker.start(task_id)- with bind_telemetry(telemetry):- # redo-log protection- redo_task_id = str(uuid.uuid4())- redo_log = get_lock_manager().redo_log- redo_log.write_pending(- redo_task_id,- {- "archive_uri": archive_uri,- "session_uri": self._session_uri,- "account_id": self.ctx.account_id,- "user_id": self.ctx.user.user_id,- "agent_id": self.ctx.user.agent_id,- "role": self.ctx.role.value,- },- )-- latest_archive_overview = await self._get_latest_completed_archive_overview(- exclude_archive_uri=archive_uri- )-- # Generate summary and write L0/L1 to archive- summary = await self._generate_archive_summary_async(- messages,- latest_archive_overview=latest_archive_overview,- )- if self._viking_fs and summary:- abstract = self._extract_abstract_from_summary(summary)- await self._viking_fs.write_file(- uri=f"{archive_uri}/.abstract.md",- content=abstract,- ctx=self.ctx,- )- await self._viking_fs.write_file(- uri=f"{archive_uri}/.overview.md",- content=summary,- ctx=self.ctx,- )- await self._viking_fs.write_file(- uri=f"{archive_uri}/.meta.json",- content=json.dumps(- {- "overview_tokens": -(-len(summary) // 4),- "abstract_tokens": -(-len(abstract) // 4),- }- ),- ctx=self.ctx,+ request_wait_tracker.register_request(telemetry.telemetry_id)+ register_telemetry(telemetry)+ try:+ with bind_telemetry(telemetry):+ # redo-log protection+ redo_task_id = str(uuid.uuid4())+ redo_log = get_lock_manager().redo_log+ redo_log.write_pending(+ redo_task_id,+ {+ "archive_uri": archive_uri,+ "session_uri": self._session_uri,+ "account_id": self.ctx.account_id,+ "user_id": self.ctx.user.user_id,+ "agent_id": self.ctx.user.agent_id,+ "role": self.ctx.role.value,+ },)- # Memory extraction- if self._session_compressor:- logger.info(- f"Starting memory extraction from {len(messages)} archived messages"+ latest_archive_overview = await self._get_latest_completed_archive_overview(+ exclude_archive_uri=archive_uri)- extracted = await self._session_compressor.extract_long_term_memories(- messages=messages,- user=self.user,- session_id=self.session_id,- ctx=self.ctx,++ # Generate summary and write L0/L1 to archive+ summary = await self._generate_archive_summary_async(+ messages,latest_archive_overview=latest_archive_overview,)- logger.info(f"Extracted {len(extracted)} memories")- for ctx_item in extracted:- cat = getattr(ctx_item, "category", "") or "unknown"- memories_extracted[cat] = memories_extracted.get(cat, 0) + 1- self._stats.memories_extracted += len(extracted)- get_current_telemetry().set("memory.extracted", len(extracted))-- # Write relations (using snapshot, not self._usage_records)- if self._viking_fs:- for usage in usage_records:- try:- await self._viking_fs.link(self._session_uri, usage.uri, ctx=self.ctx)- except Exception as e:- logger.warning(f"Failed to create relation to {usage.uri}: {e}")-- redo_log.mark_done(redo_task_id)-- # Update active_count (using snapshot, not self._usage_records)- if self._vikingdb_manager:- uris = [u.uri for u in usage_records if u.uri]- try:- active_count_updated = await self._vikingdb_manager.increment_active_count(- self.ctx, uris+ if self._viking_fs and summary:+ abstract = self._extract_abstract_from_summary(summary)+ await self._viking_fs.write_file(+ uri=f"{archive_uri}/.abstract.md",+ content=abstract,+ ctx=self.ctx,)- except Exception as e:- logger.debug(f"Could not update active_count for usage URIs: {e}")- if active_count_updated > 0:+ await self._viking_fs.write_file(+ uri=f"{archive_uri}/.overview.md",+ content=summary,+ ctx=self.ctx,+ )+ await self._viking_fs.write_file(+ uri=f"{archive_uri}/.meta.json",+ content=json.dumps(+ {+ "overview_tokens": -(-len(summary) // 4),+ "abstract_tokens": -(-len(abstract) // 4),+ }+ ),+ ctx=self.ctx,+ )++ # Memory extraction+ if self._session_compressor:logger.info(- f"Updated active_count for {active_count_updated} contexts/skills"+ f"Starting memory extraction from {len(messages)} archived messages")+ extracted = await self._session_compressor.extract_long_term_memories(+ messages=messages,+ user=self.user,+ session_id=self.session_id,+ ctx=self.ctx,+ latest_archive_overview=latest_archive_overview,+ )+ logger.info(f"Extracted {len(extracted)} memories")+ for ctx_item in extracted:+ cat = getattr(ctx_item, "category", "") or "unknown"+ memories_extracted[cat] = memories_extracted.get(cat, 0) + 1+ self._stats.memories_extracted += len(extracted)+ get_current_telemetry().set("memory.extracted", len(extracted))++ # Write relations (using snapshot, not self._usage_records)+ if self._viking_fs:+ for usage in usage_records:+ try:+ await self._viking_fs.link(self._session_uri, usage.uri, ctx=self.ctx)+ except Exception as e:+ logger.warning(f"Failed to create relation to {usage.uri}: {e}")++ redo_log.mark_done(redo_task_id)++ # Update active_count (using snapshot, not self._usage_records)+ if self._vikingdb_manager:+ uris = [u.uri for u in usage_records if u.uri]+ try:+ active_count_updated = await self._vikingdb_manager.increment_active_count(+ self.ctx, uris+ )+ except Exception as e:+ logger.debug(f"Could not update active_count for usage URIs: {e}")+ if active_count_updated > 0:+ logger.info(+ f"Updated active_count for {active_count_updated} contexts/skills"+ )++ try:+ await request_wait_tracker.wait_for_request(+ telemetry.telemetry_id,+ timeout=_PHASE2_QUEUE_WAIT_TIMEOUT_SECONDS,+ )+ except TimeoutError as exc:+ telemetry.set_error(+ "session.commit.phase2.wait_for_request",+ "DEADLINE_EXCEEDED",+ str(exc),+ )+ logger.warning(+ "Timed out waiting for request-scoped queues for telemetry_id=%s after %.1fs; continuing phase2 completion",+ telemetry.telemetry_id,+ _PHASE2_QUEUE_WAIT_TIMEOUT_SECONDS,+ )+ finally:+ request_wait_tracker.cleanup(telemetry.telemetry_id)+ unregister_telemetry(telemetry.telemetry_id)# Phase 2 complete — update meta with telemetry and commit infosnapshot = telemetry.finish("ok")