Skip to content

feat(members): show the credits a Bot's work used on its Goals tab - #37665

Merged
buluoray merged 1 commit into
mainfrom
crew/slack/goal-cost-on-goals-tab
Nov 15, 2026
Merged

buluoray merged 1 commit into
mainfrom
crew/slack/goal-cost-on-goals-tab

Conversation

@buluoray

@buluoray buluoray commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Part of #37361

Problem / Motivation

Goal: A Bot's Goals tab shows the credits that the Bot's work has used, right under its goals.

The owner in #37361 gave a Bot a goal and let it run for days. The goal and its milestones say what the Bot believes, and nothing on the Bot's page shows what the work spent. The per-task cost already exists: the workstreams crew-log fold joins each work item to the charges of the worker session bound to it. Only a page the Bot writes itself (project report, org chart) reads that fold today, so an owner who never asked for such a page sees no number at all.

Why it matters

An owner who cannot see what a goal has cost cannot tell when to stop or narrow the work. This is the "what was spent" half of the third ask in #37361, and the number the later per-goal limits would be measured against.

Not a goal

What changed (motivation → approach → change)

The Goals tab gets a Credits used card right after Goals.

What the gateway read The card says
Charges reported by the worker sessions 42.5 credits
The same, but the fold dropped boards, tasks, units or spenders At least 42.5 credits
No metered charge at all Not reported (never 0)
The fold is not warm yet Still counting
The fold could not be read no card; the goals still load
The Bot's thread binding names another Bot (a shared slug, or a deleted Bot's leftover thread) or no thread exists no card

GET /api/members/{slug}/goals adds a spend field (dashboard/handlers/member_goals.py, typed as GoalSpend in api/client/agents.ts). work_spend sums the task rows of the workstreams fold for the Bot's thread slot, and counts each worker session once by the fold's per-render spender alias, so a worker that served three tasks is billed once. The route reads the fold with cold=False: a cold slot answers pending and asks one background prime, so the request never folds every unit on the loop. Goal writes do not read the crew log; the Goals tab and the Heartbeat row keep the spend line they already have when a write answer comes back without one.

What the number includes and what it leaves out. It is the credits that the turn, subagent and background closers of each session bound to a work item reported (work/charged, relayed into the board's log). It leaves out the Bot's own chat turns, sessions that were never bound to a work item, and anything a provider did not meter. It does not touch the Telemetry spend table that #37407 changes, does not implement the attribution rule that the #35488 RFC proposes, and does not fix #21973 (subagent spend missing from turn and session totals in Telemetry); a subagent's charge counts here only when the bound worker's own log recorded it with credits.

New strings are in all 12 locales (i18n/locales/*.json, with en-XA.json regenerated); docs/system-specs/modules/crew-mode.md describes the card.

Backwards compatibility

Compatible: the GET answer gains one optional field, spend; every existing field and route is unchanged, and the frontend treats a missing field as no card.

Removes nothing: the change adds one field and one card; no key, route, record or reader is changed or dropped.

Tests

  • test/test_member_goals_spend.py (new): one worker bound to two tasks counts once; no charge reads not_reported, not zero; any dropped board, task, unit or spender reads partial; a malformed value reads not_reported; the GET route carries the line and reads only workstreams with cold=False; a cold slot reads pending and schedules one prime; only the Bot that the thread's DM binding names sees its spend, and another Bot on the same slug (before or after the owner is deleted) or a Bot with no thread gets spend: null without reading the fold; an unreadable fold gives spend: null with a 200; a goal write does not read the fold.
  • website/src/pages/members/CrewGoals.test.tsx: the card sits between Goals and Milestones; At least, Not reported (and no 0), Still counting; no card on null; the line survives a milestone removal and a Heartbeat toggle, whose answers carry no spend.
  • Mutation checks: summing a worker per task (double count), dropping the not_reported branch, and replacing the cache merge in CrewGoals.tsx or CrewHeartbeat.tsx each turn a test red.
  • Determinism: the backend file passed 5 repeats and a shuffled order; the frontend file passed 3 runs with --sequence.shuffle.
  • Gates: black, isort, flake8, mypy, comment-history, brand-name, file-line-cap, flake-pattern ratchet, semgrep, i18n:check with I18N_BASE_REF, the src/i18n/ vitest layer, tsc, eslint and npm run build pass. The related backend set (1356 files) has 57 failures in five files (file_explorer/tests/test_server.py, test_cli.py, test_cli_stt_memory_doctor.py, test_apps_registry_identity_admission.py, test_auto_improvement_members.py); the same 57 fail on a clean checkout of the base commit on this host, so they are environment failures, not this change. The related frontend set (567 files) passes.

Manual verification

Component renders with mocked data (below). No live gateway was used.

Screenshots / video

Component render, not the live page. Mocked data.

Reported, light:

Credits used card, reported, light theme

At least (dark), Not reported (light) and Still counting (dark)

Credits used card, partial, dark theme

Credits used card, not reported, light theme

Credits used card, still counting, dark theme

Related Issues

Part of #37361

Related, not duplicated: #37407 (Telemetry spend table outcome columns), #35488 (RFC for subagent credit attribution), #21973 (subagent spend missing from totals).

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

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 15, 2026 18:43
@buluoray
buluoray enabled auto-merge (squash) November 15, 2026 18:44
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 6d5d3d04f40eaa73aba1c04723a0b2bbe0a31b20 — 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: the card is a new view next to the goals, built on the existing workstreams fold and its cold-read pattern, and no default changes.

What this change ships

Inventory (6 items) — 6 justified

Intent: let a Bot's owner see what the Bot's work has spent so far, next to its goals. This is an ADDITION.

  1. The Goals tab shows a new Credits used card between Goals and Milestones. — justified
  2. When nothing was metered the card says "Not reported" instead of 0, and it says "At least" when the fold dropped boards, tasks, units or workers. — justified
  3. Before the fold is warm the card says "Still counting", and opening the tab starts one background prime. — justified
  4. The card is hidden when the thread's binding names a different Bot, when no thread exists, or when the fold can't be read. — justified
  5. GET /api/members/{slug}/goals gains an optional spend field. — justified
  6. Saving a goal or toggling Heartbeat keeps the spend line already on screen. — justified

[FIRST-PRINCIPLES-REVIEWED] 6d5d3d0

Description read

[DESCRIPTION-READ] 0a5dee93dc7158aae4cb6eb90e32ccdf5eb0370241f8ba325c1de21680c07f11

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 6d5d3d04f40eaa73aba1c04723a0b2bbe0a31b20 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change adds an optional field and a card on top of the workstreams fold's own per-spender roll-up, which already supports this. The request path never folds cold, and screenshots of the card are attached.

Notes

[DESIGN-REVIEWED] 6d5d3d0

Description read

[DESCRIPTION-READ] 3151473ed961ae90aa12e7093345ab5e682cb4cc73478d525b6c1246c74a26af

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

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 6d5d3d04f40eaa73aba1c04723a0b2bbe0a31b20 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

No blockers. All four card states are in the screenshots, and the blind reader correctly read "Credits used" as what the work has cost so far.

Notes

  • goals_spend_hint "Credits reported by the sessions doing {{name}}'s tasks." uses "sessions", which the reader didn't know. It also contradicts "Not reported" when the two sit together. Hide the hint in that state, or reword it to "Counts the work on {{name}}'s tasks; excludes chat."
  • "Not reported" and "Still counting" both read as "no number". The query doesn't refetch while the status is pending, so "Still counting" stays on screen until the page is opened again. The reader said: "I don't know whether I should wait or reload." Either poll while pending, or say "Still counting — check back shortly."
  • "At least 42.5 credits" doesn't say what's missing. The reader said: "makes me unsure whether I can trust the number." Add a short reason, e.g. "Some tasks weren't counted."

[UX-REVIEWED] 6d5d3d0

Description read

[DESCRIPTION-READ] 8602dd5a286438ef8f3c261cddfac44b39fb685d7b512ceeb6fcf8a6f0b2a06c

That sha256 names everything this verdict read: the PR description, plus the 7 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 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 6d5d3d04f40eaa73aba1c04723a0b2bbe0a31b20 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6d5d3d0

Verdict parsed from the review's SHA-scoped output markers for commit 6d5d3d04f40eaa73aba1c04723a0b2bbe0a31b20.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 6d5d3d04f40eaa73aba1c04723a0b2bbe0a31b20 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 6d5d3d04f40eaa73aba1c04723a0b2bbe0a31b20 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6d5d3d0

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 6d5d3d04f40eaa73aba1c04723a0b2bbe0a31b20 false-positive: <reason, 20 to 500 characters>

@KiroCrewCaptain

KiroCrewCaptain commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, but it changes 521 lines, more than the 400 it may approve on its own.

Additive change: GET /api/members/{slug}/goals gains an optional spend field, and the Goals tab shows a Credits used card. Verified against the code: work_spend counts each worker session once through the fold's per-render spender alias. That matches how the workstreams render works: a task's credits is the bound worker's whole bill, and board totals already count each distinct worker once. No credits_reported gives not_reported, never 0, and any omitted counts mark the total partial. The route reads the fold with cold=False off the loop, and a cold fold gives pending plus one background prime, matching existing request-path callers. The thread-binding check (member and slot_key) mirrors the agent half's _agent_member guard. Read failures give spend: null with a 200. Goal write routes do not read the fold. The only two cache writers (CrewGoals and CrewHeartbeat) keep the spend line already shown, and ChangeCard invalidates, so its refetch brings spend back. Backend and frontend tests cover every state and both binding-mismatch cases. CI is green.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 6d5d3d04f4 · 521 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@buluoray

Copy link
Copy Markdown
Contributor Author

Render Benchmark (counter budgets) is red for a reason outside this diff: Playwright cannot install Chromium on the ubuntu-26.04 runner image (ERROR: Playwright does not support chromium on ubuntu26.04-x64, https://github.com/kirodotdev/KiroCrew/actions/runs/43748388324/job/132918556271). The same lane is red on main: #37645, fix in #37653. This PR waits for that fix and will rebase onto it.

@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 15, 2026
@buluoray
buluoray force-pushed the crew/slack/goal-cost-on-goals-tab branch from d2cdf7a to 0fa8fec Compare November 15, 2026 19:46
@buluoray

Copy link
Copy Markdown
Contributor Author

span=eecd55cefe1e
self-added: no

  • Attribute spend only to the thread's owning Bot

fixed in 0fa8fec: _read_work_spend returns None unless _member_names_for_slug(cfg, slug) == [member], so two Bots on one slug show no card and the shared fold is not read.
Test: test_two_bots_on_one_slug_show_no_spend seeds scout and Scout!, asserts spend: null and zero fold reads; turning the guard off makes it red.

@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 15, 2026
@buluoray
buluoray force-pushed the crew/slack/goal-cost-on-goals-tab branch from 0fa8fec to 6d5d3d0 Compare November 15, 2026 20:21
@buluoray

Copy link
Copy Markdown
Contributor Author

span=eecd55cefe1e
self-added: yes
mechanism: roster-uniqueness guard in _read_work_spend, replaced by a DM-binding ownership check

  • Check persisted thread ownership after a colliding Bot is deleted

fixed in 6d5d3d0: _read_work_spend reads members_mod.read_dm_binding(slug) and returns None unless it names this member and the derived slot, the check the agent half of this module already makes. It replaces the roster check from the last round: a shared slug, a deleted owner's leftover thread and a Bot with no thread all read no spend.
Tests: test_spend_is_shown_only_to_the_bot_the_thread_is_bound_to (before and after deleting the owner) and test_a_bot_with_no_thread_reads_nothing; dropping the member check or the whole guard turns them red.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 15, 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 head 6d5d3d04f40e.

What I checked

  • member_goals.work_spend: counts each worker once through the per-render spender alias, only for rows with credits_reported is True, returns not_reported (never 0) when nothing was metered, and marks partial when the fold dropped boards, tasks, units or spenders.
  • _read_work_spend: reads with cold=False off the loop, schedules one background prime on SlotFoldNotReady, and returns null unless the thread's DM binding names this Bot and this slot, so a shared slug or a deleted Bot's leftover thread shows nothing. Any read error gives spend: null with a 200, so the Goals GET cannot fail because of the card.
  • Writes do not read the crew log; both cache writers (CrewGoals, CrewHeartbeat) keep the spend line already shown.

Tests run locally on this head

  • Backend: test/test_member_goals_spend.py plus the other test/test_member_goals*.py files: 252 passed.
  • Frontend: src/pages/members/CrewGoals.test.tsx: 53 passed.
  • All CI checks pass on this head (none pending); the Render Benchmark red mentioned earlier is gone.

Optional (non-blocking)

  • CrewGoals.tsx SpendCard: the query does not refetch while status is pending, so "Still counting" stays until the tab is opened again (the UX review noted the same). A short refetchInterval while pending, or "Still counting, check back shortly", would fix it. Fine as a follow-up.

AI-assisted, sent by Bolin Review bot

@buluoray
buluoray merged commit 7d8aa4e into main Nov 15, 2026
98 checks passed
@buluoray
buluoray deleted the crew/slack/goal-cost-on-goals-tab branch November 15, 2026 22:13
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 15, 2026
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.

Turn and session credit totals leave out subagent spend

3 participants