Skip to content

fix: six findings from live perf-monitoring (#152 #153 #155 #156 #157 #158) - #160

Merged
JAORMX merged 6 commits into
mainfrom
fix/monitoring-findings
Jun 23, 2026
Merged

JAORMX merged 6 commits into
mainfrom
fix/monitoring-findings

Conversation

@JAORMX

@JAORMX JAORMX commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Six issues found while live-monitoring a running mecatui --perf session, each delivered through the dev pipeline (architect → separate implementer → parallel review panel → iterate → commit-per-issue). One commit per issue; full task lint/task test/api:check green on the complete branch.

Opened as a single PR so the live-e2e CI lane exercises the behavior fixes against real models — notably #152 (triggered by a slow reasoner, glm-5.2) and #155 (TTFT across real tool-call/reasoning turns).

Fixes

Notes

  • Pre-existing, unrelated: there are two ADRs numbered 0041 on main (direct-write-subagent, output-economy-default-prompt) — flagged for a separate cleanup, not touched here.

🤖 Generated with Claude Code

JAORMX and others added 6 commits June 23, 2026 13:21
…ogress terminals

A free-text Subagent that ended StopNoProgress or an empty StopEndTurn
returned the opaque "(subagent produced no summary)", discarding the
child's work. Slow reasoning models (e.g. glm-5.2 via the router) emit
reasoning-only/empty turns, exhaust the no-progress nudges, and hit
StopNoProgress with empty final text — so whole delegated branches came
back empty.

- Widen the salvage trigger (salvageEmptyLimitStop -> salvageEmptyStop)
  to any empty terminal stop via isEmptyTerminalStop {MaxTurns,
  MaxToolCalls, Budget, NoProgress, EndTurn}; ResetUsage stays scoped to
  StopBudget only (NoProgress/EndTurn must keep the carried budget as the
  salvage-turn brake).
- Last-resort digestChildActivity: recover the child's last assistant
  text when salvage yields nothing.
- StopNoProgress note names the reason and points at recovery; the
  worst-case placeholder is no longer a dead end (resume via agentId).
- Result always carries the agentId trailer; never silently empty.

Closes #152

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The Bash tool discarded the partial stdout/stderr the runner had already
captured when Run returned a ctx error, telling the model only
"command failed to run: <err>". A command that produced useful output
before timing out gave the model nothing actionable.

- Surface captured res.Stdout/res.Stderr on the runner-error path, with a
  classified reason trailer: timeout (naming timeout_ms only when set —
  never fabricating the runner's private default), cancel, no-shell, or
  generic. Result stays is_error so the model adapts.
- Trailer is composed AFTER budgeting/truncating the body, so a runaway
  timed-out command (huge output) never loses its timeout signal to the
  25000-byte cap. Export toolkit.TruncationMarker as the single source of
  truth for the reservation.
- Do not print "[exit code: 0]" on the ctx-error path (it reads as
  success); the trailer is the status signal there.
- bashDescription documents the behavior and that cancel/no-shell are not
  retryable (only timeouts are).

Closes #153

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…deltas

mecatl_ttft_seconds never recorded for tool-call-first or
reasoning-replay-blob turns: the TTFT anchor (noteContent) fired only on
ChunkText/ChunkReasoning display deltas, so pure tool-call turns (the bulk
of an agentic run) and reasoning-delivered-as-encrypted-blob turns left
TTFTMs=0 and the telemetry >0 guard skipped every observation — the
histogram never materialized.

- Split the dual-duty noteContent into a turnLatency value object:
  noteFirstOutput (TTFT anchor on the FIRST observable output of any kind,
  first-only) and noteStreamDelta (inter-token gap accounting on genuine
  text/reasoning deltas only). ChunkToolCall/ChunkReasoningItem now anchor
  TTFT; ChunkText/ChunkReasoning seed the gap series. One clock read per
  delta preserved (byte-identical gap timing); a scripted-clock over-read
  oracle pins that parity (mutation-tested).
- Gap series stays pure (a tool call never appends a spurious inter-token
  gap), proven for both empty and non-empty series.
- TTFT now means "time to first observable output (text, reasoning,
  reasoning replay item, or tool call)"; event.go field doc + the metric
  description reworded (instrument name unchanged). ChunkPhase/Usage/Done
  still do not anchor.

Closes #155

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…"skipped"

Agent defs ported from other harnesses were silently truncated and logged
as "agent def skipped", which reads as "not loaded" — but the def was kept
and functional, just clipped.

- Raise the caps asymmetrically by blast radius: MaxAgentBodyBytes
  8KiB -> 32KiB (cheap — in-context only for that one specialist engine,
  covers 10-20KB ported specialist prompts), MaxAgentDescriptionBytes
  800 -> 2000 (expensive — rides every request x all agents on the
  byte-stable prompt-cache prefix, so kept conservative). One-time
  deterministic cache-prefix invalidation. (engine API const values
  changed -> api:update + engine/CHANGELOG.md, classified Changed.)
- Replace the overloaded "agent def skipped" WARN with a STRUCTURAL split:
  SkipError.Fatal (set at the def-excluding sites) drives "agent def
  dropped" (excluded) vs "agent def adjusted" (kept), the latter carrying
  outcome="agent still loaded" so the operator knows it is usable. A
  closed-set classification test fails loudly if a future fatal site
  forgets Fatal:true.
- Constants-only (no configurable override); deferred-config path noted.

Closes #156

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…antiles

The latency instruments used base-2 exponential-histogram views, which the
otel-prometheus exporter renders as native histograms — in the classic
text exposition (a plain `curl :9099/metrics`) those show only le="+Inf",
so a human/promtool could not get p50/p90/p99. (The perf-MCP reducer
already reconstructed quantiles from the native fields, so the agent path
was fine; only the human text path was blind.)

- Switch the latency instruments to explicit-bucket histograms with a
  ms-to-minutes ladder {0.001 .. 300}s, so /metrics, promtool, and the MCP
  reducer all yield real le= buckets and quantiles with zero scrape config.
  The lost exponential-tail precision is unconsumed today (no OTLP metrics
  reader is wired).
- Verified all six latency record sites feed SECONDS (msToSeconds /
  Duration.Seconds), so the ms-scale low-end buckets have real resolution;
  an end-to-end ms-resolution test now guards that conversion.
- New ADR 0045 supersedes ADR 0018 §5 decision 2 (histogram aggregation
  only); 0018's body is unchanged (status pointer added).

Closes #158

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…measurement gap

Live monitoring fingered main-turn allocation churn (per-turn full
conversation re-marshal + SSE decode), but that path had ZERO offline
benchmark coverage — every bench drives mockllm, which bypasses the
adapter request-assembly and decode entirely — so the hypothesis could
never be ranked.

- Add internal/adapter/{anthropic,openai}/request_bench_test.go: benchmark
  buildParams/buildMessages/buildInput (our glue), buildParams+json.Marshal
  (the full per-turn re-marshal), and the test-only decodeSSE/translate
  glue, over synthetic 50/200/500-message conversations.
- Profile (alloc_objects) verdict: the per-turn re-marshal is ~92%
  (anthropic) / ~87% (openai) the provider SDK's reflection-based
  json.Marshal — code we don't own — with our glue a small, already
  capacity-presized remainder. No byte-identical win exists in our glue
  without risking the byte-stable prompt-cache prefix. So: gap closed,
  NO source change (matches the GC-absorbed live data: pauses <=262us).
- The benches are a runnable human A/B / regression guard; deliberately
  NOT wired into the fail-closed allocs-gate (an SDK-dominated number
  shifts on SDK bumps); glue-only gating noted as a follow-up.

Closes #157

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@JAORMX JAORMX added the e2e-live Run the live e2e suite on this PR label Jun 23, 2026
@JAORMX
JAORMX merged commit ee5ae1a into main Jun 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment