Repository navigation
feat: add full time-accounting macro for inter-turn gaps (5 categories) - #10
Merged
Merged
Conversation
The existing "AI Session Stall Classification (daily)" saved search only classifies outlier stalls (5min-2hr gaps) and discards everything else, so it cannot answer where every second of a session went. Adds claude_time_accounting_by_gap, parameterized by sessionId, bucketing every inter-turn gap into TOOL_EXEC/SUBAGENT_WAIT/MODEL_ACTIVE/HUMAN_IDLE. Also documents in props.conf that production events land as bare sourcetype=claude:code rather than the claude:code:session literal this TA's macros/eventtypes currently hardcode.
A downstream consumer (VisiCore_App_for_AI_Observability dashboard PR) needs the 5th category broken out rather than folded, which is exactly the real-use-case condition the prior comment named as the bar for splitting it. gap<2s -> SYSTEM_OVERHEAD, else MODEL_ACTIVE.
The prior comment claimed subagent transcripts get datatype-stamped as claude:code:subagent. Verified directly against production (7-day window, 146,804 events): that sourcetype has zero hits, ever -- every event, main session and subagent alike, lands as bare claude:code. The only reliable signal for a subagent transcript is the source file path containing /subagents/. Corrects the note on [claude:code:session] and flags the dormant [claude:code:subagent] stanza accordingly.
claude_time_accounting_by_gap classifies per-source in isolation, so it can't detect a parent session's gap overlapping a concurrently-running subagent in a different source file. scripts/time_accounting/ adds a stdlib-only classifier (session_timeline.py) plus a Splunk-export variant (splunk_retro_timeline.py) that reuses the same logic against index=claude data for sessions without a local transcript. Validated against local ground truth: single-digit-minute agreement across all 5 categories. Assisted-by: Claude:claude-sonnet-5 Claude-Session: https://claude.ai/code/session_012bPR299mQKnurhRohuAaas
fleet_discover.py closes the "any session, no prior sessionId" gap: it discovers every distinct sessionId active in index=claude over a time window, runs splunk_retro_timeline on each, and aggregates into one fleet-wide view of total time by category plus top blocking labels ranked by minutes lost. Validated against production (-24h, 14 sessions): correctly surfaced a known hung zammad MCP call (216 min) and independently found a second, previously-unknown orphaned tool call in an unrelated session. Assisted-by: Claude:claude-sonnet-5 Claude-Session: https://claude.ai/code/session_012bPR299mQKnurhRohuAaas
Verified directly against a live production session: every row that reaches the "no tool, no text" branch has EMPTY thinking content -- Claude Code logs an empty placeholder thinking block as its own transcript row, with real content landing on a separate row moments later. A single confident MODEL_ACTIVE bucket therefore overclaimed; neither the SPL macro nor the Python classifier could actually prove that time was spent generating. Splits both into MODEL_ACTIVE_CONFIRMED (row has measurable text/ thinking/tool-input output) and MODEL_ACTIVE_UNVERIFIED (it doesn't). The two tools use different gap-attribution models (macro: gap AFTER a row, by that row's own content; Python: gap BEFORE a row, by that row's own output) and so report materially different splits on the same data -- documented in both the macro comment and README rather than papered over, since they are not directly comparable numbers. Assisted-by: Claude:claude-sonnet-5 Claude-Session: https://claude.ai/code/session_012bPR299mQKnurhRohuAaas
Jacob (JacobPEvans-personal)
requested changes
Aug 5, 2026
Jacob (JacobPEvans-personal)
left a comment
Collaborator
There was a problem hiding this comment.
No; too custom. This needs re-evaluated completely. Use AI-native data stores
Jacob (JacobPEvans-personal)
requested changes
Sep 24, 2026
Jacob (JacobPEvans-personal)
left a comment
Collaborator
There was a problem hiding this comment.
No scripts; especially not in Splunk apps
Keeps the macro, props and their docs. Assisted-by: Claude:claude-opus-5-5 Claude-Session: https://claude.ai/code/session_01VQYAUPu8ecjxjt7TodfeBY
Jacob (JacobPEvans-personal)
approved these changes
Oct 20, 2026
Jacob (JacobPEvans-personal)
approved these changes
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The existing
AI Session Stall Classification (daily)saved search only classifies outlier stalls and discards everything else, so it cannot answer "where did every second of this session go." This adds a macro that does full, unfiltered time accounting instead.Live saved-search SPL (pulled verbatim from the Splunk REST API), for reference — this is the pattern the new macro generalizes:
What changed
New macro
claude_time_accounting_by_gap(sessionId)indefault/macros.conf— removes thegap>300 AND gap<7200outlier filter, usessourcetype=claude:code*(wildcard, see point 2), and maps onto a 5-category taxonomy instead of the 6-bucketkindfield above:TOOL_EXEC— any tool call other than Agent/TaskSUBAGENT_WAIT— tool_use name is Agent or Task (spawned subagent)HUMAN_IDLE— no tool_use, content type includes text (turn handed control back)SYSTEM_OVERHEAD— no tool_use, no text content, gap<2sMODEL_ACTIVE— no tool_use, no text content, gap>=2s (thinking/generating)Output fields:
time_category,turns,gap_sec,gap_min.Call
`claude_time_accounting_by_gap(<sessionId>)`for one session, or withsessionId="*"for fleet-wide accounting.Revision note: this started as a 4-bucket macro that folded SYSTEM_OVERHEAD into MODEL_ACTIVE (documented as a deliberate simplification, "not worth it until a real use case needs sub-2s granularity"). A downstream consumer building a dashboard against this exact macro hit that real use case, so it's now split out as its own bucket at a gap<2s threshold — noted in the macro comment as a starting guess, tunable once dashboard data shows the natural cutoff.
Documented in
default/props.conf(comment above[claude:code:session]): production events actually land as baresourcetype=claude:code, notclaude:code:session. This meansclaude_assistant_events,claude_all_session_events(both inmacros.conf), and everyclaude_*stanza ineventtypes.confcurrently match zero events at the ingestion boundary actually in use — they all hardcode theclaude:code:sessionliteral. I checked repo history (git log -- default/props.conf) and README/CHANGELOG for any indication this was already fixed; it hasn't been. The new macro avoids the bug by usingsourcetype=claude:code*directly. Fixing the existing macros/eventtypes is a separate, larger change (it'd touch the two live saved searches and any dashboards depending on them) and is left as a follow-up rather than folded into this PR.Revision note (commit
1f1b928): an earlier version of this comment additionally claimed subagent transcripts get datatype-stamped asclaude:code:subagent. That claim was wrong — I verified directly against production (7-day window, 146,804 events):claude:code:subagenthas zero hits, ever. Every event, main session and subagent alike, lands as bareclaude:code. The only reliable way to distinguish a subagent transcript is thesourcefile path containing/subagents/— sourcetype gives no signal for this at all. Corrected the comment and flagged the now-confirmed-dormant[claude:code:subagent]stanza inprops.confaccordingly. This macro was never affected (it already used thesource-partitioning-agnosticsourcetype=claude:code*wildcard and never filtered on the subagent sourcetype), but the documentation was actively misleading anyone who'd try to write a query filteringsourcetype=claude:code:subagentexpecting it to work.Validation
I ran the extended/unfiltered pattern directly against production Splunk myself (via
vct-splunk-cli,sourcetype=claude:code* sessionId="c024f242-4203-408c-b8bc-c8d4dc8e7f11" earliest=-6h) and got sane results, from the original 4-bucket version of this macro (SYSTEM_OVERHEAD not yet split out — its share of these numbers is folded into MODEL_ACTIVE below, not separately re-validated post-split):Known limitation (documented in the macro's comment)
Classification is per-
source(one session/subagent JSONL file) in isolation.SUBAGENT_WAITis near-zero here because synchronous Agent/Task tool_use → tool_result pairs are rare within a single source file — a subagent runs in a differentsource. This macro does not detect that aHUMAN_IDLE-looking gap in the main session actually overlapped with a concurrently-running subagent in a differentsource; only a local JSONL-parsing script comparing timestamp windows across files can do that today. A future enhancement could join acrosssourcevalues sharing the samesessionId+ time window to reclassify overlappingHUMAN_IDLEintoSUBAGENT_WAIT, mirroring what a local script does — out of scope here.Testing
default/macros.confanddefault/props.confparse cleanly (configparser, both files)./scripts/package.shbuilds the app tarball successfully with the changesRepo conventions note
This repo is trunk-based (default branch
main, nodevelop), so this PR targetsmaindirectly rather than git-flow'sfeature/* -> develop.Cross-repo consumer
VisiCore_App_for_AI_Observabilityis building an "AI Session Time Accounting" dashboard against this macro. Field/bucket names above are current as of the latest commit on this branch; will flag here again if they change further before merge.Update (2026-07-24): Python cross-source correlation tool
Added
scripts/time_accounting/— a stdlib-only Python complement to the macro above, for exactly the "Known limitation" case: it pairstool_use/tool_resultby ID across a session's main file and its subagent files, and reclassifies a parent's gap asSUBAGENT_WAITwhenever it overlaps a subagent's actual observed window (something SPLjoinhandles poorly — hit three separate silent-failure modes trying: a dropped join key,overwrite=trueclobbering the group-by field, and an uncontrolled cross-product fromjoin type=left max=0).session_timeline.py— local JSONL classifier, same 5-bucket taxonomy as the macro.splunk_retro_timeline.py— same classifier, but sourced fromindex=claudeviavct-splunk-cliexport instead of local files, so it works retroactively for any session/subagent set still in Splunk.Validated against local ground truth on a live session: single-digit-minute agreement across all 5 categories between the local-JSONL path and the Splunk-export path. Documented in README under "Time Accounting Tool".
Update (2026-07-24, cont.): fleet-wide session discovery
Added
scripts/time_accounting/fleet_discover.py— closes the "any session, no prior sessionId" gap. Discovers every distinctsessionIdactive inindex=claudeover a time window (stats count, min(_time), max(_time) by sessionId— sessionId is confirmed correct as the fleet-grouping key since subagents share their parent's sessionId), runs the per-session classifier on each, and aggregates into one fleet-wide view: total time by category across every session, plus top blocking labels (tools/commands/MCP calls) ranked by total minutes lost.Ran it for real against production (
-24h, 14 sessions, no output committed — contains real command text/paths): correctly re-surfaced the known hungmcp__zammad__zammad_create_ticketcall (216 min) and independently found a second, previously-unknown orphaned tool call (anEditin an unrelatedansible-proxmox-aisession, 83 min, no matching result event) — direct evidence the fleet-wide rollup finds real, actionable stalls that single-session analysis misses. This is the tool for "always know what to target to improve AI end-to-end execution times."Update (2026-07-24, cont.): MODEL_ACTIVE was overclaiming — split into confirmed vs unverified
A direct user challenge ("if a subagent outputs 5 words in 5 minutes, that's downtime, not thinking") led to verifying the single
MODEL_ACTIVEbucket against production data. Finding: 100% of the rows that reach the macro's "no tool, no text" branch have EMPTY thinking content (tested a live session, 1hr and 2hr windows). Claude Code logs an empty placeholderthinkingblock as its own transcript row, with the real content (text or a tool call) landing on a separate row moments later — so the macro's per-row gap-attribution model structurally routes every row with real content intoHUMAN_IDLE/TOOL_EXECbefore it can ever reachMODEL_ACTIVE. Calling that one confident bucket "model thinking/generating" overstated what the data actually proves.Fixed by splitting into
MODEL_ACTIVE_CONFIRMED(row has measurable text/thinking chars) andMODEL_ACTIVE_UNVERIFIED(it doesn't) — now 6 buckets total.MODEL_ACTIVE_CONFIRMEDreads near-zero via this macro specifically, which is documented in the macro comment as an accurate structural consequence, not a bug: the companion Python tool uses a different attribution model (gap before each row, by that row's own output) and found a materially different split on the same live session (~56% confirmed / ~44% unverified) — the two numbers are correct under their own definitions and are not directly comparable. Both are now documented clearly so nobody mistakes one confident number for ground truth again.