Skip to content

Agent Observability Replay — Full-Fidelity Session Reload #47

Description

@Number531

Summary

Agent observation cards now reconstruct full activity detail on session reload, matching the live streaming view. Previously, reloading a session showed only 2 agents (those with state files) and displayed "No activity recorded" — now all 29+ agents appear with granular tool-by-tool activity logs including durations, success/failure, search queries, and file targets.

Version: v4.10.0
Commit: f58e960

Changes

Backend — Hook Data Enrichment (hookDBBridge.js)

  • toolTimers Map: PreToolUse→PostToolUse elapsed time → duration_ms
  • agentTimers Map: SubagentStart→SubagentStop elapsed time → duration_ms
  • Per-hook-type success derivation (!tool_response.isError, false for failures, true for agents)
  • Compact tool_input extraction: query/pattern/command/url into event_data JSONB
  • WebSearch/WebFetch native SDK tool name matching (alongside MCP variants)
  • AUDIT_SKIP_TOOLS emptied — Read/Grep/Glob now persisted to hook_audit_log
  • persistState reads input.duration_ms for agent_states table

Backend — Query & API (dbFrontendRouter.js, postgres.js)

  • UNION ALL query: stateless research agents sourced from hook_audit_log SubagentStop
  • GET /api/db/sessions/:key/agent-events/:agentType — per-agent tool event feed
  • agentType regex validation (/^[a-z0-9_-]+$/i)
  • Composite index idx_audit_session_agent_event_time

Frontend — Playing Card Popup (app.js, styles.css)

  • Async activity feed: fetches granular events from DB, renders tool/target/context/duration
  • renderAgentStats() called on reload (stats grid populated)
  • CSS .detail-* rules scoped under .agent-obs-activity (cascade fix)
  • Activity feed max-height: 200px → 320px

Remaining Frontend Enhancements

The following items would further close the gap between live and reload views:

  • Transcript summary fallback — when DB events are unavailable (pre-v4.10.0 sessions), parse transcript_summary from SubagentStop event_data for a condensed activity view
  • Live-to-reload parity for running agents — agents that were actively running at time of page close don't get agent_type written at completion; capture in-progress state
  • Rapid popup race condition — if user opens/closes popups quickly, pending fetch could write to wrong #agentObsActivityFeed element; add generation counter or AbortController
  • Gate check detail in popup — show individual gate check pass/fail (data exists in event_data.gate_checks_passed/total) as a visual checklist
  • Tool usage breakdown chart — render tool category distribution (WebSearch, MCP, Read/Write, Bash) as a mini bar chart in the popup header area
  • Duration sparkline — visualize per-tool durations as a horizontal bar or sparkline in the activity feed
  • Backfill script — one-time migration to compute duration_ms for existing SubagentStop events from SubagentStart/Stop timestamp deltas in hook_audit_log

Test Plan

  • All 4 modules import cleanly (hookDBBridge, hookDBBridgeConfig, dbFrontendRouter, postgres)
  • 11/11 hook data flow scenarios pass (PreToolUse deny, PostToolUse success/failure, PostToolUseFailure, SubagentStart, SubagentStop with/without duration, PreCompact, SessionStart)
  • Endpoint validation: valid agent types pass, injection attempts blocked
  • CSS scoping: 0 unscoped .detail-* rules, 8 scoped rules
  • wrapHooksForDB no-pool passthrough: returns original config unchanged
  • Composite index created (idempotent CREATE INDEX IF NOT EXISTS)
  • Live session verification — run full session post-restart, confirm enriched data in DB and populated cards on reload

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions