Skip to content

fix(session-flow): call thresholds a shipped baseline and compute the recheck trigger #6077

Closed
2 of 2 issues completed

Description

@kyle-sexton

Part of #6074

Paths below are relative to plugins/session-flow/skills/audit-sessions/ unless they start with plugins/. Line numbers are on origin/main 9671ece.

Problem

E3. Thresholds are described as this machine's own baseline but ship as fixed numbers, and their recheck trigger has fired unreported (high).

  • SKILL.md:2 ("sweep it for sessions over this machine's own thresholds"), SKILL.md:101 ("The thresholds are this machine's own baseline, set in reference/sweep-rules.json"), SKILL.md:120 ("flags sessions over this machine's thresholds") and plugins/session-flow/README.md:219 ("against this machine's own thresholds") all say the thresholds belong to the user's machine.
  • reference/sweep-rules.json:3 says the opposite: "Thresholds are the per-session p90 of a 90-session spike on one machine (Claude Code 2.1.275-2.1.287, 2026-10-02)". scripts/sweep.py:33 and :326 load only the bundled rules file, and :131 compares every session to the shipped constant. Every installer loads the same cached copy.
  • reference/sweep-rules.json:5 sets a recheck trigger ("the store's own p90 for a metric moves past its threshold by half"), but nothing computes it: sweep.py computes only medians (:120) and the report has no stale-baseline line.

S1 (standards). That trigger is deterministic arithmetic left to a person (discipline: script the deterministic work).

S4 (standards). The threshold basis cannot be re-checked from any source. "90-session" appears only in sweep-rules.json:3; scripts/tests/test_transcript_reader.py cites "spike signals.py:25-31", which is not in the repository; git log --all -S finds nothing else. reference/canaries.json:6 cites 104 sessions over the same version range, a different population.

S5 (standards). The Unchecked section recites the spike's numbers as if they described the user's store: sweep.py:129 appends f"reported only, no threshold: {rule['basis']}", so the report prints "spike 0.84" beside a store value of 0.79, and "33 of 90 sessions start with /clear" where that store had 346 of 764. The reasons still hold; the labeling is wrong.

Evidence

Verified this pass: all lines above at 9671ece (SKILL.md, sweep-rules.json and canaries.json unchanged since the audit commit cb30935).

Measured by the audit on one Windows 11 machine with 764 sessions, 2026-10-03 (not re-measured here). Reading the trigger one-sided (store p90 above 1.5x the threshold), it is met for three metrics:

Metric Store p90 Threshold Ratio
tokens.sub 252,476 72,347 3.49x
hooks.stop_ms 13,018 645 20.18x
tools.interrupts 1 0 n/a (threshold 0)

The trigger text does not say whether it is one-sided or two-sided, or what "by half" means for a threshold of 0.

Proposed approach

  1. Correct SKILL.md:2, :101, :120 and README.md:219 to say the thresholds are a shipped reference baseline, pointing at sweep-rules.json:3. Add a CHANGELOG entry.
  2. Pin the trigger arithmetic in sweep-rules.json:5: one-sided or two-sided, and how it applies to a threshold of 0.
  3. Have sweep.py compute each metric's store p90 (reuse collect.py's _percentile rule, collect.py:159-163) and show it beside the threshold in both JSON and markdown, marking rows where the trigger is met. State in SKILL.md that the mark is advisory and leaves the exit code unchanged (SKILL.md:98 ties exit 1 to format drift only). Compute it on the interactive population once the classification child's E4 lands. This closes S1.
  4. S4: commit the derivation's summary output beside sweep-rules.json (per thresholded metric: n, median, p90, population filter, Claude Code version range, date) and point sweep-rules.json:3 at it. Never commit the spike transcripts. Fix the canaries.json:6 population note so it names its own population.
  5. S5: label recited basis numbers in the Unchecked reason as the reference machine's (sweep.py:129), for example "reported only, no threshold (reference machine: ...)".
  6. When re-deriving the two thresholds the metric-accuracy child nulls (hooks.stop_ms, time.active_s), use the new definitions.

Not recommended (scope review): per-machine thresholds derived from the user's own store. It hides costs every session shares, such as Stop hooks.

