Skip to content

fix(usage): count KAS sessions on the Usage page - #26951

Merged
bolichen97 merged 2 commits into
kirodotdev:mainfrom
LucaButBoring:crew/mate/usage-kas-sessions
Nov 8, 2026
Merged

bolichen97 merged 2 commits into
kirodotdev:mainfrom
LucaButBoring:crew/mate/usage-kas-sessions

Conversation

@LucaButBoring

@LucaButBoring LucaButBoring commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

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.

Day Sessions shown Sessions in the KAS store
10-26 0 693
10-27 1 365
10-28 0 410
10-29 0 258
10-30 0 355
10-31 2 471
11-01 0 39

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

  • Changing the Today, This Week and This Month boundaries. They are calendar periods, so on the first day of a month This Month covers a single day and can be smaller than This Week.
  • Reading the session stores of the other harnesses, such as Claude or Codex.
  • Changing the other readers of the kiro-cli transcript directory, such as the storage inventory.

What changed (motivation → approach → change)

_parse_sessions in dashboard/handlers/usage_sessions.py read only kiro-cli's flat <kiro home>/sessions/cli/*.jsonl files. The KAS harness writes each session to <kiro home>/sessions/<id>/sess_<uuid>/messages.jsonl in 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 cli directory and counts their rows. A user row or an assistant row of operation type Say is a message, which leaves out the KAS reasoning rows, and a tool_call row 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 its session.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 stat still 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/cli listing 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.py covers the KAS store:

  • A KAS record counts as a session on the local day of its first row, with its user and Say rows as messages and its tool_call rows as tool calls.
  • KAS records count on an install that has no cli directory.
  • kiro-cli and KAS sessions add up in the totals.
  • Sessions recorded today reach Today, This Week and This Month. The test freezes the parse's clock at the rows' instant, so a day, week or month boundary during the run cannot change the result.
  • A KAS record older than the 30-day window counts toward the all-time total only.
  • A KAS record without messages.jsonl, and a directory whose name does not start with sess_, count neither as sessions nor as failed loads.
  • A second parse reads again only the transcript that changed, and that transcript's new rows reach the totals.
  • A deleted transcript's counts leave the cache on the next parse.
  • A KAS path rejected by the path validator counts in 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 4 together with test/test_usage.py and test/test_usage_daily_credits.py, and 5 shuffled orders of all tests in the file. The cache tests start from an empty cache, set through monkeypatch, and an earlier test cannot change their result.

Manual verification

The patched _parse_sessions ran read-only against the stores of an install on the KAS backend, on 2026-11-01:

Before After
Today 0 sessions, 0 messages, 0 tool calls 39 sessions, 144 messages, 1,228 tool calls
This Week 3 sessions, 0 messages, 0 tool calls 2,591 sessions, 19,937 messages, 53,214 tool calls
Sessions in the 30-day window 397 4,167
Transcripts that failed to load 0 0

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:

Parse Sessions Time
main 397 4.8 s and 7.0 s, in two runs
This branch, first run 4,197 36.9 s
This branch, next run 4,197 7.9 s

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

  • 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

@LucaButBoring
LucaButBoring requested review from a team and KiroCrewCaptain as code owners November 1, 2026 06:29
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Nov 1, 2026
@LucaButBoring
LucaButBoring force-pushed the crew/mate/usage-kas-sessions branch from 46370e0 to 3d33c28 Compare November 5, 2026 05:49

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 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.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 6fe714505f2bfb301250efb09d34c76f07e42f24 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 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 6fe714505f2bfb301250efb09d34c76f07e42f24 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • PinnedDirectory.child now passes links_only down to children on POSIX too. This change is in shared platform_compat_links and only the tests use it on POSIX. Before merge, confirm that no other pinned_directory(..., links_only=True) caller, such as pinned_delete.py:466, starts behaving differently when its children run the Windows branch.

[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 .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 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 6fe714505f2bfb301250efb09d34c76f07e42f24 via the fork AI-review pipeline — 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

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

  • Item 4 — rides along: the sessions/cli listing moves from iterdir() to _pin_listing_dir with no reported defect for that directory. The description only says it "now also goes through the path check and a pinned open". Subtraction: keep sessions_dir.iterdir() for the cli listing and use _pin_listing_dir only in _kas_transcripts. The eight test-stub rewrites to _files_validate_as in test_usage.py and test_usage_daily_credits.py would then go too.
  • Item 5 — undeclared: PinnedDirectory.child now passes links_only down to its children on POSIX as well. The description never mentions this change to a shared primitive. Subtraction: drop the POSIX-branch edit in platform_compat_links.py, since its only reader here is the test fixture that sets IS_POSIX to false.

What this change ships

Inventory (5 items) — 3 justified

Intent: an operator on the KAS backend sees their real session, message and tool-call activity on the Usage page. FIX.

  1. Usage page counts KAS sess_*/messages.jsonl records as sessions, messages and tool calls — justified
  2. A KAS record without a messages file is skipped instead of counted as a failed load — justified
  3. Per-transcript counts cached on mtime+size, so a refresh rereads only transcripts that changed — justified
  4. sessions/cli listing now goes through the path check and a pinned open — rides along, no reported defect
  5. PinnedDirectory children inherit links_only on POSIX — undeclared, shared primitive

[FIRST-PRINCIPLES-REVIEWED] 6fe7145

Description read

[DESCRIPTION-READ] 0671d421597fd41fd23ed44f00fbdfdc42edabb1bfd222a30094fdf5ad5a4818

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 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 6fe714505f2bfb301250efb09d34c76f07e42f24 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6fe7145

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 6fe714505f2bfb301250efb09d34c76f07e42f24 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6fe7145

@LucaButBoring
LucaButBoring force-pushed the crew/mate/usage-kas-sessions branch from 3d33c28 to 7012e0c Compare November 6, 2026 00:38
@LucaButBoring

Copy link
Copy Markdown
Contributor Author

Fixed in 7012e0c. The period-summary test now uses the fixed _STAMP instant with the zone pinned by local_tz, and the Semgrep determinism rules report no findings on the file.

@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 6, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 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.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@LucaButBoring
LucaButBoring force-pushed the crew/mate/usage-kas-sessions branch from 7012e0c to 93709cf Compare November 6, 2026 02:44
@LucaButBoring

Copy link
Copy Markdown
Contributor Author

Fixed in 93709cfe1f. We now validate the KAS root and sessions/cli with validate_file_path, pin each canonical path with pin_directory and list each directory through its pin. Each KAS record directory is opened through the root's pin, so a link at its name fails the open instead of being followed. The change is in _pin_listing_dir, _kas_transcripts and the cli listing, and the new tests check that a linked record directory, a refused session root and a linked cli directory are never listed.

Two behaviors change. A roaming-profile home, whose session directory the UNC gate refuses, gets the sessions_dir_unreadable error instead of zero counts. A link to a local directory under the KAS root is skipped.

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 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.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@LucaButBoring
LucaButBoring force-pushed the crew/mate/usage-kas-sessions branch from 93709cf to 2cc80dc Compare November 6, 2026 04:03
@LucaButBoring

Copy link
Copy Markdown
Contributor Author

Fixed in 2cc80dc. _kas_transcripts now skips a directory that raises FileNotFoundError or NotADirectoryError and counts any other listing OSError once in refused_transcripts, at the root and at each record directory. A root that fails the path check still adds no count.

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.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 6, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@buluoray

buluoray commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@LucaButBoring thanks for the squash. One more red on 59e6afe: New-test stability (windows-latest) fails the two new tests:

  • test_cloud_files_session_directories_are_listed_on_windows: _parse_sessions() returns code: sessions_dir_unreadable
  • test_a_linked_record_directory_is_still_skipped_on_windows: all_time_sessions is 0, expected 1

The cause is the windows_cloud_files_pins fixture: its stand-in pin opens each directory with os.open(path, pinned_dir_flags()), and os.open cannot open a directory on Windows, so every pin fails there. The product code is fine (test_a_windows_special_directory_is_still_listed passes on Windows because it calls the real pin_directory).

This change keeps the stand-in on Linux/macOS and uses the real Windows pin on Windows. Locally on Linux, test_usage_kas_sessions.py, test_pinned_directory.py and test_junction_link_fences.py pass (82 passed, 1 skipped), and flake8, isort and black are clean. I could not run it on Windows, so windows-latest is the real check.

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 PR Hygiene? We won't push to your branch.

@LucaButBoring
LucaButBoring force-pushed the crew/mate/usage-kas-sessions branch from 59e6afe to 588be98 Compare November 7, 2026 00:25
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 7, 2026
@buluoray
buluoray dismissed iamwhatever’s stale review November 7, 2026 06:01

Dismissed by maintainer: this review was on the old head 1d58173; the requested changes are addressed on head 588be98, where every AI lane passes.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 7, 2026
@buluoray

buluoray commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@LucaButBoring main moved and this PR now conflicts: src/kiro_crew/platform_compat_links.py clashes with #31676 (the Windows session-trash removal change), which edited the same area. The other files merge cleanly.

Could you rebase onto current main, keep the two commits as they are, and push? We won't push to your branch.

@LucaButBoring
LucaButBoring force-pushed the crew/mate/usage-kas-sessions branch from 588be98 to fc628a2 Compare November 7, 2026 20:29
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 7, 2026
@buluoray

buluoray commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@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 test_the_lazy_imports_stay_inside_the_functions_that_need_them and test_held_note_turn_starts were failing. Both pass on current main (the first was fixed by #32606). A rerun would test the same old merge, so it would fail the same way.

Could you rebase onto current main once more and push, keeping the two commits? We won't push to your branch.

LucaButBoring and others added 2 commits November 7, 2026 23:28
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>
@LucaButBoring
LucaButBoring force-pushed the crew/mate/usage-kas-sessions branch from fc628a2 to 6fe7145 Compare November 7, 2026 23:58
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 8, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.jsonl beside kiro-cli's cli directory. Messages are user rows and assistant rows with operationType == "Say", so reasoning steps are not counted. Tool calls are tool_call rows. 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 with validate_file_path first. A link to a UNC share is refused before any open, so it cannot trigger an SMB authentication. Children are opened through the pin with links_only. A link planted at the name fails the open.
  • No regex.

@bolichen97
bolichen97 merged commit 4182398 into kirodotdev:main Nov 8, 2026
101 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 8, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

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 _kas_transcripts is careful and well tested. One regression is now on main and needs a follow-up fix.

  1. src/kiro_crew/dashboard/handlers/usage_sessions.py:214-217 (with _pin_listing_dir at line 132). The sessions/cli listing now goes through validate_file_path on the directory itself. On a Windows home stored on a network share (a roaming profile, or a kiro home on \\host\share), the UNC check refuses that directory, because unc_probe_allowed trusts only the data home, the temp dir and the agents dir. Line 217 raises, and the payload gets error: 'cannot read sessions directory' with code sessions_dir_unreadable. api_kiro_usage copies that error into the response. In the frontend, acp.ts throws on s.error before it reads billing, so the Usage tab shows only an untranslated error card. On main, the same install saw its plan, credits and spend, plus the localized refused_transcripts_warning written for this exact network-drive case. Billing does not depend on transcripts, so it should not disappear. Smallest fix: keep iterdir() for the cli listing and pin only the KAS root. Or, when _pin_listing_dir returns None, leave error unset and count the refusal in refused_transcripts. Do the same for a refused KAS root at line 83, which today returns ([], 0) and drops its sessions with no refused count. Please also restore a test where validate_file_path refuses the directory itself (not only files, as _files_validate_as(None) does) and assert that error is absent and refused_transcripts > 0.

  2. Description and comments. The Backwards compatibility section says "Removes nothing" and "the response shape is unchanged", but item 1 changes what a UNC-home install receives. If you keep the directory pin, please add a Reader: line for that payload (api_kiro_usage and the Usage tab's error rendering), as docs/system-specs/common/take-away-changes.md asks. You can do that with a PR comment. The comments at lines 246-255 and 371-375 still say every UNC transcript reaches the per-file refusal branch, which is no longer true at this head. Please correct them either way.

Optional:

  • The transcript loop now makes about 10x more default-gate validate_file_path calls, and each one goes through the shared path-resolution pool. validate_file_path(..., canonical_gate=True) is the form the codebase uses for bulk reads on a worker thread.
  • The cache check at line 282 is only half pinned. Dropping either st_size or st_mtime_ns from the comparison reds no test. Two cases (same-size rewrite with a new mtime, and an append with the old mtime restored via os.utime(ns=...)) would pin it.
  • The POSIX hunk in platform_compat_links.py:641-643 has no effect on any platform: POSIX children never read _links_only, and the non-POSIX branch already passed it on main. Consider dropping it, or mention it in the description.

buluoray added a commit that referenced this pull request Nov 8, 2026
* 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
buluoray added a commit that referenced this pull request Nov 9, 2026
* 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)
buluoray added a commit that referenced this pull request Nov 9, 2026
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Usage page counts almost no sessions on the KAS backend

5 participants