Skip to content

fix: count an unreadable transcript only as could not load - #32583

Merged
bolichen97 merged 1 commit into
mainfrom
fix/30423-usage-unreadable-double-count
Nov 8, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/30423-usage-unreadable-double-count

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A transcript the Usage page cannot read is counted once, as "could not load", and not as a session.

On the Usage page, a session transcript from the last 30 days that cannot be opened (for example, a file the user has no read permission on) shows up twice: all_time_sessions: 1 and refused_transcripts: 1 for the same file.

Why it matters

The all-time session total is too high by one for every unreadable recent transcript, and the same file is reported as both loaded and not loaded, so the "could not load" warning contradicts the total shown next to it.

Not a goal

  • Making unreadable transcripts readable, or changing how a validator refusal or a stat failure is counted (both already skip the all-time total).
  • Changing how transcripts older than the 30-day window are counted: they still count toward the all-time total without being read.
  • Any change to the Usage page UI or the payload's keys.

What changed (motivation → approach → change)

An unreadable recent transcript inflated the all-time session total while being reported as "could not load".

The root cause is ordering in usage_sessions.py: all_time_sessions was incremented before the transcript was opened, so a failed read put the same file in refused_transcripts on top of it. The validator-refusal and stat-failure branches already skip the all-time count.

The fix counts an out-of-window transcript at the 30-day cutoff exactly as before, and counts an in-window transcript only after its read succeeds, next to total_sessions. Every did-not-load branch now feeds only refused_transcripts.

Backwards compatibility

Compatible: the payload keeps every key and type; only the all-time count stops including transcripts that failed to load.

Removes nothing: no key, route, file or record is removed; one counter stops counting a file twice.

Tests

test/test_usage.py::TestParseSessions::test_file_read_oserror now pins the single count for a recent transcript whose open() raises OSError: all_time_sessions == 0 and refused_transcripts == 1. The existing old-session tests keep the out-of-window transcript in the all-time total.

Proof: PROVEN test/test_usage.py::TestParseSessions::test_file_read_oserror (head 94097fd08767)

Determinism: the changed test passed 20/20 at -n0, 10/10 at -n 4 --dist loadgroup --max-worker-restart=2 beside test/test_usage_series.py and test/test_usage_scrape_editable.py, and all 98 tests of test/test_usage.py passed in a shuffled order (seed 11982). The backend related set (scripts/run_scoped_tests.py --surface backend, 148 tests) and the flake-pattern ratchet pass.

Manual verification

N/A — unit coverage sufficient: the change is the position of one counter in a pure file-scan function, and the tests drive each did-not-load branch directly.

Screenshots / video

N/A — backend-only change; the diff touches no frontend file.

Related Issues

Closes #30423

Sibling sweep

Swept: git grep -nE "sessions += 1|refused_transcripts += 1" -- src/
Siblings: none -- all_time_sessions and refused_transcripts are only counted in _parse_sessions; the other hits count unrelated things (STT streams, trash moves, batch manifests).

Pattern harvest

Not generalizable: a one-off ordering slip where one counter ran before the read it depends on, in a single function.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 7, 2026 20:07
@bolichen97
bolichen97 enabled auto-merge (squash) November 7, 2026 20:14
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 7, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Backend Tests shards 5 and 6 (Linux and Windows) fail on this head in test/test_held_note_turn_starts.py and test/test_dashboard_server_composition_contract.py::test_the_lazy_imports_stay_inside_the_functions_that_need_them. Both fail the same way on main (the Windows shards of the push run for 03016b6), and neither file is in this diff; Coverage Gate fails only because those shards did. #32606 re-pins both tests, so this PR waits for it and rebases onto it once it merges.

The review lanes, Dependency License Gate and the readiness signal on this head stopped on an exhausted API rate limit before producing a verdict, so they hold no finding yet; they run again on the rebased head.

