Skip to content

yeaight7/agent-powerups / plugins/dev-vitals/skills/agent-session-forensics

agent-session-forensics

Verified

Use when diagnosing agent session history, interrupted tool loops, missing tool results, timing bottlenecks, or subagent trace correlation.

Agent Session Forensics

When To Use

  • Agent session ended mid-tool-call or cannot resume.
  • Tool call appears in assistant turn but no corresponding result turn follows.
  • Need to correlate tool calls, tool results, and timing metadata.
  • Diagnosing slow LLM calls, duplicate user turns, or malformed results.
  • Debugging experimental MCP data-layer sessions.

Requirements / Checks

  • Locate session directory and history files before editing anything.
  • Prefer read-only inspection first.
  • Have jq or equivalent JSON tooling available.
  • Ask before modifying, truncating, or deleting any session or history file.

Workflow

  1. Inventory session files — find metadata, current history, rotated previous history, and related subagent histories.

  2. Count and list last turns:

    jq 'length' history.json                                      # total messages
    jq '.[-10:] | .[] | {role, stop_reason}' history.json        # last 10 turns
    jq '.[] | select(.role=="assistant") | .tool_calls[].id' history.json  # tool call IDs
    jq '.[] | select(.role=="user") | .tool_results[]?.tool_call_id' history.json  # results
    
  3. Correlate tool call IDs — every tool_call in an assistant turn must have a matching tool_result in the immediately following user turn. Find the first gap.

  4. Check timing for slow calls:

    jq '.[] | select(.timing) | {role, duration_ms: .timing.duration_ms}' history.json
    
  5. Identify failure pattern — see table below.

  6. Repair (if approved) — write a backup first (cp history.json history.json.bak), then make the smallest possible fix at the last valid correlation boundary.

Common Failure Patterns

SymptomLikely causeRepair
Tool call with no result turnSession interrupted mid-toolTruncate after last matched pair
Two consecutive user turnsDuplicate message insertionRemove the duplicate
tool_result with no prior tool_callCorrupted or manually edited historyRemove orphan result
Empty content on assistant turnModel returned no text + no toolsUsually safe to truncate
Session loops without progressMissing result causes re-promptInject minimal synthetic result

Safety Constraints

  • Do not edit session JSON without backing up the original first.
  • Treat history files as sensitive: prompts, tool arguments, credentials, and file contents may appear.
  • Do not infer user intent from stale history when current user instructions conflict.
  • Do not repair by deleting broad ranges — find the last valid tool-call/result correlation boundary.

Validation / Done Criteria

  • Report the names of every session file inspected.
  • Every tool-call ID is accounted for (matched or flagged as unmatched).
  • Any proposed repair names the backup path and truncation boundary.
  • No session file is mutated without explicit user approval.

References

  • references/history-diagnostics.md
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 468kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 321kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 321kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 321kUpdated Claude CodeCodexVerifiedInstall