Skip to content

evals product practices b

sherry-wiki edited this page Nov 23, 2026 · 1 revision

🛡️ B-Class Eval Practices in the Product

Sherry Wiki · English · 中文 · 日本語 · 한국어

← Back to index

Four fail-open hardening practices promoted from eval-harness observations (external-bench / DeepSWE) and from measured product failure modes. Unlike the A-class set, these are observability / guard rails: none changes the decision path of an existing gate, and each degrades to a no-op on failure. Source of truth: the files listed under each section.

1. PathGuard denial accounting (agent/middlewares/path_guard/core.py, server/service/turn_runner.py)

A blocked tool call returns a normal error ToolMessage, so an agent looping on a PathGuard rejection produced hundreds of calls with no visible reason. PathGuard now records a per-session denial tally (record_denial → _PATH_DENIALS) at both the sync and async rejection branches — count plus the distinct rejected paths. At turn end, on_turn_finished drains the tally (one-shot) and pushes a transient system.notice card (title literal: PathGuard 拒绝了写/读操作) with the count and up to five paths. The notice uses the existing in-chat notice strip, so no new socket frame or toast handler was added. Session teardown calls clear_denials so a deleted session leaves no residue. The decision path is unchanged: the tally is observability only, empty session ids are not counted, and a drain returns None when there was nothing to report.

2. Wait-only directive for in-flight steps (agent/middlewares/todo_continuation/core.py)

The plan-continuation enforcer used to say "continue working on the next pending task" even while TaskFlow step children were still running — an agent could declare completion with four children mid-flight. When _has_in_flight_steps(flows) is true (any step dispatched or ready), the gate now selects [SYSTEM DIRECTIVE: STEPS IN FLIGHT] instead: call taskflow_step(action='wait_all'), then resume the settled steps, close the flow with taskflow_flow(action='finish'), and do not declare completion or start new work until every child has settled. The ordinary continuation is used when nothing is in flight; blocked-only still applies to the all-blocked shape (in-flight and blocked are disjoint). The status block and board footer are retained — the directive narrows the decision, it does not hide the rest of the plan.

3. Reminder snapshot across compression (agent/middlewares/reminder_catalog/dynamic.py, agent/middlewares/summarization/compression.py)

A mid-turn compression replaced the whole cutoff window — including every <system-reminder> inside it — with a summary pair, leaving the model to execute the rest of the turn with no todo/TaskFlow anchor. After truncation (and before recovery-context rewriting), the compression pipeline now calls capture_reminder_snapshot and inserts the result between the summary pair and the preserved tail: [summary, snapshot, preserved…]. The snapshot is the compression-time version of the last non-transient reminder per source — not live state — so the model sees a timeline: summary → state at compaction → newer preserved reminders. Transient sources (current_time, lsp_diagnostics, project_instructions) are never captured. Per source, a snapshot byte-identical to the oldest preserved reminder is dropped (pure redundancy); comparing to the oldest — not the newest — avoids deleting a snapshot when state changed and changed back. The snapshot is lazy-imported, runs only when a summary pair was actually built, and fails open to "no snapshot" on any error. The dynamic reminder middleware, its guards and the next turn's injection are untouched.

4. Aggregate size guard for a parallel tool batch (agent/safe_tool_node.py, pub/func/message/eviction.py, config/features/agent_side/tool_parallel.py)

ContextEviction evicts per call inside the tool node, so N parallel results each just under its 20K-char threshold all survive and their sum blows the context window — no per-call hook sees the total. SafeToolNode now applies _enforce_batch_size_limit at the only point that holds the whole batch: after gather, before _combine_tool_outputs, on all four enforce/non-enforce × sync/async paths. When the sum exceeds TOOL_PARALLEL["batch_result_threshold_chars"] (default 100K, 0 disables), the largest results are evicted first via the existing evict_tool_result (disk offload + head/tail preview), falling back to hard_clip_tool_result (memory clip), until the batch fits or no more can be shrunk. Both helpers take a force=True keyword for this path so a single 19K result can be evicted despite being under the 20K per-call threshold; default callers are byte-for-byte unchanged. Already-evicted results and zero-size items are skipped; order and count are preserved; every failure keeps the original result. A disk preview carries a ~4K-char floor, so a very large batch is reduced by several times rather than forced under the threshold at the cost of all signal. The async path runs the guard via asyncio.to_thread so the event loop never blocks. The existing read_file recovery hint was corrected to offset=1 (the tool is 1-indexed).

Safety invariants

  • All four are additive: no existing prompt contract, middleware order, tool schema, state key or turn-lifecycle hook changed incompatibly.
  • Every read/guard path is fail-open: a missing session id, empty tally, broken store, capture error or failed offload degrades to "no signal / keep original", never a hard failure.
  • Thresholds live in TOOL_PARALLEL; the wait-only rule reuses the existing _has_in_flight_steps predicate; the snapshot reuses the reminder catalogue's transient-source registry. No magic numbers in the hot path.

Clone this wiki locally