Skip to content

fix: restore logger levels after silencing machine output - #2011

Merged
RaghavChamadiya merged 7 commits into
repowise-dev:mainfrom
Aman-goel-04:fix/silence-logs-machine-output-1976
Oct 3, 2026
Merged

RaghavChamadiya merged 7 commits into
repowise-dev:mainfrom
Aman-goel-04:fix/silence-logs-machine-output-1976

Conversation

@Aman-goel-04

@Aman-goel-04 Aman-goel-04 commented Aug 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Prevents machine-output log silencing from leaking process-global stdlib logger levels across CLI commands and tests.
  • Restores the complete prior structlog configuration after machine-output commands finish, including Click option-callback paths.
  • Adds regression coverage for scoped log silencing and restores the adapter markdown-output test.

Related Issues

Fixes #1976

Test Plan

  • Lint passes (ruff check .) — CI passed
  • Tests pass (pytest) — CI passed on Python 3.11, 3.12, and 3.13
  • Web build passes (npm run build) (no frontend changes)

Checklist

  • My code follows the project's code style
  • I have added tests for new functionality
  • All existing tests still pass
  • I have updated documentation if needed

@Aman-goel-04

Copy link
Copy Markdown
Collaborator Author

@RaghavChamadiya, please review this PR and let me know if any changes need to be made!

@Aman-goel-04
Aman-goel-04 force-pushed the fix/silence-logs-machine-output-1976 branch from 500dd13 to 8653f1e Compare September 8, 2026 09:38
@Aman-goel-04 Aman-goel-04 changed the title wip: silence_logs_for_machine_output fix fix: restore logger levels after silencing machine output Sep 8, 2026
@Aman-goel-04

Copy link
Copy Markdown
Collaborator Author

Hey @RaghavChamadiya, rebased this onto current main to clear the conflict (there was a real merge collision in health_cmd/command.py against the new --scope production/all feature, resolved so both land together), and fixed a test that referenced the pre-rename helper name. CI's green and it's mergeable now, ready whenever you get a chance to take another look!

@RaghavChamadiya

Copy link
Copy Markdown
Member

Thanks @Aman-goel-04, and sorry this sat for three days after you cleared the last conflict. I have read it properly now and it is right.

The part I want to name, because it is the part that would have been easy to skip: silence_logs_for_machine_output_until_close. An option callback returns before the command body runs, so a with block there restores the levels before any work happens, and re-indenting a long command body under one with is the kind of diff that hides a real change. Registering the undo on ctx.call_on_close and following the precedent update_cmd already set for console.file is the right answer to that, and the docstring saying so means the next person does not re-litigate it.

The autouse _isolate_silenced_logger_levels fixture is the other half and the reason #1976 actually closes rather than narrows. The explanation of why an empty caplog results, that the module's own logger has no level so its effective level comes from the ancestor pinned at ERROR and the record is dropped before any handler runs, is the thing nobody debugging this from the symptom would work out quickly. Putting the same fact in CONTRIBUTING.md discharges something we have owed since #1976 was filed.

Verified rather than assumed: all eleven call sites are migrated, so there is no bare call left silently doing nothing, and tests/unit/test_structlog_isolation.py, test_tool_adapter_commands.py and test_update_full_dry_run.py are 67 passed locally.

It has gone conflicting again, and it is ours, not yours. #2180 landed on 9 September, the day after your rebase, and it rewrote the same region of health_cmd/command.py that your with silencer: block wraps. I test-merged your head against current main: packages/cli/src/repowise/cli/commands/health_cmd/command.py is the only conflicting file.

git fetch origin && git rebase origin/main and take both sides in that one function. I will merge on green with no further review — this is reviewed and tested as it stands, and the rebase is only there because we kept moving underneath you.

@Aman-goel-04

Copy link
Copy Markdown
Collaborator Author

@RaghavChamadiya, that's fine, I don't mind resolving the conflicts again if you want me to.

@Aman-goel-04
Aman-goel-04 force-pushed the fix/silence-logs-machine-output-1976 branch from 30f2f58 to dad8793 Compare September 18, 2026 09:19
@repowise-bot

