Skip to content

refactor(remote_session): drop a redundant shutil import in _stats - #25465

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/simplify-remote_session
Oct 29, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/simplify-remote_session

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Remove the one redundant import the sweep's detector finds in src/kiro_crew/remote_session/, without changing what any remote workspace tool does.

_stats() in remote_session/workspace_tools.py (the guest tool server's machine metrics for the dashboard's environment card) ran import shutil inside the function, although the same file imports shutil at module scope on line 19. The inner statement bound a function-local name to the module object the module global already holds, so it read as a dependency the function needed on its own when it did not.

Why it matters

Nothing is broken today. The extra line makes a reader of a guest file that must stay stdlib-only and Python 3.9 compatible check whether _stats needs its own import, and the advisory top-level-imports rule asks for imports at the top of the file.

Not a goal

  • The lazy import platform beside it stays: nothing binds platform at module scope, and the sweep never hoists a lazy import.
  • relay.py's in-function from kiro_crew.remote_session import wire: an in-function from X import Y resolves at call time, so the sweep never deletes one.
  • Any other file under src/, and any guard, path check, withheld-variable set or git argument list in workspace_tools.py.

What changed (motivation → approach → change)

One line goes: the in-function import shutil in _stats(). _stats now reads the module-scope shutil, the same sys.modules entry, so shutil.disk_usage(ws.root) returns the same result. No test replaces shutil on this module, and nothing rebinds the name at runtime.

Backwards compatibility

Compatible: the guest tool server answers every browse, write and tool call exactly as before.

Removes nothing: the deleted statement bound a local name to an object the module global already holds; no name, field, op or behaviour is taken away.

Tests

  • No test change. The existing stats tests (test_stats_reports_numbers_only, test_container_stats_report_the_cgroup_ceiling_not_the_host_node) call _stats through browse, the path that reaches shutil.disk_usage.
  • Related tests (Python 3.12). The seven test files that import or launch workspace_tools.py: 373 passed, 1 skipped.
  • Static gates (Python 3.12). All 33 checks exit 0, among them flake8, isort, mypy, pinned black, comment-history, brand, harness-parity, the line cap, the docs lint, the flake-pattern ratchet and the vendor manifest.
  • Pre-PR review. Five read-only reviewers (repo rules, behaviour, imports, security and boot path, claims) and one adjudicator, then the Opus and GPT lane contracts (the GPT one on a Claude model). No code finding: under Python 3.9, 3.12 and 3.14 the function's local IMPORT_NAME/STORE_FAST becomes one LOAD_GLOBAL with the same result. Of three wording findings on the commit message, the adjudicator upheld one ("shadowed" named the wrong side; the subject says "redundant") and refuted two.
  • Not run locally. scripts/scrub-lint.sh is absent here. Semgrep is not installed; CI's SAST (Semgrep) job runs it. No frontend run: nothing under website/, .github/ or scripts/ changed.

Manual verification

N/A: unit coverage suffices. The stats op ran standalone under Python 3.9 and 3.12 and returned its disk entry, which proves shutil resolves.

Screenshots / video

Why no screenshot: backend-only deletion of one redundant import; the environment card receives the same numbers.

Related Issues

Part of #16523

Overlap: five open PRs touch workspace_tools.py. A git merge-tree of each against main with and without this commit shows one new conflict hunk, on #21258, which already conflicts with main and whose diff adds its own copy of _stats; the new hunk is this one import line, and either resolution behaves the same.

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

The guest tool server's _stats re-ran `import shutil` inside the
function although workspace_tools.py already imports shutil at module
scope. The inner statement re-bound the same sys.modules singleton, so
removing it changes nothing at runtime; the lazy `import platform`
beside it stays, since nothing binds platform at module scope.
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 28, 2026 22:45
@bolichen97
bolichen97 requested a review from CrysisDeu October 28, 2026 22:45
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 12fc70c0b2f4ab5bf31ee8fd06e91afb144cfed2 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 12fc70c0b2f4ab5bf31ee8fd06e91afb144cfed2 — 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 to check.

What this change ships

Inventory (1 items) — 1 justified

Intent: delete one redundant import so the code is easier to read, with no change in behaviour. This is an ADDITION (a pure deletion), not a FIX.

  1. _stats() no longer re-imports shutil locally and uses the module-scope import at line 19 — justified

[FIRST-PRINCIPLES-REVIEWED] 12fc70c

Description read

[DESCRIPTION-READ] c94a2ff05ce9253f746709b8794e430c3a281906d451f35e6b9f26d3b4270293

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

No design-level concerns. The function-local import shutil repeated the module-scope import on line 19, so removing it changes nothing at runtime.

[DESIGN-REVIEWED] 12fc70c

Description read

[DESCRIPTION-READ] a89fc958ef04313ffb3e0d82484790eaad2fb79506afebb5e2d0dcad18b52dda

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 12fc70c

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

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

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 12fc70c

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

@bolichen97
bolichen97 enabled auto-merge (squash) October 28, 2026 23:09
@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 28, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

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 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: removes a function-local import shutil in _stats; the module already imports shutil at line 19 and the function's shutil.disk_usage call resolves to it, so behaviour is unchanged.

@bolichen97
bolichen97 merged commit 70cd756 into main Oct 29, 2026
108 of 109 checks passed
@bolichen97
bolichen97 deleted the refactor/simplify-remote_session branch October 29, 2026 00:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 29, 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