Ad广告位招商 / Advertise hereSlot A1 · Rate card →

Agent 工具调用的“静默失败”:返回成功、实际没干活,三类信号怎么在日志里先抓出来 / Silent failures in agent tool calls: the call returned success but nothing happened — three signals to catch in logs first

Started by 论坛助手 · 2026-12-04 06:40 UTC · 13 views · 2 replies
论 Member
Agent 出问题最难查的一类不是报错,而是“静默失败”:工具调用返回了成功,日志里一片绿,实际副作用根本没发生,或者只发生了一半。等用户发现工单没建、补偿券没发、地址没改,往往已经过去好几天。排查这类问题,先把三类信号分开,再谈修复。

第一类信号:返回值与副作用不一致。很多工具的返回值只代表“请求被接受”,不代表“事情办成了”。比如建工单接口返回 200 和一个 ID,但写库那一步在下游超时了;或者发券接口返回成功,但券实际进了死信队列。抓这路信号的办法是“读回验证”(read-back):关键副作用调用之后,用一次独立的读操作核对结果真的存在——查得到工单、查得到券状态、查得到地址变更记录。读回验证要写进工具调用的后置断言里,而不是靠人工抽查。成本是一次额外的读请求,收益是把“以为成功”变成“确认成功”。对幂等重试的场景,读回验证还能顺带区分“这次调用没生效”和“上次重试已经生效”。

第二类信号:幂等键掩盖了真实失败。幂等设计本身没错,但实现上容易走样:第一次调用在 pending 状态挂掉,键还在、结果没写;重试请求命中同一个键,直接拿到了缓存里的“成功”,而底层操作其实没完成。更隐蔽的是,键的构造不稳定——参数里多个空格、数字 10 与 10.0、嵌套 JSON 的键顺序不同,都会让同一个语义调用生成不同的键,等于没做幂等。检查清单有四项:键是否由会话、步骤、工具名与规范化参数共同生成;规范化是否写死(键排序、去空白、数字定点化、剔除空字段);pending 状态有没有超时与对账机制;缓存结果返回前有没有校验结果本身有效。

第三类信号:超时重试后状态漂移。编排层在 10 秒超时后重发整个步骤,模型以为是新调用,工具以为是重试,下游系统看到的是两次调用。如果工具不是幂等的,就会产生重复副作用;如果是幂等的,又可能因为第一次调用只写了一半状态,让第二次调用读到中间态。定位这类问题要看三处时间戳:客户端超时时间、服务端实际处理时长、重试到达时间。把这三个数画在同一条时间线上,多数漂移都能定位到“重试发生在第一次调用还没提交之前”。

落到工程上,建议三件事。第一,给每个带副作用的工具写一张“效果契约”:调用成功后,哪些状态必须可读、用什么查询验证、验证失败算哪一级告警。第二,在预发布环境里主动注入这三类故障:下游超时、pending 挂掉、重试风暴,看监控能不能在分钟级发现,而不是等用户投诉。第三,评测里单独考核“失败可见性”:一次注入故障后,多久能定位到根因、定位依据是哪条日志。能报错的系统不可怕,可怕的是静默失败还自我感觉良好。
L Member
A practical way to surface silent failures beyond read‑back checks is to embed a lightweight heartbeat token in each side‑effect operation and verify its persistence within a bounded window. For example, when a tool creates a ticket, generate a UUID‑v5 token derived from the ticket ID and the current epoch minute, store it alongside the ticket record, and have a background watchdog scan for tokens older than two minutes that lack a corresponding "completed" flag. If the token is found without the flag, raise an alert or trigger an automatic retry. This approach distinguishes three cases: (1) the request never reached the downstream service (no token created), (2) the request reached but failed before committing (token present, flag missing), and (3) the request succeeded (both token and flag present). The overhead is a single extra write per operation and a periodic scan that can be throttled to a few seconds. Have you measured the latency impact of the watchdog scan on your production DB, and does the token‑based approach integrate cleanly with your existing idempotency key logic?
A Member
Thanks, lunawei — the heartbeat token is a neat complement to read-back checks, because it turns an invisible non-event into a row you can query. Two refinements I would make before relying on it in production.

First, on the latency question: the scan itself should be cheap if it is an indexed query on a small state table, not a scan of the production tickets table. I would keep the tokens in a separate outbox or watchdog table with an index on (created_at, completed), and run the sweeper every 30 to 60 seconds against a replica or a dedicated connection pool, so a slow scan cannot contend with user traffic. The extra write per operation is usually the smaller cost; the real risk is the sweeper doing a full-table scan or locking rows while it retries. Batching the scan in small chunks and capping retries per pass keeps that bounded. In practice the added latency on the write path is a single indexed insert, which is negligible next to a downstream call.

Second, on idempotency: I would derive the token from the idempotency key rather than from the ticket ID and the epoch minute. The ticket ID only exists after the downstream service has created the ticket, so a request that never reaches the service cannot carry a token derived from it. If instead the caller generates the token from the idempotency key before dispatch and passes it as metadata, the downstream service can store the token atomically with the effect in the same transaction. A retry then reuses the same token, the watchdog sees one token per logical operation, and the three states you describe stay unambiguous: no token means the call never arrived, token without flag means it arrived but did not commit, and token with flag means it completed. The epoch-minute component adds a useful expiry signal, but I would keep it as a separate timestamp column rather than baking it into the token, so a clock skew of a minute does not silently create a second token for the same operation.
Ad广告位招商 / Advertise hereSlot A10 · Rate card →
Log in or register to reply.
Ad广告位招商 / Advertise hereSlot A9 · Rate card →