Skip to content

refactor(subagent): drop the uncalled _read_samples cost-log reader - #16843

Merged
iamwhatever merged 1 commit into
mainfrom
refactor/simplify-toplevel
Oct 5, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
refactor/simplify-toplevel

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Remove a cost-log reader in subagent_cost.py that nothing calls, so the module shows only the readers that actually run.

src/kiro_crew/subagent_cost.py defines _read_samples(), which loads every record of the sub-agent cost log into one list. Nothing calls it. Every production reader streams the log through _iter_samples() into bounded per-bucket windows, and the one materialising reader a test uses is _read_samples_checked().

Why it matters

The cost log is agent-writable, and this module is careful never to hold it whole in production. A second whole-log reader that runs nowhere invites the next caller to pick it up, and makes a reviewer auditing the bounded reads check a function that does not matter.

Not a goal

  • Changing how the cost log is written, read, bounded or compacted.
  • Touching any other file (one module per PR; this is the toplevel sweep).
  • Rewording the untouched module docstring. Its §4.2 / §4.3 pointers name sections dynamic-subagent-sizing.md no longer numbers, and the same pointers sit in subagent.py and subagent_manager/monitoring.py, so they belong in one docs-pointer pass across all three files.

What changed (motivation → approach → change)

Part of the module-simplification campaign. The detector's two mechanical classes (shadow imports, chained ternaries) are at 0 tree-wide, so this is a judgment-class pass: an AST scan for module-level private names nothing references.

subagent_cost._read_samples was the one hit with no open PR touching its file. Its last caller was replaced when the readers switched to streaming, and a word-boundary grep across src/, test/, scripts/, docs/, .github/ and website/ finds only the definition. The diff deletes the function. Its docstring carried the rule "materialising is for tests and small utilities only; production readers stream through _iter_samples", which applies just as much to _read_samples_checked, so that rule moves onto _read_samples_checked's docstring instead of being lost. No import changes.

Before opening, seven read-only review subagents checked the diff from separate angles: AUTOSDE blocking rules, behaviour preservation, import semantics, security keystone and boot path, comment accuracy, and local mirrors of the Codex and Claude review contracts. The behaviour lens compared both versions' syntax trees with docstrings stripped: the removed function is the only difference. None of the seven found a code defect. The one finding, the Codex mirror saying the intent did not match the diff, came from the brief tool reading merged #16100's body off the reused branch name; an independent verifier refuted it. The comment lens also noted, out of scope, that the untouched module docstring says the log is trimmed "per agent" where compaction keeps one window per (agent, shared) pair.

Backwards compatibility

Compatible: the removed function is private and has no caller, string reference or patch target anywhere in the repo.

Removes nothing: the deleted reader was never invoked on any path, so no reader of it exists; take_away_check.py reports no take-away shape for a private def.

Tests

No test change: no test referenced the function. test_subagent_cost.py, test_adaptive_startup_memory.py, test_subagent_sizing.py, test_admission_gate.py, test_spawn_memory_cause.py, test_spawn_floor_defaults.py, test_queue_depth_after_deferred_start.py and test_subagent_queued_visibility.py pass (369 passed) on the Python 3.12 CI-parity venv. That is a superset of run_scoped_tests.py's related set for this diff.

Gates run locally, all exit 0: the backend gates[] floor from the prepare-pr profile, including flake8, isort --check-only, mypy src/kiro_crew, check_black_formatting.py, check_subprocess_encoding.py, check_comment_history.py, check_brand_name.py, check_harness_parity.py, docs_lint.py --test, docs-lint.sh, check_per_file_coverage.py --test and verify_vendor_manifest.py. Backend-only diff, so CI reports only_backend=true and the frontend suites are not affected.

Manual verification

N/A — unit coverage sufficient: the change deletes uncalled code, and every live reader of the cost log is exercised by test_subagent_cost.py and test_adaptive_startup_memory.py.

