gza-task-debug
Diagnose why a gza task failed — analyzes logs, detects loops, checks diffs, compares baselines, and suggests fixes
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Diagnose why a gza task failed — analyzes logs, detects loops, checks diffs, compares baselines, and suggests fixes
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Review changes on current branch and output a structured review. Optionally post to PR with --pr flag, or apply non-blocking follow-ups inline with --apply-followups.
Run an interactive code-only review for a gza task's implementation branch and produce structured review output compatible with gza-task-improve
Check the implementation against the behavior specs in specs/behavior/. Reports where the code diverges from intended behavior — each divergence is either a code bug or a spec gap. The behavior spec is the source of truth; this skill never edits code or the spec.
Check the behavior spec set for coherence, ownership boundaries, and plain-language discipline without editing the spec or the code
Turn the recurring `watch` stuck-task pile into (1) a diagnosis of why each class is stuck, (2) the existing stuck rows actually cleared now, and (3) systemic prevention so it does not recur. Snapshots watch/incomplete/queue, buckets stuck tasks by failure class, dedups against already-tracked `system` work, unsticks each row by its clearing action (drop moot/dead/stale, spawn follow-up, hand review-loop rows to /gza-task-fix), then ranks and files `system`-tagged prevention fixes by blast radius (cascade-preventer first). Never merges, retries, resumes, deletes branches, or edits code.
Triage `gza incomplete` rows — classify each unresolved merge-unit lineage and recommend the right corrective action (drop moot leaves, escalate to fix, surface manual-resolve rebases, etc.). Never merges, retries, resumes, or deletes branches; never edits code.
استنادا إلى تصنيف SOC المهني
| name | gza-task-debug |
| description | Diagnose why a gza task failed — analyzes logs, detects loops, checks diffs, compares baselines, and suggests fixes |
| allowed-tools | Read, Bash(uv run python -c:*), Bash(uv run gza search:*), Bash(git:*), Bash(wc:*), Bash(grep:*) |
| version | 1.1.0 |
| public | true |
Diagnose why a gza task failed by analyzing logs, detecting agent loops, comparing against baselines, and providing actionable recommendations.
The user should provide a full prefixed task ID (for example, gza-1234). Extract it from the input.
Run a Python one-liner to get all task details as JSON:
uv run python -c "from gza.db import get_task; import json; print(json.dumps(get_task(<ID>), indent=2, default=str))"
Note the following fields for analysis:
status — should be failed or max_turns (or possibly completed if user suspects partial failure)num_turns — number of agent turns usedduration_seconds — total wall-clock timecost_usd — API costlog_file — provider conversation transcript path; also inspect the sibling <stem>.ops.jsonl file for runner lifecycle, preflight, command, outcome, and stats eventsreport_file — path to the report (if any)branch — git branch the task worked onCompare the failed task's metrics against the last 20 completed tasks:
uv run python -c "from gza.db import get_baseline_stats; import json; print(json.dumps(get_baseline_stats(20)))"
Calculate how far the failed task deviates:
num_turns is 2x+ the average → flag as high turnscost_usd is 3x+ the average → flag as high costDo NOT just read the tail — scan the full log for repeated patterns.
If log_file is set, run these grep-based checks against the conversation log first. Then inspect the sibling ops log for infrastructure/preflight/outcome clues:
ops_log="${log_file%.log}.ops.jsonl"
Repeated file opens (same file opened 5+ times):
grep -o 'Reading file: [^ ]*\|reading.*["\x27][^"'\'']*["\x27]\|open.*["\x27][^"'\'']*["\x27]' <log_file> | sort | uniq -c | sort -rn | head -20
Repeated tool invocations (same command run many times):
grep -oE '(Bash|Read|Write|Edit|Grep|Glob)\(' <log_file> | sort | uniq -c | sort -rn | head -10
Repeated error strings:
grep -iE '(error|failed|exception|traceback)' <log_file> | sort | uniq -c | sort -rn | head -20
Repeated test runs (pytest/jest/etc. invoked repeatedly):
grep -cE '(pytest|npm test|jest|rspec|go test)' <log_file>
Same search query repeated:
grep -oE 'pattern": "[^"]*"' <log_file> | sort | uniq -c | sort -rn | head -10
If any file appears 5+ times, or any error string repeats 5+ times, this strongly indicates a stuck agent loop.
Read the last portion of the log file to understand how the task ended:
grep -c '' <log_file>
(to get total line count, then read the last ~200 lines using offset)
Also read the last 200 lines directly to see the final state — what was the agent doing right before it stopped? Was it:
If report_file is set, read it for the agent's own summary of what happened.
Determine the base branch by running git rev-parse --abbrev-ref @{upstream} 2>/dev/null | sed 's|.*/||'. If that fails (no upstream set), fall back to main. Store this as BASE_BRANCH.
If the task has a branch with commits:
git diff $BASE_BRANCH...<branch> --stat
This shows:
Calculate the turns-per-file-changed ratio:
num_turns / files_changedAlso check what was actually committed:
git log $BASE_BRANCH...<branch> --oneline
Based on all evidence, determine the root cause. Common failure patterns:
1. Max-turns with loop (stuck agent)
2. Max-turns with scope creep
3. Max-turns with missing context
--based-on to chain from an explore task4. Max-turns with legitimate large task
--max-turns or break into sequential subtasks5. External failure (test/build errors)
6. Unnecessary work (over-engineering)
Output a structured diagnosis with these sections:
| Field | Value |
|---|---|
| ID | |
| Status | |
| Prompt | |
| Turns | <num_turns> |
| Duration | <duration_seconds>s () |
| Cost | $<cost_usd> |
| Branch | <branch or "none"> |
| Metric | This Task | Avg (last 20) | Ratio |
|---|---|---|---|
| Turns | <num_turns> | <avg_turns> | x |
| Duration | s | <avg_duration>s | x |
| Cost | $ | $<avg_cost> | x |
[What was the agent doing at the end? What was it trying to accomplish?]
[One of: Stuck Loop | Scope Creep | Missing Context | Legitimate Large Task | External Failure | Over-engineering]
[2-3 sentence explanation of what specifically caused the failure]
[If applicable: specific prompt text to use, specific AGENTS.md sections to add, specific task splits]
First, dedup by ID. Before offering to create any replacement/fix task, check whether one already exists — fix tasks cite their originating task ID in their prompt, so the task ID is the reliable dedup key (keyword guessing is not):
uv run gza search "<task-id>"
If an open (pending / in-flight) task already cites this ID, surface "already tracked by gza-XXXX" and offer to wait for it rather than filing a duplicate. Only offer new tasks after this returns nothing.
After the diagnosis, ask:
Would you like me to create replacement tasks based on this analysis?
Suggest concrete replacements based on root cause:
--based-onUse the format:
Would you like me to create N replacement tasks?
1. [Task description] — [why this addresses the root cause]
2. [Task description] — [why this addresses the root cause]
If the user says yes, use the gza-task-add skill to create each task.
.gza/gza.db relative to cwd (project root)branch is NULL, skip the git diff analysislog_file is NULL or empty, note this and rely on database fields only