Skip to content

[AI Generated] BugFix: don't assert in unsubscribe_log when handler is missing#4462

Merged
LiliDeng merged 1 commit into
mainfrom
bugfix/unsubscribe-log-handler-missing_260503_191007
May 9, 2026
Merged

[AI Generated] BugFix: don't assert in unsubscribe_log when handler is missing#4462
LiliDeng merged 1 commit into
mainfrom
bugfix/unsubscribe-log-handler-missing_260503_191007

Conversation

@LiliDeng
Copy link
Copy Markdown
Collaborator

@LiliDeng LiliDeng commented May 3, 2026

Problem

When deploying an environment, lisa_runner._deploy_environment_task does:

try:
    test_result.subscribe_log(environment.log)
    ...
finally:
    test_result.unsubscribe_log(environment.log)

subscribe_log lazily creates the per-case log file handler the first time it runs. If that creation fails (e.g. the case log directory can't be created, the path is too long on Windows, the disk is full, or relative_to(RUN_LOCAL_LOG_PATH) raises), self._log_file_handler stays None. The finally block still calls unsubscribe_log, which then trips:

File ".../lisa/testsuite.py", line 285, in unsubscribe_log
    assert self._log_file_handler, "Log file handler is not set"
AssertionError: Log file handler is not set

That AssertionError masks the original deployment / log-setup error, making the real failure invisible in CI.

Change

In lisa/testsuite.py, replace the assert in unsubscribe_log with a defensive early return when the handler was never attached. There's nothing to detach in that case, and the original exception then propagates normally.

No other behavior changes.

…s missing

If subscribe_log raises before create_file_handler runs (e.g. when the per-case log path can't be created), _log_file_handler stays None. The surrounding finally block in lisa_runner._deploy_environment_task still calls unsubscribe_log, which then trips `assert self._log_file_handler` and surfaces `AssertionError: Log file handler is not set`, masking the real underlying error.

Skip detaching when no handler exists so the original exception propagates.
Copilot AI review requested due to automatic review settings May 3, 2026 11:11
@LiliDeng LiliDeng requested a review from johnsongeorge-w as a code owner May 3, 2026 11:11
@LiliDeng LiliDeng added AI_GEN_PR 🐞 Bug Something isn't working labels May 3, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens LISA's test-result logging cleanup so a failure while creating the per-case log handler does not get replaced by a secondary AssertionError during environment-deployment cleanup. It fits into the core runner/testsuite path that manages per-case log attachment while provisioning environments and running cases.

Changes:

  • Replace the assert in TestResult.unsubscribe_log with a defensive early return when no file handler was created.
  • Add inline context explaining the expected failure mode when subscribe_log fails before create_file_handler.
  • Preserve the original deployment or log-setup exception instead of masking it during finally cleanup.

Comment thread lisa/testsuite.py
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

✅ AI Test Selection — PASSED

1 test case(s) selected (view run)

Marketplace image: canonical 0001-com-ubuntu-server-jammy 22_04-lts-gen2 latest

Count
✅ Passed 1
❌ Failed 0
⏭️ Skipped 0
Total 1
Test case details
Test Case Status Time (s) Message
smoke_test (lisa_0_0) ✅ PASSED 35.964

@LiliDeng LiliDeng merged commit 0ff4fe1 into main May 9, 2026
65 checks passed
@LiliDeng LiliDeng deleted the bugfix/unsubscribe-log-handler-missing_260503_191007 branch May 9, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI_GEN_PR 🐞 Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants