Skip to content

fix: stop CLI logic capture after interrupted waits - #316

Open
YashAnand69 wants to merge 1 commit into
fossasia:mainfrom
YashAnand69:fix/cli-logic-capture-cleanup
Open

YashAnand69 wants to merge 1 commit into
fossasia:mainfrom
YashAnand69:fix/cli-logic-capture-cleanup

Conversation

@YashAnand69

@YashAnand69 YashAnand69 commented Oct 11, 2026 •

Copy link
Copy Markdown

Interrupting pslab collect logic_analyzer during its acquisition wait skips STOP_LA, leaving capture running after the command exits.

Put the wait in try/finally so the existing stop command is attempted on interruption as well as success. Failed capture initiation still propagates without an additional stop, and successful channel names, timestamps and stop-before-fetch order are unchanged.

Validation: twelve interruption regressions fail on unchanged main; six success/error controls pass. The fixed branch passes all 18 new tests plus 33 existing CLI, Pico SCPI and MQ135 cases (51 total), independently rerun after full diff review. Tests use the real LogicAnalyzer capture/stop methods with a controlled transport and check STOP_LA plus acknowledgment. Configured Black, Flake8, Bandit and pydocstyle, wheel/sdist and Sphinx builds pass; seven existing docs warnings remain. Scoped CLI coverage does not decrease (73.656% to 73.797%). Combining this patch with the updated #315 passes 61 tests.

No physical PSLab or full device integration suite was run. A failed stop command still propagates its transport error with the original interruption as context; cleanup requires a working connection. This differs from #314's ultrasonic trigger-output cleanup and #267's CLI transport migration. Current issue comments and open patches were checked for overlap. Developed and tested with Codex assistance.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fadb3ce3-8f9c-44a7-8342-cbfb864b1823


📥 Commits

Reviewing files that changed from the base of the PR and between 08de0d0 and 834d27c.



📒 Files selected for processing (2)
  • pslab/cli.py
  • tests/test_cli_logic_cleanup.py


Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.




📝 Walkthrough
📝 Walkthrough

Walkthrough

The CLI logic-analyzer capture now stops in a finally block, including when the wait raises. Hardware-independent tests cover cleanup ordering, capture errors, returned data, and cleanup-stop errors.

Changes

Logic analyzer cleanup

Layer / File(s) Summary
Capture cleanup and validation
pslab/cli.py, tests/test_cli_logic_cleanup.py
logic_analyzer stops the analyzer in a finally block. Tests check stop and acknowledgment ordering, exception propagation, and returned channel data. They also cover capture-initiation errors and cleanup-stop errors.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix



Merge Risk: ⚪ Minimal · up to 834d2

Interrupting a logic analyzer capture from the CLI now attempts to stop the analyzer instead of leaving it running. Successful captures behave as before. No actionable merge risk remains.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 834d2

The change improves interrupted-capture cleanup without expanding device access or changing successful results. No material security risk was identified in the compared behavior. Cleanup remains dependent on a working connection.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed cleanup acts on the same connected analyzer already selected for capture. Its effective scope remains that device's acquisition state; it does not select additional devices or obtain additional authority.

Trust Boundaries and Controls

  • inferred — CLI-controlled instrument, channel, duration, and port inputs follow the existing dispatch and connection path. The changed block adds cleanup on wait failure without introducing another caller, transport, credential, or identity transition.

Resilience and Maintainability Implications

  • inferred — Cleanup is an attempted transport operation, not a guarantee that hardware has stopped. A failed stop or acknowledgment can leave device state uncertain. Capture initiation can likewise fail after a start command without reaching CLI cleanup; that initiation limitation predates this change.
  • inferred — Stop is device-global and carries no capture-owner token. Exceptional cleanup can therefore affect an overlapping capture on the same device. However, capture already stops prior acquisition and successful CLI execution already stops through that same connection, so this is not newly granted cross-owner authority. Safe concurrent operation was not established by the inspected evidence.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: stopping CLI logic capture after an interrupted wait.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR



  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Sorry @YashAnand69, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 23 hours and 52 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

The CLI now reliably sends STOP_LA when a started logic-analyzer capture is interrupted or the acquisition wait raises, while preserving normal results and failure semantics. New transport-controlled tests cover interruption cleanup, success ordering, initiation failures, and cleanup-error context.

Sequence diagram for interrupted logic analyzer capture cleanup

sequenceDiagram
    participant CLI
    participant LogicAnalyzer
    participant Transport

    CLI->>LogicAnalyzer: capture(channels, block=False)
    LogicAnalyzer->>Transport: START_LA
    Transport-->>LogicAnalyzer: acknowledgment
    CLI->>CLI: time.sleep(duration)
    alt wait completes
        CLI->>LogicAnalyzer: stop()
    else wait interrupted or raises
        CLI->>LogicAnalyzer: stop()
    end
    LogicAnalyzer->>Transport: STOP_LA
    Transport-->>LogicAnalyzer: acknowledgment
    CLI->>LogicAnalyzer: fetch_data()
Loading

File-Level Changes

Change Details Files
Ensure logic-analyzer acquisition is stopped whenever the wait exits, including interruptions and other wait errors.
  • Wrap the acquisition delay in a finally block that invokes the existing stop operation.
  • Preserve capture-initiation error behavior by only entering cleanup after capture starts.
  • Keep stop-before-fetch ordering and existing channel/timestamp results unchanged.
pslab/cli.py
Add hardware-independent regression and control coverage for cleanup, ordering, and error propagation.
  • Exercise KeyboardInterrupt and wait-error cleanup across all channel counts.
  • Verify successful results, STOP_LA acknowledgment, and no fetch after interrupted waits.
  • Verify capture-initiation failures do not add a stop and stop failures retain the wait error as context.
tests/test_cli_logic_cleanup.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

This branch has not been deployed

No deployments
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.

1 participant