JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(cron): propagate user_id for AgentOS sandbox routing
yechenzhen87677beaab93
diff --git a/jiuwenswarm/agents/harness/common/tools/cron/cron_tools.py b/jiuwenswarm/agents/harness/common/tools/cron/cron_tools.pyindex a638527938..cec57fa800 100644--- a/jiuwenswarm/agents/harness/common/tools/cron/cron_tools.py+++ b/jiuwenswarm/agents/harness/common/tools/cron/cron_tools.py@@ -652,6 +652,7 @@ class CronTools:work_mode=work_mode,service_id=self._service_id,agent_id=self._agent_id,+ user_id=str(normalized.get("user_id") or "").strip(),**session_kw,**mode_kw,**model_kw,diff --git a/jiuwenswarm/gateway/channel_manager/tui/tui_connect.py b/jiuwenswarm/gateway/channel_manager/tui/tui_connect.pyindex 449e370fdd..5f6297c93a 100644--- a/jiuwenswarm/gateway/channel_manager/tui/tui_connect.py+++ b/jiuwenswarm/gateway/channel_manager/tui/tui_connect.py@@ -3134,7 +3134,7 @@ def register_cli_handlers(bind: CliHandlersBindParams) -> None:logger.warning("[cron.job.get] %s", exc)await channel.send_response(ws, req_id, ok=False, error=str(exc), code="INTERNAL_ERROR")- async def _cron_job_create(ws, req_id, params, session_id):+ async def _cron_job_create(ws, req_id, params, session_id, user_id=None):cc = _get_cron()if cc is None:await channel.send_response(ws, req_id, ok=False, error="cron not available", code="INTERNAL_ERROR")@@ -3145,6 +3145,10 @@ def register_cli_handlers(bind: CliHandlersBindParams) -> None:try:if session_id:params["session_id"] = session_id+ # 与 Web _cron_job_create 对齐:写入创建者,执行时透传 AgentOS X-Session-Context。+ uid = str(user_id or getattr(ws, "_gateway_user_id", None) or "").strip()+ if uid:+ params["user_id"] = uid# project_dir 默认值:TUI 前端已自动注入;仅当「未传」时从当前会话 metadata 兜底# 注意:显式传空串 "" 等价于归默认项目,不可覆盖——用 key presence 区分if "project_dir" not in params and session_id:diff --git a/jiuwenswarm/gateway/cron/scheduler.py b/jiuwenswarm/gateway/cron/scheduler.pyindex 44c7d1a242..29f2ae702f 100644--- a/jiuwenswarm/gateway/cron/scheduler.py+++ b/jiuwenswarm/gateway/cron/scheduler.py@@ -578,6 +578,7 @@ class CronSchedulerService:``cron_{job_id}`` 与真实会话不匹配,cancel 请求落不到点上。"""target_session_id = (state.exec_session_id or "").strip() or f"cron_{state.job_id}"+ job = self._jobs.get(state.job_id)try:interrupt_env = e2a_from_agent_fields(request_id=f"cron-cancel-{state.run_id}",@@ -587,6 +588,7 @@ class CronSchedulerService:params={"cron": {"job_id": state.job_id, "run_id": state.run_id}},is_stream=False,timestamp=self._now_fn(),+ user_id=str(getattr(job, "user_id", "") or "").strip() or None,)await self._agent_client.send_request(interrupt_env)logger.info(@@ -1289,6 +1291,7 @@ class CronSchedulerService:is_stream=False,timestamp=self._now_fn(),metadata={"cron": {"job_id": job.id, "run_id": ev.run_id}},+ user_id=str(job.user_id or "").strip() or None,)resp = await self._agent_client.send_request(envelope)