Files: SKILL.md, plugins/session-flow/README.md, reference/sweep-rules.json, reference/canaries.json, a new derivation summary file under reference/, scripts/sweep.py, scripts/tests/test_sweep.py, CHANGELOG and plugin.json.

Acceptance criteria

  • SKILL.md and README.md no longer say the thresholds are this machine's own.
  • sweep-rules.json:5 states whether the trigger is one-sided or two-sided and how it applies to a threshold of 0.
  • The JSON and markdown reports show each metric's store p90 beside its threshold.
  • On a fixture store where a metric's p90 exceeds 1.5x its threshold, that row is marked, and the sweep's exit code is unchanged by the mark.
  • A committed file gives, per thresholded metric, n, median, p90, population filter, Claude Code version range and date, and sweep-rules.json:3 points at it.
  • Each Unchecked reason that quotes basis numbers says they come from the reference machine.

Constraints and gotchas

Context

Source: local handoff item 20261003-070338-session-flow-audit-sessions-accuracy-and-coverage.md (findings E3, S1, S4, S5). Related: #4373, PR #4192, #5925.

Sub-issues

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. added
    agent-ready
    on Oct 3, 2026
  2. kyle-sexton commented on Oct 4, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during work-loop.

    Ratify autonomous dispatch of this C3 bug-fix item?

    Classification: work-class: scoped (C3), bug-fix-shaped. Intended dispatch: the work-loop worker lane, through /work-items:work, to a draft PR the lane never merges. The lane has not completed its first drain and no item-level ratification exists, so the item is queued here instead of dispatched. Ratify it through /work-items:attend-queue, and it returns to the frontier and dispatches on a later cycle.

    Lane: work-loop, instance melo-worker-1, cycle 1.

  3. added
    needs-human
    and removed
    agent-ready
    on Oct 4, 2026
  4. self-assigned this
    on Oct 4, 2026
  5. kyle-sexton commented on Oct 4, 2026

    @kyle-sexton
    MemberAuthor
    No description provided.
  6. added
    agent-ready
    and removed
    needs-human
    on Oct 4, 2026
  7. kyle-sexton commented on Oct 4, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during attend-queue.

    Operator direction (2026-10-04): "go with the recommendations." This records that decision.

    Operator ratification: ratified as C3 (scoped), blocked by #6075. This body says to land after #6075, which is still open. A native blocked-by edge now holds this item off the frontier until #6075 closes. #6076 has merged (PR #6179), so the interactive-population prerequisite is met.

    Answers to the two open questions:

    1. Where do the S4 numbers come from? Nowhere: no signals.py or spike data survives. Re-derive each threshold from the current interactive-session store, excluding 2026-09-14 to 2026-09-27 as this issue requires. Commit the derivation (query, window, sample size, resulting p90 and threshold) beside the rules file, so acceptance criterion 5 cites a committed source instead of invented numbers.
    2. Is the recheck trigger one-sided? Yes. Fire when the store p90 exceeds 1.5x the threshold.

    Notes:

    Research: attend-queue slice intake-6077.

  8. removed their assignment
    on Oct 4, 2026
  9. kyle-sexton commented on Oct 4, 2026

    @kyle-sexton
    MemberAuthor

    New measurements for the hooks.stop_ms re-derivation, from the 2026-10-04 Windows performance audit (parent #6244). One machine, Claude Code 2.1.289, read-only; not re-run in this drafting pass. They confirm the stale baseline on a newer store and add one input the re-derivation needs.

    The current (summed) statistic. A collect plus bare sweep on 2026-10-04 reported hooks.stop_ms with a median of 4,440 ms against the 645 ms threshold, and every one of the 481 sessions with Stop data over it, so the finding ranks nothing. This is still the summed definition (scripts/collect.py:421 on origin/main 5779559; #6075 cited it at :412 before #6179 moved it). It is the median across sessions of each session's p90 of summed Stop durations.

    The max-based statistic #6075 moves to, on a different population. Over the newest 50 top-level transcripts (742 stop_hook_summary records), taking the slowest hook per record: p50 848 ms, p95 4,837 ms, max 175,206 ms. Treat this as an indication, not a threshold: it is per record, not per-session p90, and covers 50 transcripts, not the interactive store.

    Weekly Stop wall time (max per record, all transcripts including subagents):

    ISO week n p50 ms p95 ms
    W36 81 937 1,255
    W37 882 966 5,058
    W38 2,078 4,688 10,831
    W39 2,434 4,322 11,170
    W40 2,629 499 3,551

    The W38-W39 driver was harness-ops "Checking for unsurfaced hook failures..." (p50 4,670 / 2,946 ms in W38 / W39, 252 ms in W40). This supports this issue's exclusion of 2026-09-14 to 2026-09-27.

    New since the spike: the testing test-judge Stop hook ("Collecting the test judge's verdicts...", W40). On the newest 50 transcripts it ran p50 782 ms, p95 4,853 ms, max 175,206 ms (n = 721), the largest Stop contributor by total time. Any threshold derived from a window that includes W40 or later bakes in this hook. Decide on purpose whether the baseline should include it. Its long tail is the hook waiting up to 180 s for background judge runs; its separate turn-blocking on all-PASS verdicts was fixed by #6092.

    Separately, the full re-read that a session-flow version bump forces on every collect is filed as its own issue, #6257.

    Source: local handoff item 20261004-152632-claude-perf-audit-tooling-bugs.md, bug 4.

  10. removed
    agent-ready
    on Oct 14, 2026
  11. 15 remaining items

  12. added
    needs-human
    and removed
    agent-ready
    on Oct 25, 2026
  13. melodic-automation-lanes commented on Oct 25, 2026

    @melodic-automation-lanes
    Contributor

    The work-resolve-issue lane did not start this issue: it needs a person to make it clearer first.

    Why, in the run's own words:

    The code and wording parts of #6077 are already on main: the reference-baseline wording in SKILL.md and README.md, the one-sided trigger with stale_p90_factor in sweep-rules.json, the store p90 and baseline_stale mark in sweep.py with tests, the 'measured on the reference machine' Unchecked label, the canaries population note, and two CHANGELOG entries citing #6077. What is left needs measurements this lane cannot take: (1) acceptance criterion 5 and proposed step 4, a committed derivation summary with n, median, p90, population filter, Claude Code version range and date per thresholded metric, which the 2026-10-04 attend-queue comment says must be re-derived from a person's interactive-session store because no spike data survives; (2) step 6, new thresholds for hooks.stop_ms and time.active_s, both still null; (3) the acceptance carried over from #6074 on 2026-10-24, a sweep over a re-collected store. The CI runner has no interactive session store, and inventing numbers is not an option. One question is also still open, and no comment marked as a decision answers it: should the hooks.stop_ms baseline include the testing test-judge Stop hook that arrived in W40 (2026-10-04 comment: 'Decide on purpose whether the baseline should include it')? To unblock: someone runs collect on a machine with an interactive store, excluding 2026-09-14 to 2026-09-27, and posts or commits the per-metric derivation output. They also record a decision on the test-judge hook. Alternatively, a decision could re-scope the issue to close it with that work filed separately.

    What the run says it did not do:

    • Commit the per-metric threshold derivation (criterion 5): it needs measurements from an interactive session store, and the CI runner has none
    • Re-derive the hooks.stop_ms and time.active_s thresholds on their new definitions: this needs the same store, plus a decision on whether to include the test-judge Stop hook
    • The #6074 acceptance carried over (a sweep over a re-collected store shows no active time above wall clock and a max-based hooks.stop_ms): this needs a real re-collected store

    Run: https://github.com/melodic-software/claude-code-plugins/actions/runs/40190485006

    To retry, answer the question here, remove needs-human and add agent-ready again.

  14. added
    host-run
    status: confirmed
    and removed
    status: ready
    needs-human
    on Oct 27, 2026
  15. kyle-sexton commented on Oct 29, 2026

    @kyle-sexton
    MemberAuthor

    Host run. Re-collected this Linux (WSL) host's interactive session store with origin/main's collector into a copy, ran main's sweep over it, and computed the per-metric derivation numbers criterion 5 needs.

    What ran

    • origin/main a6ab693b6, Claude Code 2.1.312, session-flow 1.10.1.
    • pytest scripts/tests/test_sweep.py: 75 passed.
    • collect.py collect --data-dir <copy> --retention-days 0 over a copy of the store, so the live store was not touched. It re-read every transcript because the stored records were mostly collector 1.7.0. Wall time 257 s (18:44-18:48 UTC). Result: 2,468 records, 2,442 of them at collector 1.10.1.
    • sweep.py --data-dir <copy>: status pass, exit 0.
    • A one-off script that imports sweep's PER_SESSION, p90 and census.session_class. It was not committed.

    Acceptance criteria against origin/main

    # Criterion Result
    1 SKILL.md and README.md wording Met. SKILL.md:2 and :148 and README.md:241 say "shipped reference baseline".
    2 Trigger sidedness and threshold 0 Met. sweep-rules.json recheck says one-sided, and that a threshold of 0 fires on any p90 above 0. stale_p90_factor is 1.5.
    3 Store p90 beside each threshold Met. Every metric row in the JSON has p90, and the markdown has a p90 column (sweep.py:434). Also shown on real data in this run.
    4 Fixture row marked, exit code unchanged Met. test_sweep.py:146 passes. On real data, tokens.sub is marked baseline_stale (p90 460,415 against 72,347) and the exit code stays 0.
    5 Committed derivation file, pointed at from sweep-rules.json:3 Not met. No such file exists under reference/. The numbers are below, but no thresholds were committed (see the open question).
    6 Unchecked reasons name the reference machine Met. sweep.py:266 adds "basis measured on the reference machine, not this store". test_sweep.py:330 covers it.
    carried from #6074 Re-collected store: active time never above wall clock, and hooks.stop_ms max-based Met on this host. active_gap_s > wall_clock_s in 0 of 2,464 records. hooks.stop_ms reads stop_hooks.wait_ms_p90, the slowest hook per Stop run (sweep.py PER_SESSION), and 1,506 records have it.

    Derivation numbers (this host, not committed)

    These are the numbers criterion 5's file needs. Population: interactive and unknown-entrypoint sessions (sweep's own filter), with session starts in 2026-09-14 to 2026-09-27 excluded. That leaves n = 660, starting 2026-09-28 to 2026-10-29, Claude Code 2.1.283-2.1.312, derived 2026-10-29. p90 uses sweep.py's p90.

    Metric n Median p90 Current threshold (p90 ÷ threshold)
    tokens.main 660 94,138 230,546 205,212 (1.12x)
    tokens.sub 660 12,033 486,728 72,347 (6.73x)
    cache.missed_input_tokens 660 0 14,356 272,137 (0.05x)
    time.active_s 660 6,381.5 19,372 null
    context.clear_commands 660 1 1 null
    human.turns 660 5 16 14 (1.14x)
    tools.interrupts 660 0 0 1
    tools.denials 660 2.5 17 27 (0.63x)
    subagents.count 660 7 36 33 (1.09x)
    hooks.stop_ms (max-based p90 per session) 569 86 153 null

    This host's store holds no sessions before 2026-09-28. So it cannot split hooks.stop_ms into before and after the testing test-judge Stop hook (W40): every session here includes it. It also cannot reproduce the reference machine's population (Windows, 2.1.275-2.1.287).

    Decision (agent, under the owner's stop rule: neither input changes intent or design)

    1. Reference baseline: this Linux host's store (option a). It is the only store measured on main's definitions, and the copy can be re-collected for the next baseline. Basis: this run.
    2. hooks.stop_ms includes the test-judge Stop hook: it is a real per-stop wait, and this store cannot exclude it by window. Basis: the n = 569 row above.

    Remaining work (no host store needed): commit the derivation file under reference/ with the table above, point sweep-rules.json:3 at it, and set the time.active_s, context.clear_commands and hooks.stop_ms thresholds from these p90 values. Criterion 5 then closes.

    Target labels: add agent-ready; remove host-run.

  16. added
    agent-ready
    and removed
    host-run
    on Oct 29, 2026
  17. kyle-sexton commented on Oct 30, 2026

    @kyle-sexton
    MemberAuthor

    Superseded: #9963 shipped the wording and the computed recheck trigger; the threshold derivation is tracked in #10223 and #10271.

  18. kyle-sexton commented on Oct 30, 2026

    @kyle-sexton
    MemberAuthor

    Host run. Re-collected this operator machine's interactive session store with the audit-sessions collector, derived per-metric n, median and p90 for every rule in sweep-rules.json, and ran the sweep over the same store for the #6074 check.

    What ran

    • session-flow 1.10.4 at main a955d6b58b; Claude Code 2.1.314 on the host. Run date 2026-10-30 (UTC).
    • collect.py collect --retention-days 0 --excerpt-chars 0 --excerpt-words 0 into a fresh condensed store (no excerpt text stored), run once: exit 0, 2,490 of 2,490 sessions ingested, redaction not failing closed, 221 s wall clock. The skill quotes about 70 s for 2.6 GB and sets a 300 s recheck trigger; this run was under that.
    • sweep.py --format json, with no --write-report: exit 0, status pass, 710 sessions, 1,780 automated sessions set aside, 0 unclassified, no degraded metric, 0 canaries lost, 7 unknown record types (advisory).
    • A derivation script imported sweep.PER_SESSION, MACHINE_WIDE and PER_TICKET for the extractors and collect._percentile for the p90 rule. With the date exclusion off, its n and p90 for all 12 metrics match the sweep's data.metrics exactly.

    Population

    • Sessions are interactive (sweep's population: non-automated by census.session_class), and 0 of them have an unknown entrypoint, so the strict-interactive figures are the same.
    • The window excludes 2026-09-14 to 2026-09-27, filtered by session start date (UTC). That removed 38 sessions and left 672.
    • The store holds no session older than 2026-09-14, so the population runs 2026-09-28..2026-10-30 (Claude Code 2.1.283-2.1.312). The whole population therefore falls after W40, under one hook set.

    Derivation (n = 672 sessions unless stated)

    Metric Unit Current threshold n Median p90 Max Nonzero
    tokens.main tokens 205212 672 95196.5 233586 630958 593
    tokens.sub tokens 72347 672 13083 546457 7785928 455
    cache.missed_input_tokens tokens 272137 672 0 26553 1473232 78
    cache.write_5m_share ratio null 672 machine-wide 0.840 n/a n/a n/a
    time.active_s s null 672 6520.5 19372 46388 596
    context.clear_commands count null 672 1 1 1 412
    human.turns count 14 672 5 15 61 577
    tools.interrupts count 1 672 0 0 6 47
    tools.denials count 27 672 3 17 160 435
    subagents.count count 33 672 7 36 470 456
    hooks.stop_ms ms null 581 sessions with a Stop run 86 152 111151 581
    edits.churn_per_pr count 5 2054 path-PR pairs 1 5 174 2054
    • Every row covers 2026-09-28..2026-10-30 and Claude Code 2.1.283-2.1.312.
    • time.active_s reads time.active_gap_s: record gaps capped at 300 s.
    • hooks.stop_ms is the median of each session's p90 Stop wait, read from stop_hooks.wait_ms_p90.
    • The sweep marks only tokens.sub baseline_stale: its store p90 is above 1.5 times its threshold.

    hooks.stop_ms includes the test-judge Stop hook. The metric reads every hookInfos entry and excludes no hook (collect.py:487-493). The store keeps no hook names, so this run cannot show how many sessions the test-judge hook ran in (UNVERIFIED). The 86 ms median is well below the 782 ms test-judge p50 measured on 2026-10-04, which suggests the hook fired in few of these sessions (UNVERIFIED).

    #6074 check, sweep over the re-collected store

    • Records with active time above wall clock: 0 of all 2,490 records, using the collector's 1 s rounding tolerance (collect.py:541). The strict comparison also gives 0, and so does the interactive population. For contrast, the old turn_duration sum (time.active_s, still stored) is above wall clock in 56 records.
    • hooks.stop_ms reads the max-based per-Stop wait. sweep.py:111 reads stop_hooks.wait_ms_p90, and the collector builds that from the slowest hookInfos[].durationMs of each Stop run (collect.py:493), not from the sum.
    • The sweep lost no invariant canary: active_over_wall, stop_wait_over_sum, usage_regress and subagent_files_missing all held their expected absent state.

    Acceptance criteria

    No PR: the step changes no code. Slice 2 sets the thresholds from these p90s.

    Target labels: add agent-ready; remove host-run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readystatus: confirmed

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions