Skip to content

fix(stats): await the async dashboard scope filter (#795) - #806

Merged
jeff-r2026 merged 2 commits into
Tencent:mainfrom
SaulMoro:fix/main-stats-async-scope-filter
Sep 24, 2026
Merged

jeff-r2026 merged 2 commits into
Tencent:mainfrom
SaulMoro:fix/main-stats-async-scope-filter

Conversation

@SaulMoro

Copy link
Copy Markdown
Collaborator

Follow-up to #795 and #771: main is red since 352cfc4

Summary

#771 and #795 each passed review alone, but together they break teamai stats. #795 changed the scope filter's contract and moved the reported snapshots, and #771's call sites in stats.ts still use the old ones.

 showStats
-  filterEventsByScope(events, { projectRoot } | { excludeProjectRoots })   // sync, old argument
+  await filterEventsByScope(events, config)                               // the call pull makes
   unreportedDashboardStats
-    readJson(~/.teamai/dashboard/reported-*.json)                         // no longer written since #795
+    readReportedInterventions(config) / readReportedPromptTokens(config)  // the scope's own, as pull reads

Evidence

origin/main this PR
npx tsc --noEmit 4 errors in src/stats.ts clean
npx vitest run 11 failed (stats-scope.test.ts: events is not iterable) 303 files, 4640 passed, 1 skipped
new test: own snapshot vs stale shared one expected 2 to be 1 passes
npm run build builds (tsup does not type-check) builds

Real CLI, sandbox HOME, run from the project: project scope (http), team file holds 1 session, events hold sess-1 (reported) and sess-2 (new) in this scope plus sess-3 from another scope, shared snapshot {}, project snapshot has sess-1.

before$ teamai stats --by-repo
TypeError: events is not iterable
    at aggregateSessionMetrics ... at showStats                exit=1

after$ teamai stats --by-repo
  Sessions:           2          # 1 reported + sess-2; sess-3 out, sess-1 once
  Conversation turns: 2
  Tokens (total):     300
By Repo (local event log):
  proj-a  2 sess, 2 turns, 0 tools, 300 tok                    exit=0

Covered one agent-independent path (stats reads local files only); no provider × agent matrix.

Merge Danger

Door: two-way

Local read path only; nothing written to the team repo. A stats run seeds the scope snapshot from the shared file once, the same seed the next pull would write.

Blast Radius: teamai stats

Headline and --by-repo / --by-time for the user scope no longer count events recorded before events carried a data home, matching what pull reports.

Tencent#795 made filterEventsByScope async and changed its argument from a
projectRoot/excludeProjectRoots filter to the scope config, while Tencent#771
still called it synchronously with the old filter. On main, tsc fails in
stats.ts and every stats-scope test throws "events is not iterable";
`teamai stats` crashes once there are dashboard events.

stats now awaits the filter and passes the scope config, the call pull
makes, which is what Tencent#771 set out to do: show what the report sends.
The cwd-based project-root resolution is gone with the old argument.

The user-scope test followed pull's rule before Tencent#795 (keep events that
carry no dataHome); it now follows the current one: the user scope
never reports them, so it does not count them.
Since Tencent#795 each scope reports against its own reported-*.json under its
data home, and the shared ~/.teamai/dashboard files are no longer
written. stats still subtracted the shared files, so after the upgrade
every session reported since counted twice in the headline.

stats reads the snapshots through team-push's readers with the scope
config, including the one-time seed from the shared file.
@SaulMoro

Copy link
Copy Markdown
Collaborator Author

@jeff-r2026 heads-up: main has been red since 352cfc4 (#795), and this PR fixes it.

c3bfef3  #771  stats.ts calls the dashboard scope filter synchronously
352cfc4  #795  the filter becomes async (it carried #791's first commit)
         → 4 tsc errors in src/stats.ts, 11 failing tests in stats-scope.test.ts,
           and `teamai stats` crashes with "events is not iterable"

Each PR was green on its own; the break only shows once both are on main. The second commit fixes the other half of the same clash: stats still subtracted the shared reported-*.json that #795 stopped writing, so it would have counted newly reported sessions twice.

The other open #752 PRs, once rebased onto main, show the same stats failures until this one lands, so it would help to merge this one first.

@SaulMoro
SaulMoro requested a review from jeff-r2026 September 24, 2026 11:41
@jeff-r2026 jeff-r2026 self-assigned this Sep 24, 2026
@github-actions

Copy link
Copy Markdown

No findings.

The PR description provides sufficient testing evidence, including a representative real-CLI end-to-end run for the runtime behavior change.

@jeff-r2026
jeff-r2026 merged commit fd0e913 into Tencent:main Sep 24, 2026
10 checks passed
@SaulMoro
SaulMoro deleted the fix/main-stats-async-scope-filter branch September 24, 2026 11:50
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.

2 participants