Repository navigation
perf: load the HTTP stack only when a role command runs - #53
Conversation
instructor/student --help imported lighthouse_cli.api (requests, config) through assessment_commands. Import the API and assessment helpers inside the functions that use them instead; role help now loads like root help. Replaces the lazy-export layer in #29.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing |
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — verified the lazy-import mechanism end-to-end: read all changed files plus the _AssessmentGroup wiring in cli.py, grepped for stale references to the moved symbols, ran ruff + lint-imports + 188 tests locally, mutation-tested the new test (restoring the top-level api import makes both cases fail), and confirmed CI green on the head SHA.
- Deferred the HTTP-stack imports in
assessment_commands.pyto call time —_run, the_createdry-run branch,quiz-create, andassignment-createnow importLighthouseClient/assessment_apihelpers inside the function, so resolving role groups no longer pullsrequests; every lazy import is used at its site. - Moved the annotation-only
AssessmentAPIimport underTYPE_CHECKINGin bothassessment_commands.pyandcourse_read_commands.py, guarded byfrom __future__ import annotations(same pattern asms_auth.py). - Retargeted 8 mock patches to
lighthouse_cli.api.LighthouseClient— correct, since_runnow resolves the attribute fromlighthouse_cli.apiat call time — and added a subprocess test asserting role--helpimports neitherrequestsnorlighthouse_cli.api.
glm-5.3 | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — re-reviewed the delta since the prior pullfrog review (9bfb331): one test-only commit, re-ran the tightened test at head, and re-checked the full diff for drift.
- Tightened the role-help subprocess test to require a zero exit code —
except SystemExit: passbecameexcept SystemExit as exc: assert exc.code == 0, so the test now catches a regression where role--helprenders via an error path (e.g. Click'sSystemExit(2)) even if no HTTP imports leaked; both parametrized cases pass at8cdf3e3.
glm-5.3 | 𝕏
|
|
||
| def _run(course_id: int, json_output: bool, action: Callable[[AssessmentAPI], Any]) -> None: | ||
| # Imported here, not at module level, so role --help skips the HTTP stack. | ||
| from .api import LighthouseClient |
There was a problem hiding this comment.
SUGGESTION: These function-level imports run before the try block, so an ImportError (broken install/missing dependency) escapes _run's format_user_error handling and surfaces as a raw Click traceback instead of the repo's safe JSON/human error path. Before this change the same failure crashed at module import, so this is not a regression, but the failure is now deferred later in the flow — in _create's non-dry-run path the user answers the click.confirm prompt first and only then hits the crash. If you want the error contract to hold even in broken-environment scenarios, consider placing these imports inside the guarded region or catching ImportError explicitly at this boundary.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
|
|
||
| def _create(course_id: int, resource: str, payload: dict[str, Any], yes: bool, dry_run: bool, json_output: bool) -> None: | ||
| if dry_run: | ||
| from .assessment_api import project |
There was a problem hiding this comment.
SUGGESTION: Worth being aware that this dry-run path still transitively loads the full HTTP stack: assessment_api imports requests and .api at its own module level, so from .assessment_api import project here pulls both in at command execution time. The lazy-import win is therefore limited to --help/role-group resolution (which the new subprocess test correctly guards), not to dry-run execution. That is fine for the stated perf goal, but a future reader may assume --dry-run is HTTP-stack-free; a brief note here (or moving project to a dependency-free module later) would prevent that misconception.
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
Code Review SummaryStatus: 2 Issues Found | Recommendation: Merge (non-blocking suggestions only) Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (3 files)
Fix these issues in Kilo Cloud Reviewed by glm-5.3-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |

What changed
lighthouse instructor --helpandlighthouse student --helpimported the whole HTTP stack (lighthouse_cli.api,requests, config), becauseassessment_commands.pyimportedapiandassessment_apiat the top of the file. Those imports now happen inside the functions that use them (_run,_create,quiz-create,assignment-create).course_read_commands.pyonly neededAssessmentAPIfor type hints, so it now imports it underTYPE_CHECKING.This replaces #29. That PR took the same idea further, with a 316-line lazy-export layer (
__getattr__/globals()) over the legacycommandsmodule, but that module already loads lazily fromcli.py, so the role groups were the only slow path left.Measured
Median wall time of a fresh process, 20 runs after 3 warm-ups. The machine was under load, so the numbers are noisy but consistent across rounds.
lighthouse --helplighthouse instructor --helplighthouse student --helpTests
test_role_help_does_not_load_http[instructor|student]runs role help in a subprocess and asserts that neitherrequestsnorlighthouse_cli.apiwas imported. Putting the top-levelapiimport back makes both cases fail.lighthouse_cli.assessment_commands.LighthouseClientnow patchlighthouse_cli.api.LighthouseClient, which the function-level import reads at call time.Closes #27