@bolichen97
bolichen97 force-pushed the fix/30423-usage-unreadable-double-count branch from 3582d23 to be461e8 Compare November 8, 2026 02:41
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in the Backend shard 5 and 6 tests since this head ran (3582d23 -> be461e8, onto 601aa4c, which carries #32606); CI re-running. The GPT, Opus, Design and First Principles lanes on the old head failed on a GitHub API rate limit before reviewing, so they re-run on this head. Local gate (test/test_usage.py, flake8, isort, black, mypy, flake-pattern ratchet, semgrep), local GPT and local Opus review passed on this tree.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 573ac620418672321549e0fa341b10e7de8e5def touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 573ac620418672321549e0fa341b10e7de8e5def — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the counter now runs after the read succeeds, so every did-not-load branch feeds only refused_transcripts.

Notes

  • The old all_time_sessions == 1 assertion carried no comment explaining why it should be 1. The only comment in that test was on total_sessions ("not counted when file read fails"), and it makes the same point as this fix. So changing the pin reverses an oversight, not a recorded decision.

[DESIGN-REVIEWED] 573ac62

Description read

[DESCRIPTION-READ] f5a030e33c6d958727e97ead23d27af5ca76b19d841881c5bc6a71e17aa7c6f3

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 573ac620418672321549e0fa341b10e7de8e5def — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The change only moves one counter so that an in-window transcript is counted after its read succeeds. The deleted == 1 pin contradicted the function's own warning, "the reported session counts exclude them".

What this change ships

Inventory (2 items) — 2 justified

Intent: the Usage page counts a transcript it could not read once, as "could not load", and not also as a session. This is a FIX.

  1. A recent transcript that cannot be read no longer adds one to the all-time session total. — justified
  2. The test now expects all_time_sessions == 0 and refused_transcripts == 1 for that case, where it used to expect 1. — justified

[FIRST-PRINCIPLES-REVIEWED] 573ac62

Description read

[DESCRIPTION-READ] d50132232cd749793d63b88bb3804eaf58843d177e6655cab37f09490c8d20a9

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 573ac620418672321549e0fa341b10e7de8e5def — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 573ac62

Verdict parsed from the review's SHA-scoped output markers for commit 573ac620418672321549e0fa341b10e7de8e5def.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 573ac620418672321549e0fa341b10e7de8e5def false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 573ac620418672321549e0fa341b10e7de8e5def and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 573ac62

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 573ac620418672321549e0fa341b10e7de8e5def false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 8, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 8, 2026
@bolichen97
bolichen97 force-pushed the fix/30423-usage-unreadable-double-count branch from be461e8 to 573ac62 Compare November 8, 2026 03:42
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 8, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/dashboard/handlers/usage_sessions.py (#26951 split the transcript read into a cached _count_transcript), which made this PR conflict (be461e8 -> 573ac62, onto 3a5c452). Kept main's cache and mtime = st.st_mtime, and kept this PR's one change: the session counter moves past the read, so an unreadable recent transcript counts only as could not load. Local gate (test/test_usage.py, flake8, isort, black, mypy, flake-pattern ratchet), local GPT and local Opus review passed on this tree; CI re-running.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 8, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 8, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. On head 573ac62 the review read the whole diff and traced every path through the _parse_sessions loop. Each transcript now adds to all_time_sessions at most once, and a transcript that fails to read counts only as could not load. In a scratch export of this head, 118/118 tests in test_usage.py and test_usage_kas_sessions.py pass. With the merge-base version of usage_sessions.py and the PR's test, test_file_read_oserror fails with assert 1 == 0. Removing either new increment alone also makes existing tests fail.
Done well: the fix moves the counter to the points where a transcript's outcome is known, rather than adding a decrement in the failure branch. The edited test checks both counters.
Optional: the Proof: line in the PR body names head 94097fd08767, which is from before the last rebase. Rerun the proof on 573ac62 and update the sha.

@bolichen97
bolichen97 merged commit 86a4fef into main Nov 8, 2026
154 of 156 checks passed
@bolichen97
bolichen97 deleted the fix/30423-usage-unreadable-double-count branch November 8, 2026 05:37
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 8, 2026
buluoray pushed a commit that referenced this pull request Nov 8, 2026
buluoray added a commit that referenced this pull request Nov 8, 2026
bolichen97 added a commit that referenced this pull request Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One unreadable transcript is counted both as a session and as "could not load"

2 participants