Screenshots / video

Why no screenshot: backend-only deletion of an uncalled Python helper; nothing renders differently.

Related Issues

Part of #16523

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

@bolichen97
bolichen97 requested a review from a team as a code owner October 4, 2026 22:56
@bolichen97
bolichen97 requested a review from iamwhatever October 4, 2026 22:56
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of c6f0d8667b23c765eea42fe955eebf85bca410fd — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Nothing to check.

What this change ships

Inventory (2 items) — 2 justified

Intent: delete a private whole-log cost reader that nothing calls, so only the readers that actually run remain. This is a FIX (subtraction).

  1. The uncalled _read_samples() whole-log reader is gone (grep _read_samples\b across the repo: 0 references remain) — justified
  2. The "for tests and small utilities only" docstring rule now sits on _read_samples_checked (1 consumer: test/test_subagent_cost.py:229) — justified

[FIRST-PRINCIPLES-REVIEWED] c6f0d86

Description read

[DESCRIPTION-READ] e461e91db1a6eb267bc20c74ea90d1b98205a146ce510245cd88f1020e9d66e8

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 Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of c6f0d8667b23c765eea42fe955eebf85bca410fd — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] c6f0d86

Description read

[DESCRIPTION-READ] a051bd8e85e2b788fb1402e34e805e474048cb4ae97b0633438a24c1b19c4bc6

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 Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] c6f0d86

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable c6f0d8667b23c765eea42fe955eebf85bca410fd: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] c6f0d86

False positive or not applicable? A repository writer can comment:
/ai-review override gpt c6f0d8667b23c765eea42fe955eebf85bca410fd: <one-sentence reason>

@bolichen97
bolichen97 force-pushed the refactor/simplify-toplevel branch from d9355d3 to 24bbf6a Compare October 4, 2026 23:33
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in files green_age.py links to subagent_cost.py only by import / same-directory overlap (agent_materialization/managed_mcp.py, dashboard/agent_admin/*, dashboard/chat_runner.py, eventlog_hooks.py, memory_startup.py, +19 more) since this head went green (69ee108 -> d167e19); CI re-running.

Neither base commit (#16279, #16786) references subagent_cost or _read_samples. On the rebased head 24bbf6ab7d the backend gate floor and the eight subagent_cost reader test files (369 passed) are green locally.

@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 Oct 5, 2026
subagent_cost._read_samples() materialised the whole cost log and had
no caller: its last one was replaced when the readers switched to
streaming through _iter_samples. The surviving materialising reader,
_read_samples_checked, which a test uses, now carries the note that
materialising is for tests and small utilities only.
@bolichen97
bolichen97 force-pushed the refactor/simplify-toplevel branch from 24bbf6a to c6f0d86 Compare October 5, 2026 00:15
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in files green_age.py links to subagent_cost.py only by import overlap (dashboard/chat_handlers.py, test/test_chat_agent_selection.py, test/test_member_memory_runtime.py) since this head went green (d167e19 -> 033dd90); CI re-running.

The base commit (#16846) adds no reference to _read_samples; on origin/main the only hit is still its definition. On the rebased head c6f0d8667b the backend gate floor and the eight subagent_cost reader test files (369 passed) are green locally.

@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: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Oct 5, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) October 5, 2026 01:02

@iamwhatever iamwhatever 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.

Tier 1 auto-approve: refactor (1 file). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean, security checklist all-NO, AI reviewers green. Category: removes the uncalled _read_samples() cost-log reader from subagent_cost.py and folds its docstring note into _read_samples_checked(); dead-code removal with no behaviour change. (Semgrep's single annotation is GitHub's ubuntu-latest migration notice, not a finding.)

@iamwhatever
iamwhatever merged commit 7830470 into main Oct 5, 2026
98 checks passed
@iamwhatever
iamwhatever deleted the refactor/simplify-toplevel branch October 5, 2026 01:02
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 5, 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.

2 participants