Repository navigation
fix: count an unreadable transcript only as could not load - #32583
Conversation
|
[operator: bolichen97] Backend Tests shards 5 and 6 (Linux and Windows) fail on this head in 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. |
3582d23 to
be461e8
Compare
|
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. |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the counter now runs after the read succeeds, so every did-not-load branch feeds only Notes
[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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The change only moves one counter so that an in-window transcript is counted after its read succeeds. The deleted What this change shipsInventory (2 items) — 2 justifiedIntent: 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.
[FIRST-PRINCIPLES-REVIEWED] 573ac62 Description read[DESCRIPTION-READ] d50132232cd749793d63b88bb3804eaf58843d177e6655cab37f09490c8d20a9 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
be461e8 to
573ac62
Compare
|
Rebased: main moved in |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
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.
(cherry picked from commit 86a4fef)
(cherry picked from commit 86a4fef) Original author: @bolichen97
(cherry picked from commit 86a4fef)
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: 1andrefused_transcripts: 1for 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
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_sessionswas incremented before the transcript was opened, so a failed read put the same file inrefused_transcriptson 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 onlyrefused_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_oserrornow pins the single count for a recent transcript whoseopen()raisesOSError:all_time_sessions == 0andrefused_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=2besidetest/test_usage_series.pyandtest/test_usage_scrape_editable.py, and all 98 tests oftest/test_usage.pypassed 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)