Skip to content

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: Delayed push timed response failure.

wncbdj15cd33e3ac6c
diff --git a/jiuwenclaw/agentserver/tools/cron_tools.py b/jiuwenclaw/agentserver/tools/cron_tools.py
index bc00aac776..0f3873821f 100644
--- a/jiuwenclaw/agentserver/tools/cron_tools.py
+++ b/jiuwenclaw/agentserver/tools/cron_tools.py
@@ -87,7 +87,7 @@ class CronTools:
if agent_client is None:
try:
agent_client = AgentServerClient.get_instance()
- except RuntimeError:
+ except (RuntimeError, AttributeError):
agent_client = None
if message_handler is None:
diff --git a/jiuwenclaw/config.py b/jiuwenclaw/config.py
index d09980991a..b9c6c6f8e5 100644
--- a/jiuwenclaw/config.py
+++ b/jiuwenclaw/config.py
@@ -76,12 +76,14 @@ def resolve_env_vars(value: Any) -> Any:
return value
-def _normalize_config(config: dict[str, Any]) -> None:
+def _normalize_config(config: dict[str, Any] | None) -> None:
"""后处理配置,将需要结构化的字符串字段解析为原生类型。
例如 custom_headers 在 YAML 中通过环境变量传入时是 JSON 字符串,
需要统一解析为 dict。
"""
+ if config is None:
+ return
models = config.get("models", {})
if isinstance(models, dict):
for entry in models.values():
@@ -99,7 +101,7 @@ def _normalize_config(config: dict[str, Any]) -> None:
def get_config():
with open(get_config_file(), "r", encoding="utf-8") as f:
- config_base = yaml.safe_load(f)
+ config_base = yaml.safe_load(f) or {}
config_base = resolve_env_vars(config_base)
_normalize_config(config_base)
diff --git a/jiuwenclaw/gateway/cron/models.py b/jiuwenclaw/gateway/cron/models.py
index 8f62c93fcd..69779a3ab1 100644
--- a/jiuwenclaw/gateway/cron/models.py
+++ b/jiuwenclaw/gateway/cron/models.py
@@ -237,3 +237,8 @@ class CronRunState:
finished_at: float | None = None
result_text: str | None = None
error: str | None = None
+ job_name: str | None = None
+ targets: str | None = None
+ session_id: str | None = None
+ chat_type: str | None = None
+ timezone: str | None = None
diff --git a/jiuwenclaw/gateway/cron/scheduler.py b/jiuwenclaw/gateway/cron/scheduler.py
index 7916df4456..63de1181eb 100644
--- a/jiuwenclaw/gateway/cron/scheduler.py
+++ b/jiuwenclaw/gateway/cron/scheduler.py
@@ -276,8 +276,25 @@ class CronSchedulerService:
async def _handle_event(self, ev: _Event) -> None:
job = self._jobs.get(ev.job_id)
- if job is None:
+ if job is None and ev.kind != "push_update":
return
+ if job is None and ev.kind == "push_update":
+ state = self._runs.get(ev.run_id)
+ if state is None:
+ logger.info("[Cron] push_update skipped: no state and no job job_id=%s run_id=%s", ev.job_id, ev.run_id)
+ return
+ job = CronJob(
+ id=state.job_id,
+ name=state.job_name or "",
+ enabled=False,
+ expired=False,
+ cron_expr="",
+ timezone=state.timezone or "Asia/Shanghai",
+ targets=state.targets or "",
+ session_id=state.session_id,
+ chat_type=state.chat_type,
+ )
+ logger.info("[Cron] push_update using rebuilt job from state job_id=%s run_id=%s", ev.job_id, ev.run_id)
# push_update 是对已触发任务的补发,即使单次任务已过期也必须放行,否则真正结果永远发不出去
if not job.enabled and ev.kind != "push_update":
return
@@ -332,6 +349,11 @@ class CronSchedulerService:
job_id=job.id,
wake_at_iso=wake_dt.isoformat(),
push_at_iso=push_dt.isoformat(),
+ job_name=job.name,
+ targets=job.targets,
+ session_id=job.session_id,
+ chat_type=job.chat_type,
+ timezone=job.timezone,
)
self._runs[run_id] = state
@@ -422,6 +444,11 @@ class CronSchedulerService:
job_id=job.id,
wake_at_iso=wake_dt.isoformat(),
push_at_iso=push_dt.isoformat(),
+ job_name=job.name,
+ targets=job.targets,
+ session_id=job.session_id,
+ chat_type=job.chat_type,
+ timezone=job.timezone,
)
self._runs[run_id] = state