Repository navigation
feat(usage): add owner-only usage per team - #331
agent-relay-code[bot] wants to merge 6 commits into
Conversation
GET /api/v1/organizations/{organizationId}/usage/teams and its audit
list, behind both the teams and usage_people features. Each session
read from the read API's session list is counted in exactly one row
(a team, a set of teams, no team, unattributed or not resolved), so
the rows sum to the total. Searches come from usage_people_daily. A
person's team is the assignment open at the end of the range, else
the one that closed last inside it. Reads use the People view's
bounds and a truncated read is labelled. No migration.
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
The team report dropped a session when the same harness and session id had already been read from another workspace. The People view and the Usage page count such a session in each workspace, so a team of one could show fewer sessions than that person. The key now includes the workspace; a session listed twice for one workspace still counts once. Tests added for the tiebreak between two closed assignment windows and for an archived team that only a cross-team row names. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Source finding at fe97cb5: teamsReport caches the session sample by org, user, date range and workspace IDs. ownerIdentities also supplies the workspace role, caller credential and readerKind; the History reader deliberately includes all three in its own token-cache identity (src/sessions/history.ts). A second credential or reader context for the same owner can hit the Teams cache without its upstream read being authorized. Partition the sample by the complete effective History reader context (use a credential digest, never a raw token), or avoid sharing cached reads across those contexts. Add a regression that warms the cache, changes reader context while retaining the same user and workspace IDs, and requires a fresh upstream authorization. The user-role and feature checks at the HTTP route do not distinguish these contexts. I pushed the main refresh; this is a source finding, not independent approval.
Adds the owner-only usage report per team from
docs/specs/team-model.md(sections 4 to 7), for sessions and searches. Depends on the organization teams from #326.Routes
GET /api/v1/organizations/{organizationId}/usage/teams?days=7|30|90GET /api/v1/organizations/{organizationId}/usage/teams/auditBoth are owner-only (admins and the bootstrap bearer get 403
forbidden) and need bothteamsandusage_peopleselected: a team of one shows one person's figures, so an installation that turned the People view off does not get them through teams. Neither feature is selected by default.Grouping
crossTeamrow for a set of teams (nullfor a person with no team),noTeam,unattributedornotResolved. The rows'sessionssum tototal.sessions.teamAsOf(the end of the range, or now when that is earlier): the assignment open then, else the one that closed last inside the range, else none. One query per report, limited to the organization.searchescome fromusage_people_daily.notResolvedstays 0 until the read API can group by user set. The grouping function already takes those buckets.spendisnullin every row and listed inunavailable.Bounds
The People view's bounds apply (pages of at most 200, at most 3 calls and 2 seconds), with a 5-minute cache of its own. A report that did not read every session is labelled
truncated, and its session figures are lower bounds. If the read API cannot be read, session figures arenulland searches are still served.Audit
Every served report, cached or not, writes an organization-level
usage.teams.viewedrow. The People audit list is unchanged.Not changed
People view behaviour (
src/usage/people.tsonly exports existing helpers). No migration, no new table, no new feature name, no dashboard change.Checks run locally at this head
tsc --noEmit: cleantest/usage-teams.test.ts: 10 of 10test/sessions.test.ts: 50 of 50The full suite is left to CI.
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by cubic
Adds owner-only usage per team: a report and an audit list under
/api/v1/organizations/{organizationId}/usage/teams, requiring both theteamsandusage_peoplefeatures. Admins and the bootstrap bearer get 403forbidden.total.sessions; searches come fromusage_people_daily. A session listed twice for one workspace counts once, while the same session id in two workspaces counts in each.teamAsOf— the open assignment, else the one that closed last inside the range — so moves and removals count under the later team.truncated, and an unreachable read API leaves session figuresnullwhile still serving searches.usage.teams.viewedaudit row.Written for commit a1c5282. Summary will update on new commits.