AGENT SKILL

field-log-duration-clustering-race-diagnosis

A device-only timing bug (e.g. speech recognition "no speech detected", NFC/AVFoundation timeouts) can't be reproduced in the Simulator, and you're about to ship a speculative fix for a suspected timer-arms-before-async-task-exists race with no evidence it's the real cause. Use when a hardware-gated framework (on-device Speech, CoreNFC, AVFoundation capture) fails intermittently only on real devices, you have structured diagnostic logs already recording per-attempt duration and outcome, and you need to confirm or refute a race hypothesis — and pick a numeric fix constant — without a repro.

License 许可
MIT
最近更新
2026-11-07
Stars
★ 1
Forks
1

01 前言 Front Matter

name
field-log-duration-clustering-race-diagnosis
description
A device-only timing bug (e.g. speech recognition "no speech detected", NFC/AVFoundation timeouts) can't be reproduced in the Simulator, and you're about to ship a speculative fix for a suspected timer-arms-before-async-task-exists race with no evidence it's the real cause. Use when a hardware-gated framework (on-device Speech, CoreNFC, AVFoundation capture) fails intermittently only on real devices, you have structured diagnostic logs already recording per-attempt duration and outcome, and you need to confirm or refute a race hypothesis — and pick a numeric fix constant — without a repro.

03 SKILL.md 正文

Field-Log Duration Clustering Confirms a Startup-Race Timeout Hypothesis

Symptom

A hardware-gated framework (on-device Speech recognition, CoreNFC, AVFoundation capture) intermittently times out or fails on real devices — e.g. .noSpeechDetected — with no way to reproduce it, because the framework doesn't run in the Simulator at all. You have a hypothesis ("the timeout timer arms before the async task it's supposed to be timing even exists, so it races startup/warm-up latency instead of detecting a genuine pause") but no way to test it, so any fix would ship purely speculative.

Root cause

A silence/timeout timer (e.g. armSilenceTimer()) is started before the guarded async operation (e.g. recognitionTask(with:)) is actually created. The timer's countdown therefore includes framework startup/warm-up latency, not just genuine mid-operation silence. On a device, startup latency is variable and sometimes exceeds the timeout, producing false failures that look like real timeouts — but only on the very first arm of the timer, not on subsequent re-arms once the async task is already running.

Fix

  1. Instrument first, cheap, ship-now. If the app already has structured diagnostic logging that records per-attempt duration and outcome, no new code is needed — go straight to analysis. If it doesn't, add minimal logging (duration + outcome per attempt) and ship that alone before attempting a fix.
  2. Mine the field log for a duration cluster near the suspect threshold. Pull every failure's duration and outcome. If failures cluster tightly around a duration close to the suspect timer's threshold — while the rare success takes meaningfully longer — that's quantitative confirmation of the race hypothesis without needing a repro. (Evidence below: 9 of 10 failures within ~250ms of each other, right at timeout-plus-startup-overhead; the 1 success took roughly double that.)
  3. Split the single timeout constant into two. A short one for genuine mid-utterance/mid-operation re-arming (the original value, still correct once the async task is live), and a longer, empirically-derived one for the very first arm before any result exists yet. Derive the first-arm value from the observed failure cluster — e.g. roughly 2x the worst individual observed failure duration, while staying comfortably under the one successful attempt's total duration — not a round-number guess.
  4. Instrument the fix with the same signal. Keep the duration/outcome log in place after the fix ships. On the next real-world use, the same signal tells you whether the fix worked (failures disappear) or the constant needs another bump (failures persist, but at a new shifted duration near the new threshold).

This generalizes to any mobile/embedded timing bug that only manifests on real hardware and can't be reproduced in a simulator/emulator/CI: instrument first, then use the field-log duration distribution as the evidence base for both diagnosing the race and picking the numeric fix parameter, rather than guessing or shipping an untested speculative fix blind.

Evidence

Session 0011, Phase 7 (00:55), Cubby iOS: "Analysis of every [Voice] entry ... 9 of 10 failed with .noSpeechDetected at a near-identical 1868–2111ms total duration; the 1 success took 4226ms ... close to a textbook confirmation of the plan's leading hypothesis: armSilenceTimer() arms its 1.5s countdown before recognitionTask(with:) is even called."

Fix: split into speechSilenceTimeoutSeconds (re-arm) vs new speechInitialSilenceTimeoutSeconds (first arm, 4.0s — "roughly 2x the worst individual observed failure duration ... while staying comfortably under the one successful attempt's 4.2s total"), with the reviewer noting the same log signal will confirm or refute the new constant on the next real attempt.

Related skills

  • avfoundation-capture-delivery-watchdog — a related timeout/watchdog pattern for AVFoundation capture delivery on real devices.
  • mainactor-launch-watchdog-audit — launch-time watchdog timing audited under MainActor-default isolation.

04 同仓库更多 Skills

abhijitbansal
abhijitbansal/claude-skills

second-wind

Orchestrate long unattended Claude Code runs across multiple repos with the wind CLI. Use when the user wants to run Claude Code overnight, resume sessions after the 5-hour usage limit, run Claude in many repos at once via tmux, or says "set up second wind", "wind up", "overnight run", "resume after limit", "usage limit orchestrator".

★ 1
abhijitbansal
abhijitbansal/claude-skills

structured-output-adaptive-thinking-token-bloat

A Claude API call using output_config.format (json_schema structured outputs) with thinking:{type:"adaptive"} burns most of its output budget on thinking (observed ~21k of ~24k tokens) without improving JSON quality, making the run up to ~5x more expensive than the same call with thinking omitted — use when calling the Messages API with a json_schema output format for extraction, ranking, classification, or summarization tasks, or when a schema-constrained call's usage.output_tokens is far larger than the returned JSON.

★ 1
abhijitbansal
abhijitbansal/claude-skills

review

Apply a code-review lens to a diff, branch, or file — find correctness bugs, security issues, and quality problems, ranked by severity, with a concrete fix for each. Use when the user says "review this", "review my diff", "check this PR", "look this over before I commit", or "is this safe". Skip when the user wants the code written, not reviewed.

★ 1
abhijitbansal
abhijitbansal/claude-skills

refresh

Rebuild the prompt-craft command registry and usage profile, and print a summary of installed commands and your personalized recommendations. Use when you install or update plugins and want the advisor to pick them up immediately, or say "refresh prompt-craft", "rebuild the command registry".

★ 1
abhijitbansal
abhijitbansal/claude-skills

refactor

Apply a refactoring lens — restructure code without changing behavior, guarded by tests that pass before and after. Use when the user says "refactor", "clean this up", "extract this", "simplify this", "reduce duplication", or "make this readable" on existing working code. Skip when the change is meant to alter behavior (that's a feature or a fix).

★ 1
abhijitbansal
abhijitbansal/claude-skills

plan

Decompose a non-trivial task into an explicit, tracked plan with goals and per-step acceptance criteria before writing code. Use when the user says "plan this", "break this down", "what's the plan", or asks for a multi-step feature/refactor that touches more than one file. Pairs with plan mode. Skip for single-edit changes that need no decomposition.

★ 1