repowise-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🔍 1 thing to check

  1. 4 files that usually change with this PR's files are not in it: packages/cli/src/repowise/cli/commands/update_cmd/persistence.py, packages/core/src/repowise/core/workspace/update.py, packages/cli/src/repowise/cli/commands/init_cmd/command.py (+1 more)

✅ Health of changed files: 4.6 (unchanged)

👀 Suggested reviewers @RaghavChamadiya


📊 See the full report for this PR
Blast radius, every caller of the contracts it changes, and health before and after. No sign-in.
Plain markdown for agents

Settings and updates

Updated 2026-10-03 12:10 UTC, since the last push: health 4.4 to 4.6
Silence one PR with [skip repowise] in the title · Bot settings
⭐ Star Repowise · 📥 Install on another repo

@repowise-bot

repowise-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Repowise checks

Check Result
Coverage Waiting for this PR's CI to upload a report (last report from this repo 4 minutes ago)
Tests 9 of 10 changed files reached by a test (inferred) · 1 reached by no test
Security No new findings on changed lines
Doc drift No drift in docs this PR edits
Tests: which tests reach the changed files (inferred)
  • packages/cli/src/repowise/cli/commands/doctor_cmd/command.py: No test reaches this file (inferred)
  • packages/cli/src/repowise/cli/commands/_tool_adapters.py: tests/unit/cli/test_risk_cmd_contract.py, tests/unit/cli/test_output_agent_readiness.py and 2 more (call graph)
  • packages/cli/src/repowise/cli/commands/dead_code_cmd.py: tests/unit/cli/test_analysis_cmds_include_submodules.py, tests/unit/cli/test_dead_code_stored.py and 1 more (import graph)
  • packages/cli/src/repowise/cli/commands/doc_drift_cmd.py: tests/unit/cli/test_doc_drift_cmd.py (call graph)
  • packages/cli/src/repowise/cli/commands/health_cmd/command.py: tests/unit/cli/test_health_cmd_exclusions.py, tests/unit/cli/test_health_cmd_logging.py and 2 more (import graph)
  • packages/cli/src/repowise/cli/commands/impacted_tests_cmd.py: tests/unit/persistence/test_impacted_tests_resolution.py (call graph)
  • packages/cli/src/repowise/cli/commands/security_cmd.py: tests/unit/cli/test_security_cmd.py, tests/unit/cli/test_security_check_cmd.py and 1 more (import graph)
  • packages/cli/src/repowise/cli/commands/update_cmd/command.py: tests/unit/cli/test_coverage_cmd.py, tests/unit/cli/test_update_full_dry_run.py and 5 more (call graph)
  • packages/cli/src/repowise/cli/helpers.py: tests/unit/cli/test_helpers.py, tests/unit/cli/test_command_target.py and 90 more (call graph)
  • packages/cli/src/repowise/cli/output.py: tests/unit/cli/test_output_agent_readiness.py, tests/unit/cli/test_format_json_rollout.py and 2 more (call graph)

Inferred from the code graph of the last indexed commit (6100a2c), nearest tests first; a test reaching a file does not mean it covers the changed lines.

Configure checks: bot settings

@Aman-goel-04

Copy link
Copy Markdown
Collaborator Author

@RaghavChamadiya, I've resolved the conflicts. Please review it when you get the time!!

@RaghavChamadiya RaghavChamadiya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Aman-goel-04 for the fast rebase. Making the helper a context manager is the right shape: the levels it touches are process-global, so a bare call had no owner to put them back, and call_on_close covers the option-callback sites that cannot wrap a with block. I checked it on top of current main: no bare call is left behind, and the touched CLI, doctor and structlog-isolation tests pass (152). Merging.

@RaghavChamadiya
RaghavChamadiya merged commit e38d243 into repowise-dev:main Oct 3, 2026
10 checks passed
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.

silence_logs_for_machine_output mutates global logger levels with no restore, so caplog assertions fail only in a full test run

2 participants