360 Secure SkillHub
360 安全技能中心

Cron Cost Guard

核心功能:检查AI代理定时任务的会话隔离冲突、模型配置矛盾、系统提示词超限及重试循环等token成本风险,提供修复方案。典型场景:新建定时任务、排查token消耗突增、多代理配置审计、成本异常复盘。支持触发词唤起,输出含检查命令、风险红标、修复步骤及量化指标,帮精准定位解决问题。

pouria3
pouria3
热度 36.68
最近更新 2026-05-11 17:38:51
分类:安全依赖:代码执行 / MCP 服务应用场景:DevOps / 财务 / 报告撰写

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add cron-cost-guard
Metadata
name
cron-cost-guard
description
Audit AI agent cron jobs for token cost risks, model-switch loops, and session isolation failures. Use when setting up new cron jobs, debugging unexpected token usage spikes, auditing multi-agent cron configurations, or after a cost anomaly. Triggers on "audit crons", "check cron costs", "token budget", "cron safety", "cost spike", "model switch error", "session isolation", "cron health check".

Cron Cost Guard

Prevent silent token budget burns from misconfigured AI agent cron jobs.

Quick Audit

Run this checklist on every cron setup or when investigating a cost spike:

1. Session Isolation (Critical)

Check every cron job for session binding conflicts:

cron list (includeDisabled: true)

Red flags:

  • sessionKey: "agent:main:main" with sessionTarget: "isolated" → stale binding, will cause model conflicts
  • agentId pointing to a different agent than the session owner → cross-agent model contamination
  • consecutiveErrors >= 3 → likely stuck in a retry loop
  • lastError containing LiveSessionModelSwitchError → model-switch loop confirmed

Fix: Remove and recreate the job without sessionKey. Set sessionTarget: "isolated".

2. Model Conflicts

In multi-agent setups (e.g., Agent A on Claude, Agent B on GPT), each agent's crons must be scoped to that agent only.

  • Set agentId explicitly on every cron job
  • Set model explicitly in the payload when available
  • Never let Agent B's cron inherit Agent A's session model

3. System Prompt Size

Audit injected workspace files:

wc -c MEMORY.md SOUL.md AGENTS.md TOOLS.md USER.md QUEUE.md

Target: < 20KB total injected. Move large files (playbooks, heartbeat templates, reference docs) to references/ for on-demand reading.

Size Status
< 20KB Healthy
20-40KB Trim soon
> 40KB Trim now — every API call is bloated

4. Cost Monitoring

sessions_list (limit: 10, messageLimit: 1)

Look for sessions with high estimatedCostUsd but low output tokens — that's a retry loop signature.

Metric Healthy Warning Critical
Cron consecutive errors 0 1-2 ≥3
Session cost (cron) < $0.50 $0.50-2.00 > $2.00
Model switch retries 0 1-2 ≥3

Diagnosis: Token Spike

For detailed diagnosis steps and post-incident checklist, read references/diagnosis.md.

Prevention Rules

  1. Every cron job: sessionTarget: "isolated", no stale sessionKey
  2. Every cron job: explicit timeoutSeconds (never unlimited)
  3. Multi-agent: explicit agentId matching the agent that should run it
  4. After changing default model: audit all cron jobs for conflicts
  5. Weekly: check consecutiveErrors across all jobs — anything ≥ 3 needs investigation