Skip to content

Add cc-stats telemetry report - #46

Merged
datacas merged 2 commits into
mainfrom
issue-42-cc-stats
Sep 23, 2026
Merged

datacas merged 2 commits into
mainfrom
issue-42-cc-stats

Conversation

@datacas

@datacas datacas commented Sep 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add a read-only, repository-scoped telemetry report with date windows, historical totals, sample-aware approval rates, trends, role/profile counts, operational outcomes, verification, measured duration/cost, and Jev shadow comparisons.
  • Add and register the cc-stats supporting skill across package validation, runtime installation, skill discovery, and the README.
  • Keep private identifiers and raw telemetry out of the report; leave missing measurements unknown.

Work item: #42

Verification

  • python3 scripts/validate-package.py — passed
  • python3 -m unittest discover -s tests -v — 587 tests passed
  • npx --yes skills@1.5.23 add . --list — discovered 13 skills, including cc-stats
  • bash -n scripts/install.sh — passed
  • git diff --check — passed

@datacas

datacas commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

Initial review — PR #46 Add cc-stats telemetry report

Verdict: CHANGES_REQUESTED. Reviewed HEAD: b87915f3354cb84466e76eed50e47fd9b259633a.

Summary and scope

I reviewed the whole diff from merge-base 0ffcb0d (current main) to HEAD. It has one commit and touches 8 files: scripts/stats.py (new), skills/cc-stats/SKILL.md (new), tests/test_stats.py (new), tests/test_install_runtime.py, scripts/runtime.manifest, scripts/validate-package.py, .github/workflows/validate.yml, and README.md. I checked the change against work item #42 and against the telemetry contract it reads: scripts/telemetry.py, and the row kinds written by scripts/cycle.py.

What works:

  • The read-only SQLite access, repository scoping, and sample gating are correct.
  • The skill and runtime are registered in every place CONTRIBUTING.md lists.
  • Privacy holds: no task or cycle IDs, no free text, and no local paths appear in the output.

One problem blocks approval. The headline counts (stages, per-role counts, and the daily activity trend) count every telemetry row. Since schema 3/4, a single stage writes several rows. The result is inflated numbers, which is exactly what the work item says a dashboard must not do.

Findings

[REV-001] · medium · open · blocks:yes — Stage, role, and activity counts include verdict, shadow, and cycle rows

Path: scripts/stats.py (lines 162, 175–222, 252). Category: correctness.

aggregate() treats every row in the window as a stage. CycleRecorder writes several kinds of row:

  • record_kind=dispatch for each dispatch attempt;
  • verdict for each review outcome;
  • shadow for each Jev suggestion on implement/resolve;
  • one cycle row (role coordinate) at close.

As a result, summary.stages, summary.roles, trend_daily (the "Stages" column in the Markdown), and the coordinate role all count rows that are not stages. Related symptom: fallback_stages sums used_fallback over every dispatch attempt row, so a stage that was rerouted counts once per attempt. The cycle row already carries the authoritative fallback_stages.

Evidence observed at runtime: one cycle with 2 real stages (implement → review, approved at first pass), written with the same record_kinds as cycle.py, produces:

stages: 5 roles: {'implement': 2, 'review': 2, 'coordinate': 1} daily: {'2026-09-23': 5}

Expected: stages: 2, roles: {'implement': 1, 'review': 1}. The existing tests in tests/test_stats.py do not catch this because their fixtures do not model verdict, shadow, and cycle rows alongside dispatch rows.

Suggested direction: count stages as dispatch rows (or as distinct (cycle_id, stage_seq) pairs, with a fallback for pre-schema-3 rows that have no record_kind). Take fallbacks from the cycle row when one exists. Add a fixture that writes the full set of row kinds for one cycle.

[REV-002] · low · open · blocks:no — With --all-time, comparison.previous_first_pass is the current period's rate

Path: scripts/stats.py (lines 292–294). Category: correctness.

When start is None, previous_first_pass falls back to _first_pass(rows), which is the whole history, i.e. the same data as current_first_pass. The Markdown hides it because available is false. But --format json is the documented structured output for the agent, and there it shows a "previous period" identical to the current one (observed: both {"passed": 1, "total": 1, ...}). It should be null or omitted when no previous period exists.

[REV-003] · low · open · blocks:no — CHANGELOG.md not updated

Path: CHANGELOG.md. Category: maintainability.

