oad/debug-prod
GitHub提供 OpenAgentd 生产环境日志与 OTEL 遥测数据的诊断工作流。包含定位目录、使用脚本分析日志模式、通过 DuckDB 查询追踪指标,以及新增工具使用审计功能以评估工具效率与错误率。
Trigger Scenarios
Install
npx skills add lthoangg/OpenAgentd --skill oad/debug-prod -g -y
SKILL.md
Frontmatter
{
"name": "oad\/debug-prod",
"description": "Workflow and patterns for inspecting, analyzing, and diagnosing production logs and OTEL telemetry in OpenAgentd."
}
Production inspection and telemetry analysis workflow for OpenAgentd instances.
1. Locate Log and Telemetry Directories
OpenAgentd stores state under XDG roots based on APP_ENV:
- Production mode (
APP_ENV=production):- Logs:
~/.local/state/openagentd/logs - Telemetry:
~/.local/state/openagentd/otel
- Logs:
- Development mode (
APP_ENV=development):- Logs:
.openagentd/dev/state/logs - Telemetry:
.openagentd/dev/state/otel
- Logs:
File Layout
logs/app/app.log— Full JSON loguru stream (DEBUG+, rotated at 10 MB, 7-day retention).logs/app/app-error.log— Errors only (ERROR+, rotated at 10 MB, 14-day retention).logs/app/app.YYYY-MM-DD_HH-MM-SS_*.log— Rotated past app logs.logs/sessions/<session_id>/session.log— Per-session filtered logs.otel/spans/YYYY-MM-DD-HH.jsonl— Hourly OpenTelemetry trace spans.otel/metrics/YYYY-MM-DD.jsonl— Daily OpenTelemetry metric rollups.
2. Log Analysis Workflow
Use the dedicated log analysis script to parse loguru JSON records, apply time cutoffs, and group distinct error patterns across log files:
uv run python .openagentd/skills/oad/debug-prod/scripts/analyze_logs.py --days 7
Script location: .openagentd/skills/oad/debug-prod/scripts/analyze_logs.py
3. OpenTelemetry Telemetry Querying via DuckDB
Use the dedicated OTEL telemetry querying script (powered by DuckDB) to inspect hourly span JSONL files (read_json), aggregate metrics, and list error spans:
uv run python .openagentd/skills/oad/debug-prod/scripts/query_otel.py --days 7
Script location: .openagentd/skills/oad/debug-prod/scripts/query_otel.py
3b. Tool Usage & Usefulness Audit
Answers "is any tool underused, slow, failing, or not earning its context?" by joining spans (volume, latency, result bytes) to loguru records (arguments, result text) per tool-call id:
uv run python .openagentd/skills/oad/debug-prod/scripts/tool_usage.py --days 7
Script location: .openagentd/skills/oad/debug-prod/scripts/tool_usage.py
Reports volume/cost, outcome quality (no-hit and error rates), a FIXED-OR-LIVE error-date table, unknown tool names the model guessed, repeated identical calls per run, and what shell is standing in for.
Three measurement traps it encodes — re-read these before trusting any similar analysis:
- Never divide errors by calls across different windows.
tool_errorrecords outlivetool_startrecords, which once read as "grep fails 44% of calls" for a bug fixed weeks earlier. The FIXED-OR-LIVE table prints first/last error dates per tool so history cannot pose as a live regression. - Redundant work is only redundant within a run. Attribute duplicate calls per
run_id; counting across sessions turned legitimate reuse into 111 fake duplicateskillloads. - Logged
args=are truncated at 500 chars (tool_executor.py), so strictjson.loadssilently drops the longest ~16% of shell calls — exactly the heredocs and inline python. That skew reported "shell is used to read files 78%" when the real leaders are tests/build 30% and git 18%. Likewise,tool_result_previewcarries no call id and parallel calls interleave, so pair previews to tools in aggregate, never to the most recent start (that undercounted glob's no-hit rate as 14% instead of 32%).
4. Common Production Patterns & Diagnostic Checklists
A. Tool Execution & Sandbox Failures
- Single file vs directory targets (
NotADirectoryError): Checkapp/agent/tools/builtin/filesystem/grep.pyandglob.py. Ensure tools handle file targets seamlessly when passed asdirectoryargument. - Diff / Patch ambiguity (
Found multiple matches/Could not find oldString): Ensure LLM receives clear error output from tool executor so it can re-read context and supply unique surrounding lines. - Regex timeouts (
grep scan timed out after 10s): Occurs on broad directory sweeps or complex regex. Check_SCAN_TIMEOUT_S.
B. Provider API & Protocol Violations
- Gemini turn order / role rules (
HTTP 400 INVALID_ARGUMENT): Gemini APIs reject back-to-backuserroleContentblocks. ConsecutiveToolMessageoutputs must be combined into a singleContent(role="user", parts=[FunctionResponse...])block. Check_convert_messages_to_geminiin provider and OAuth plugins. - Anthropic thinking block invariants (
thinking/redacted_thinking): Anthropic models reject requests if assistant thinking blocks are modified or stripped when replaying history. Ensurereasoning_signatureandredacted_thinking_blocksare preserved. - Context length exceeded (
HTTP 400 context_length_exceeded): Check summarization thresholds (app/agent/hooks/summarization.py) and message history context boundaries.
C. Log Noise & Level Calibration
- Unconfigured optional MCP integrations:
Optional MCP server warnings (e.g.
agent_unknown_mcp_server) should useDEBUGlog level so disabled/unconfigured MCP servers do not flood log sinks. - Session history sanitization:
Normal cleanup of interrupted turns (
deserialize_strip_incomplete_assistant_tool_calls,deserialize_drop_orphan_tool_message) should useDEBUGlog level during normal session loads.
5. Verification Protocol
After diagnosing and applying fixes:
- Verify Backend Suite:
make verify-backend - Verify Service Scenarios:
make scenarios - Verify Plugin Overrides (if applicable):
- Ensure plugin overrides in dev (
.openagentd/dev/config/plugins/) are synchronized to active production config roots (~/.config/openagentd/plugins/). - Perform syntax verification (
python3 -m py_compile <plugin_path>).
- Ensure plugin overrides in dev (
Version History
-
ac16c4e
Current 2026-08-16 07:56
新增 tool_usage.py 脚本,用于审计工具调用量、延迟及错误率;文档补充了三项测量陷阱说明。
- b4ec0d3 2026-07-24 16:51


