Repository navigation
fix(usage): count KAS sessions on the Usage page - #26951
Conversation
46370e0 to
3d33c28
Compare
buluoray
left a comment
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:
The change itself looks good: KAS sessions now count on the Usage page, and the targeted tests pass. One CI finding to fix before approval: SAST (Semgrep) rule test-naive-local-time flags datetime.now().astimezone() at test/test_usage_kas_sessions.py:103. Use a fixed instant or the existing local_tz fixture so the test does not depend on the runner's clock and zone. The Sensitive Change Review failure on this head is a GitHub API rate limit in its checker, not the code; it can be rerun.
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the page now reads the second session store that KAS actually writes to, the mtime/size cache keeps a warm parse affordable, and the response shape is unchanged. Notes
[DESIGN-REVIEWED] 6fe7145 Description read[DESCRIPTION-READ] ef021c807cdd9d4deb74941d6ec778f5e36af17c344539077c10b3f74e9af091 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, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. Issue #26948 and the table in the description show the defect. No KAS store reader exists in the repo yet, and the per-transcript cache is justified by the measured parse cost. Notes
What this change shipsInventory (5 items) — 3 justifiedIntent: an operator on the KAS backend sees their real session, message and tool-call activity on the Usage page. FIX.
[FIRST-PRINCIPLES-REVIEWED] 6fe7145 Description read[DESCRIPTION-READ] 0671d421597fd41fd23ed44f00fbdfdc42edabb1bfd222a30094fdf5ad5a4818 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
3d33c28 to
7012e0c
Compare
|
Fixed in 7012e0c. The period-summary test now uses the fixed |
buluoray
left a comment
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:
Thanks, the test fix for Semgrep looks right. One change before I approve: GPT's upheld finding holds. _kas_transcripts (src/kiro_crew/dashboard/handlers/usage_sessions.py:82) drops every OSError when listing a record directory, so an unreadable KAS directory silently disappears from the counts, and the page shows no incomplete-data warning. The kiro-cli path counts such failures in refused_transcripts. Please skip only FileNotFoundError / NotADirectoryError (a record torn down mid-listing), count other listing failures into refused_transcripts, and add a test for an unreadable record directory.
7012e0c to
93709cf
Compare
|
Fixed in Two behaviors change. A roaming-profile home, whose session directory the UNC gate refuses, gets the |
buluoray
left a comment
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:
Thanks for the pinned-listing hardening; skipping a linked record directory looks right, and so does surfacing the UNC refusal as an error. The earlier point is still open on 93709cf, though: in _kas_transcripts (src/kiro_crew/dashboard/handlers/usage_sessions.py:87-96) the per-record except OSError: continue still drops a record directory that can't be listed, with nothing counted in refused_transcripts. So an unreadable KAS directory vanishes from the Usage counts, the page shows no incomplete-data warning, and the low count is cached.
Please skip only FileNotFoundError / NotADirectoryError (a record torn down mid-listing), count any other listing OSError into refused_transcripts (the root names() failure too), and add a test for an unreadable record directory. Happy to approve once that's in.
93709cf to
2cc80dc
Compare
|
Fixed in 2cc80dc. New tests cover an unreadable record directory, a record directory that is removed or replaced by a file mid-listing, and an unreadable root. The refused-root test now asserts a zero count. |
|
@LucaButBoring thanks for the squash. One more red on 59e6afe:
The cause is the This change keeps the stand-in on Linux/macOS and uses the real Windows pin on Windows. Locally on Linux, diff --git a/test/test_usage_kas_sessions.py b/test/test_usage_kas_sessions.py
--- a/test/test_usage_kas_sessions.py
+++ b/test/test_usage_kas_sessions.py
@@ -400,16 +400,23 @@ def windows_cloud_files_pins(monkeypatch):
A cloud-files directory carries a reparse point that is not a link, which the
default Windows pin refuses and ``links_only=True`` pins. CI hosts cannot
create such a directory. The stand-in refuses each pin without ``links_only``
- and opens the others with the POSIX flags, which refuse a symlink.
+ and pins the others: with the real Windows pin on Windows, and elsewhere with
+ the POSIX flags, both of which refuse a link.
"""
+ import sys
+
import kiro_crew.platform_compat_links as links
calls: list[bool] = []
+ real_pin = links.pin_directory
def pin(path, *, links_only=False):
calls.append(links_only)
if not links_only:
raise NotADirectoryError(errno.ENOTDIR, "not a real directory", os.fspath(path))
+ if sys.platform == "win32":
+ # os.open cannot open a directory on Windows.
+ return real_pin(path, links_only=True)
return os.open(os.fspath(path), links.pinned_dir_flags())
monkeypatch.setattr(links, "IS_POSIX", False)Could you amend it into your second commit (59e6afe), so the PR stays at 2 commits for |
59e6afe to
588be98
Compare
|
@LucaButBoring main moved and this PR now conflicts: Could you rebase onto current main, keep the two commits as they are, and push? We won't push to your branch. |
588be98 to
fc628a2
Compare
|
@LucaButBoring thanks for the rebase. The remaining red shards on fc628a2 come from main, not from this PR: CI tested it merged onto main at 03016b6, where Could you rebase onto current main once more and push, keeping the two commits? We won't push to your branch. |
The Session Activity card and Daily History table read only kiro-cli's sessions/cli transcripts. The KAS harness writes each session to sessions/<id>/sess_<uuid>/messages.jsonl in another row format, so an install on the KAS backend showed almost no sessions and no messages or tool calls, while the same days showed real credit spend. The parse now also lists the KAS records beside the cli directory and counts their user rows, Say assistant rows and tool_call rows. A KAS record without a messages file is skipped, not reported as a failed load. Each transcript's counts are kept keyed on its mtime and size, so a refresh reads only the transcripts that changed.
Pin the KAS root and sessions/cli with links_only, as the upload path does, so a cloud-files or dedup folder is listed instead of read as missing or unreadable. KAS record directories opened through the root pin inherit links_only, so they are listed too. Links and junctions are still refused. Co-authored-by: Ray Xu <buluoray@gmail.com>
fc628a2 to
6fe7145
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Approving at 6fe7145. All checks pass and there are no change requests.
What I checked:
- The Usage page now also counts KAS sessions: each
<kas_root>/<id>/sess_<uuid>/messages.jsonlbeside kiro-cli'sclidirectory. Messages areuserrows andassistantrows withoperationType == "Say", so reasoning steps are not counted. Tool calls aretool_callrows. The kiro-cli row counting is unchanged. - A directory that cannot be listed adds one to the existing did-not-load total instead of failing the page. A directory removed mid-listing is skipped.
- Each transcript's counts are cached on
(st_mtime_ns, st_size)and rebuilt from what each parse saw, so a refresh rereads only changed files, and a deleted one drops out. - Listing goes through
_pin_listing_dir, which checks the path withvalidate_file_pathfirst. A link to a UNC share is refused before any open, so it cannot trigger an SMB authentication. Children are opened through the pin withlinks_only. A link planted at the name fails the open. - No regex.
|
This PR merged while the review was still running, so this is a post-merge note. The KAS counting itself checks out, and the listing-error handling in
Optional:
|
* fix(usage): count KAS sessions on the Usage page The Session Activity card and Daily History table read only kiro-cli's sessions/cli transcripts. The KAS harness writes each session to sessions/<id>/sess_<uuid>/messages.jsonl in another row format, so an install on the KAS backend showed almost no sessions and no messages or tool calls, while the same days showed real credit spend. The parse now also lists the KAS records beside the cli directory and counts their user rows, Say assistant rows and tool_call rows. A KAS record without a messages file is skipped, not reported as a failed load. Each transcript's counts are kept keyed on its mtime and size, so a refresh reads only the transcripts that changed. * fix(usage): list Windows cloud-files and dedup session folders Pin the KAS root and sessions/cli with links_only, as the upload path does, so a cloud-files or dedup folder is listed instead of read as missing or unreadable. KAS record directories opened through the root pin inherit links_only, so they are listed too. Links and junctions are still refused. Co-authored-by: Ray Xu <buluoray@gmail.com> --------- Co-authored-by: Ray Xu <buluoray@gmail.com> (cherry picked from commit 4182398) Original author: @LucaButBoring
* fix(usage): count KAS sessions on the Usage page The Session Activity card and Daily History table read only kiro-cli's sessions/cli transcripts. The KAS harness writes each session to sessions/<id>/sess_<uuid>/messages.jsonl in another row format, so an install on the KAS backend showed almost no sessions and no messages or tool calls, while the same days showed real credit spend. The parse now also lists the KAS records beside the cli directory and counts their user rows, Say assistant rows and tool_call rows. A KAS record without a messages file is skipped, not reported as a failed load. Each transcript's counts are kept keyed on its mtime and size, so a refresh reads only the transcripts that changed. * fix(usage): list Windows cloud-files and dedup session folders Pin the KAS root and sessions/cli with links_only, as the upload path does, so a cloud-files or dedup folder is listed instead of read as missing or unreadable. KAS record directories opened through the root pin inherit links_only, so they are listed too. Links and junctions are still refused. Co-authored-by: Ray Xu <buluoray@gmail.com> --------- Co-authored-by: Ray Xu <buluoray@gmail.com> (cherry picked from commit 4182398)
* fix(usage): count KAS sessions on the Usage page The Session Activity card and Daily History table read only kiro-cli's sessions/cli transcripts. The KAS harness writes each session to sessions/<id>/sess_<uuid>/messages.jsonl in another row format, so an install on the KAS backend showed almost no sessions and no messages or tool calls, while the same days showed real credit spend. The parse now also lists the KAS records beside the cli directory and counts their user rows, Say assistant rows and tool_call rows. A KAS record without a messages file is skipped, not reported as a failed load. Each transcript's counts are kept keyed on its mtime and size, so a refresh reads only the transcripts that changed. * fix(usage): list Windows cloud-files and dedup session folders Pin the KAS root and sessions/cli with links_only, as the upload path does, so a cloud-files or dedup folder is listed instead of read as missing or unreadable. KAS record directories opened through the root pin inherit links_only, so they are listed too. Links and junctions are still refused. Co-authored-by: Ray Xu <buluoray@gmail.com> --------- Co-authored-by: Ray Xu <buluoray@gmail.com> (cherry picked from commit 4182398)
Problem / Motivation
Goal: On an install that runs the KAS backend, the Usage page's Session Activity card and Daily History table count that install's sessions, messages and tool calls.
On an install with
agent.acp_backend: kas, the Session Activity card and the Daily History table show almost no sessions, while the Credits used column shows real spend for the same days. The table below compares the sessions that the page of such an install showed on 2026-11-01 with the records in its KAS session store. On each of those days the page also showed zero messages and zero tool calls.Why it matters
An operator on the KAS backend sees no session activity and cannot compare activity with spend. The 30-day totals that the card does show come from kiro-cli transcripts written before the switch to KAS, so they describe an older period than the card's labels claim.
Not a goal
What changed (motivation → approach → change)
_parse_sessionsindashboard/handlers/usage_sessions.pyread only kiro-cli's flat<kiro home>/sessions/cli/*.jsonlfiles. The KAS harness writes each session to<kiro home>/sessions/<id>/sess_<uuid>/messages.jsonlin a different row format, so on a KAS install the parse found only the kiro-cli transcripts left from before the switch. Those transcripts carry no row timestamps, and each one counted on its file's modification day.The parse now also lists the KAS records beside the
clidirectory and counts their rows. Auserrow or anassistantrow of operation typeSayis a message, which leaves out the KAS reasoning rows, and atool_callrow is a tool call. A KAS record without a messages file is skipped instead of being reported as a transcript that failed to load: the record holds only itssession.json, or the harness deleted it at session teardown after the scan listed it. The parse reads both stores on every install without checking the backend, and an install that switched backends counts the sessions from before and after the switch. The owning spec,docs/system-specs/modules/learn-cron-dashboard.md, describes the two stores and the counting rules.The KAS store adds thousands of transcripts to each parse, so the parse now keeps each transcript's counts keyed on the file's modification time and size. A later parse reads a transcript again only when either value has changed. The path validator and the
statstill run on every transcript. The validator takes most of the time of a refresh over unchanged transcripts. Its result stays uncached because a path that became a link since the last parse would then skip it.Backwards compatibility
Compatible: an install without KAS records gets the same statistics as before, and the response shape is unchanged.
Removes nothing: the change adds the KAS store as a second source. The kiro-cli
sessions/clilisting now also goes through the path check and a pinned open (_pin_listing_dir), which refuses only a reparse point that stands for another name, so a Windows cloud-files or dedup folder is still listed.Tests
test/test_usage_kas_sessions.pycovers the KAS store:userandSayrows as messages and itstool_callrows as tool calls.clidirectory.messages.jsonl, and a directory whose name does not start withsess_, count neither as sessions nor as failed loads.refused_transcripts, stays unread, and gets no counts from the cache that an earlier parse filled.Proof: PROVEN test/test_usage_kas_sessions.py::test_a_kas_record_is_counted_with_its_messages_and_tool_calls, test/test_usage_kas_sessions.py::test_kas_records_are_counted_when_the_cli_directory_does_not_exist, test/test_usage_kas_sessions.py::test_both_stores_are_counted_together, test/test_usage_kas_sessions.py::test_todays_kas_sessions_reach_the_period_summaries, test/test_usage_kas_sessions.py::test_an_old_kas_record_counts_toward_all_time_only (head 46370e0)
Determinism: each test in the new file passed 20 runs at
-n0, 10 runs at-n 4together withtest/test_usage.pyandtest/test_usage_daily_credits.py, and 5 shuffled orders of all tests in the file. The cache tests start from an empty cache, set throughmonkeypatch, and an earlier test cannot change their result.Manual verification
The patched
_parse_sessionsran read-only against the stores of an install on the KAS backend, on 2026-11-01:A parse whose transcripts have not changed takes about as long on this branch as a parse on main, although it covers 10 times as many sessions. The runs below were back to back on the same install, with a host load average near 50:
The first run reads about 2 GB of KAS transcripts. The parse runs off the event loop behind the 120 s response cache and the 50 ms request budget, and a request does not wait for it.
Related Issues
Closes #26948
Sibling sweep
Swept: git grep -n "kiro_sessions_dir()" -- src/
Sibling: src/kiro_crew/session_storage_parts/store_inventory.py:273 -- not affected -- it lists transcripts for Crew's retention and cleanup tools, and the KAS teardown policy in acp/harness/kas.py states that local transcript-retention choices are a no-op on that harness, which deletes each record itself.
Sibling: src/kiro_crew/session_digest.py:91 -- not affected -- it reads the kiro-cli event log of a single session, found by its id, for images and as a fallback count of turns, and aggregates across no sessions.
Pattern harvest
Rule candidate: review-prompt
Pattern: a reader of
kiro_sessions_dir()that aggregates over all sessions, with no branch for the stores of the other selectable harnesses.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)