Every recent feature PR (#33, #34, #38, #40, #41, #43, #44, #45) adds an entry under [Unreleased]. This PR adds a new skill and a runtime component but does not add one.

Security triage

Sensitive change: it reads local telemetry and its output could expose data (observability, privacy). I audited:

  • Read-only access: mode=ro with a URI from Path.as_uri(). The code checks is_file() first, so no database is created; test_missing_database_is_not_created and the installed-runtime test cover this.
  • SQL: parameterised, filtered by repo_id.
  • Output: limited to the repository selector, dates, and closed-vocabulary tokens (roles, profiles, missing_capability, jev_status), all validated at write time. task_id and cycle_id are used only as grouping keys and are never emitted.
  • Errors: error messages do not echo local paths.

Result: no vulnerabilities or potential risks found.

Verification executed

Preflight: Python 3.10.12, PyYAML available, a detached worktree at the PR HEAD, and no services required.

Command Result
python3 scripts/validate-package.py VALID: 13 skills (6 cycle, 7 supporting)…
python3 -m unittest tests.test_stats -v 6/6 OK
python3 -m unittest discover -s tests 586/587. The one failure is test_run_cycle.LocalOnlyPolicyTests.test_local_only_rejects_the_live_repository. It fails the same way on main when run from a detached worktree outside the main checkout, and passes in the main checkout. It is an artefact of where I ran it, not a regression from this PR; CI runs it in the canonical checkout and passes.
Reproduction script with Telemetry.record_stage (dispatch + shadow + verdict + cycle) → stats.aggregate Confirms REV-001 and REV-002 at runtime

Not verified:

  • I did not run the skill end to end from an agent host. Locating stats.py in the project or global runtime was checked by reading the code and by the test_install_runtime test, not interactively.
  • I did not run the PowerShell installer locally; CI covers it.

CI

gh pr checks 46: 4/4 passed. That is two runs of the Validate package workflow (push + pull_request) on the same SHA, each with Skills, manifests, and Bash installer ✅ and PowerShell installer ✅. None are pending, skipped, or missing compared with the workflow definition.

Residual risks

  • Until REV-001 is fixed, any report shows inflated stage and role numbers. A user could reasonably read them as more activity or more fallbacks than really happened.
  • first_pass_by_suggested_profile requires the shadow row and the cycle row to fall in the same window. A cycle that straddles the window boundary drops out of the comparison. This is acceptable, but not documented.

Project verdict: CHANGES_REQUESTED. REV-001 blocks approval; REV-002 and REV-003 do not.

@datacas

datacas commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

Review resolution — PR #46

All three findings are resolved at 9d0426035192405e13e7e8f146470f10c9e89f9b.

[REV-001] · medium · resolved · blocks:yes — Stage, role, and activity counts include verdict, shadow, and cycle rows

scripts/stats.py now counts dispatch rows once per (cycle_id, stage_seq) and uses rows without record_kind for compatibility with older telemetry. Role, profile, and daily activity counts use one representative row per stage; profile and timestamp use the final dispatch attempt. Duration and cost continue to include each dispatch attempt. Fallback totals use the closing cycle row when available and otherwise count fallback stages once. The regression fixture includes rerouted dispatch attempts plus verdict, shadow, and cycle rows. python3 -m unittest tests.test_stats -v passed (7 tests), including assertions for two stages, implement/review roles, fallback total, profile, activity, duration, and cost.

[REV-002] · low · resolved · blocks:no — With --all-time, comparison.previous_first_pass is the current period's rate

For all-time reports, comparison.previous_first_pass is now null, since no preceding comparison period exists. The regression test asserts this value.

[REV-003] · low · resolved · blocks:no — CHANGELOG.md not updated

Added the cc-stats feature under CHANGELOG.md → [Unreleased] → Added, including the corrected row-count behavior and all-time comparison behavior.

Verification

  • python3 scripts/validate-package.py — passed (VALID: 13 skills (6 cycle, 7 supporting), shared sections in sync, cross-agent manifests aligned).
  • python3 -m unittest tests.test_stats -v — 7/7 passed.
  • python3 -m unittest discover -s tests -q — 588/588 passed.
  • rtk git diff --check — passed.
  • GitHub CI after push — 4/4 checks passed across the push and pull-request runs; no pending, failed, cancelled, skipped, or missing expected checks.
  • Delegated cc-code-review — no findings.
  • Security review of the changed telemetry aggregation and output path — no vulnerabilities or potential risks identified. The review covered repository-scoped read data, aggregate output, and identifier privacy; it was not a full-system audit.

Commit: 9d0426035192405e13e7e8f146470f10c9e89f9b.

@datacas

datacas commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

Rereview — PR #46 Add cc-stats telemetry report

Verdict: APPROVED. Reviewed HEAD: 9d0426035192405e13e7e8f146470f10c9e89f9b. Previous review: b87915f3354cb84466e76eed50e47fd9b259633a.

What changed since the previous review

One commit, 9d04260 fix: address cc-stats review findings, touching scripts/stats.py, tests/test_stats.py, and CHANGELOG.md:

  • New _stage_rows() collapses dispatch attempts into one stage per (cycle_id, stage_seq) and keeps rows without record_kind for older schemas.
  • New _fallback_stage_count() prefers the closing cycle row's fallback_stages.
  • Roles, profiles, and daily activity are counted from stages only; duration and cost from dispatch or legacy rows only.
  • previous_first_pass is null in all-time reports.

I reviewed the whole diff again from merge-base 0ffcb0d to HEAD, not just the new commit.

Previous findings

[REV-001] · medium · resolved · blocks:yes — Stage, role, and activity counts include verdict, shadow, and cycle rows

Fixed and verified by running it. The original reproduction (one implement → review cycle, written with dispatch + shadow + verdict + cycle rows) now gives stages: 2 roles: {'implement': 1, 'review': 1} daily: {'2026-09-23': 2}, where it gave 5 rows before. The new fixture in tests/test_stats.py also covers rerouted attempts and fallbacks and passes. One remaining case, for pre-schema-3 rows, is filed separately as REV-004.

[REV-002] · low · resolved · blocks:no — With --all-time, comparison.previous_first_pass is the current period's rate

Fixed and verified by running it: aggregate(..., days=None)["comparison"]["previous_first_pass"] is now null.

[REV-003] · low · resolved · blocks:no — CHANGELOG.md not updated

Fixed: there is an entry under [Unreleased] → Added that references #42.

New findings

[REV-004] · low · open · blocks:no — Rows from before schema 3 still count verdicts and the close as stages

Path: scripts/stats.py (line 120, _stage_rows). Category: correctness.

_stage_rows() treats every row without record_kind as a stage. Before #37 (schema 2), record_verdict() and close() already wrote separate rows (a review row with status and a coordinate row), and none of them carried record_kind. So historical data is still inflated the same way REV-001 described.

Observed at runtime: a schema-2 cycle (implement dispatch, review dispatch, review verdict, coordinate close) gives stages: 4 roles: {'review': 2, 'coordinate': 1, 'implement': 1}. The expected result is 2 stages.

This does not block approval. Everything recorded from schema 3 on is counted correctly, and the affected rows age out of the default 30-day window. They stay inflated in --all-time, though. Suggested fix: among legacy rows, count as stages only those that carry dispatch evidence (outcome, executor, or profile), and exclude the coordinate role.

Security triage

Sensitive change (it reads local telemetry, which is an observability and privacy concern), so I ran the audit again on the new commit. The fix changes only in-memory aggregation. It adds no queries, no output fields, and no new identifiers in the output: cycle_id and stage_seq are used only as grouping keys. No vulnerabilities or potential risks.

Verification executed

Preflight: Python 3.10.12, PyYAML available, a detached worktree at HEAD 9d04260, and no services required.

Command Result
python3 scripts/validate-package.py VALID: 13 skills (6 cycle, 7 supporting)…
python3 -m unittest tests.test_stats OK (7 tests)
python3 -m unittest discover -s tests 587/588. The one failure is test_run_cycle.LocalOnlyPolicyTests.test_local_only_rejects_the_live_repository. As in the previous review, it also fails on main when run from a detached worktree outside the main checkout, so it comes from where I ran it, not from this PR.
Original REV-001/REV-002 reproduction Fixed (see above)
Schema-2 reproduction Confirms REV-004

Not verified: I did not run the skill end to end from an agent host (same limitation as in the previous review).

CI

gh pr checks 46: 4/4 passed on HEAD 9d04260. That is two runs of the Validate package workflow (push + pull_request), each with Skills, manifests, and Bash installer ✅ and PowerShell installer ✅. None are pending, skipped, or missing.

Residual risks

  • REV-004: historical telemetry recorded before schema 3 still shows inflated stage and role counts in long windows and in --all-time.
  • first_pass_by_suggested_profile requires the shadow and cycle rows to fall in the same window (not documented; acceptable).

Project verdict: APPROVED. No open finding blocks approval. REV-004 is open with blocks:no.

@datacas
datacas merged commit ce3bb23 into main Sep 23, 2026
4 checks passed
@datacas
datacas deleted the issue-42-cc-stats branch September 24, 2026 09:21
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.

1 participant