Skip to content

Add runtime version detection to prevent version mismatch errors#477

Merged
thiagoralves merged 4 commits into
developmentfrom
devin/1766011653-runtime-version-detection
Dec 18, 2025
Merged

Add runtime version detection to prevent version mismatch errors#477
thiagoralves merged 4 commits into
developmentfrom
devin/1766011653-runtime-version-detection

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

Pull request info

References

This PR is part of a coordinated change across three repositories to implement runtime version detection:

Link to Devin run

Devin session

Requested by: Thiago Alves (@thiagoralves)

Description of the changes proposed

  • Capture X-OpenPLC-Runtime-Version HTTP header from runtime API responses in handleRuntimeGetUsersInfo
  • Add runtimeVersion field to the IPC bridge return type for runtimeGetUsersInfo
  • Add utility functions getExpectedRuntimeVersion and validateRuntimeVersion in src/utils/device.ts
  • Validate runtime version during connection flow with different behaviors:
    • Version mismatch: Show error modal (hard block) when selected board target doesn't match connected runtime version
    • Older runtime (no version header): Show warning modal with "Continue Anyway" and "Cancel" buttons, allowing users to proceed if they choose

This prevents users from accidentally connecting to the wrong runtime version (e.g., selecting "OpenPLC Runtime v4" but connecting to a v3 runtime), while still allowing connections to older runtimes that don't report version.

Updates since last revision

Fixed race condition in debugger-message-modal:

  • When onResponse callback opens another modal (e.g., login dialog), the subsequent closeModal() was closing ALL modals including the newly opened one
  • Fix: capture callback before closing, close modal first, then call callback
  • This fixes "Continue Anyway" not showing the login/create-user dialog

Previous updates:

  • Changed older runtime detection from error to warning dialog with "Continue Anyway" and "Cancel" buttons
  • validateRuntimeVersion now returns status: 'ok' | 'missing' | 'mismatch' instead of just isValid: boolean
  • Use normalizedDetected.toUpperCase() instead of detectedVersion.toUpperCase() for safer code
  • Remove redundant .toLowerCase() call on expectedVersion

Important review notes

  1. Companion PRs merged: The runtime repositories (OpenPLC_v3 and openplc-runtime) now send the X-OpenPLC-Runtime-Version header.

  2. Button order for warning dialog: Buttons are ordered as ['Continue Anyway', 'Cancel'] so that Cancel (index 1) is triggered when closing the modal via Esc or clicking outside.

  3. Modal callback order change: The DebuggerMessageModal now closes before calling onResponse. This is necessary to allow callbacks to open new modals. Other existing uses of this modal (e.g., showDebuggerMessage in workspace-activity-bar) just resolve a Promise and are unaffected.

  4. Regex pattern: The version extraction uses /OpenPLC Runtime (v\d+)/i - verify this matches actual board target names in hals.json.

Suggested review checklist

  • Verify regex pattern matches board target names in hals.json
  • Test connection flow with both v3 and v4 runtimes
  • Test warning dialog behavior with older runtime (no version header)
  • Verify "Continue Anyway" proceeds to login/create-user flow correctly (race condition fix)
  • Verify "Cancel" returns to disconnected state
  • Verify closing warning dialog via Esc triggers Cancel behavior

DOD checklist

  • The code is complete and according to developers' standards.
  • I have performed a self-review of my code.
  • Meet the acceptance criteria.
  • Unit tests are written and green.
  • Test coverage: __ %.
  • Integration tests are written and green.
  • Changes were communicated and updated in the ticket description.
  • Reviewed and accepted by the Product Owner.
  • End-to-end test are successful.

- Update handleRuntimeGetUsersInfo to capture X-OpenPLC-Runtime-Version header
- Add runtimeVersion field to IPC bridge return type
- Add validateRuntimeVersion utility function to check version compatibility
- Show error modal when selected runtime version doesn't match connected runtime
- Helps users identify when they're connecting to wrong runtime version

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai

coderabbitai Bot commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


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

@thiagoralves thiagoralves linked an issue Dec 17, 2025 that may be closed by this pull request
@thiagoralves thiagoralves requested a review from Copilot December 17, 2025 23:06

Copilot AI left a comment

Copy link
Copy Markdown

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 implements runtime version detection to prevent users from connecting to an incompatible OpenPLC runtime version. It extracts the runtime version from HTTP response headers and validates it against the selected board target (e.g., "OpenPLC Runtime v3" vs "OpenPLC Runtime v4").

Key changes:

  • Added utility functions to extract expected runtime version from board target names and validate against detected versions
  • Modified the connection flow to capture and validate the X-OpenPLC-Runtime-Version header from runtime API responses
  • Display error modal when version mismatch is detected or when runtime version cannot be determined

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/utils/device.ts Added getExpectedRuntimeVersion and validateRuntimeVersion utility functions for version extraction and validation
src/renderer/components/_features/[workspace]/editor/device/configuration/board.tsx Integrated version validation into connection flow with error modal display
src/main/modules/ipc/renderer.ts Updated return type for runtimeGetUsersInfo to include optional runtimeVersion field
src/main/modules/ipc/main.ts Captured X-OpenPLC-Runtime-Version header from HTTP responses and included in return values

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/utils/device.ts Outdated
if (normalizedDetected !== normalizedExpected) {
return {
isValid: false,
errorMessage: `Runtime version mismatch: Selected "${boardTarget}" but connected to a ${detectedVersion.toUpperCase()} runtime. Please update your device configuration to match the connected runtime.`,

Copilot AI Dec 17, 2025

Copy link

Choose a reason for hiding this comment

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

The error message uses detectedVersion.toUpperCase() but detectedVersion could be undefined at this point in the code flow. While the undefined check exists at line 61, TypeScript's type narrowing may not carry through here. Consider using normalizedDetected.toUpperCase() instead, which is guaranteed to be defined at line 75.

Suggested change
errorMessage: `Runtime version mismatch: Selected "${boardTarget}" but connected to a ${detectedVersion.toUpperCase()} runtime. Please update your device configuration to match the connected runtime.`,
errorMessage: `Runtime version mismatch: Selected "${boardTarget}" but connected to a ${normalizedDetected.toUpperCase()} runtime. Please update your device configuration to match the connected runtime.`,

Copilot uses AI. Check for mistakes.
Comment thread src/utils/device.ts Outdated

// Normalize versions for comparison (both should be lowercase like "v3", "v4")
const normalizedDetected = detectedVersion.toLowerCase()
const normalizedExpected = expectedVersion.toLowerCase()

Copilot AI Dec 17, 2025

Copy link

Choose a reason for hiding this comment

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

The expectedVersion is already normalized to lowercase by getExpectedRuntimeVersion (line 39), making the second .toLowerCase() call on line 70 redundant. Consider removing it or adding a comment explaining why double-normalization is intentional.

Suggested change
const normalizedExpected = expectedVersion.toLowerCase()
const normalizedExpected = expectedVersion

Copilot uses AI. Check for mistakes.
devin-ai-integration Bot and others added 3 commits December 18, 2025 03:17
- Use normalizedDetected.toUpperCase() instead of detectedVersion.toUpperCase() for safer code
- Remove redundant .toLowerCase() on expectedVersion since getExpectedRuntimeVersion already returns lowercase

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
… option

- Modify validateRuntimeVersion to return status: 'ok' | 'missing' | 'mismatch'
- Show warning dialog for older runtimes without version header
- Add 'Continue Anyway' and 'Cancel' buttons to allow user to proceed
- Update message to suggest updating runtime to latest version

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
When the debugger-message modal's onResponse callback opens another modal,
the subsequent closeModal() call was closing ALL modals including the newly
opened one. Fix by capturing the callback, closing the modal first, then
calling the callback.

This fixes the issue where clicking 'Continue Anyway' on the older runtime
warning dialog would not show the login/create-user dialog.

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
@thiagoralves thiagoralves merged commit f633524 into development Dec 18, 2025
7 of 8 checks passed
@thiagoralves thiagoralves deleted the devin/1766011653-runtime-version-detection branch December 18, 2025 15:02
@RaynoP

RaynoP commented Dec 18, 2025

Copy link
Copy Markdown

Cool thanx. Will test.

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.

Check between v3 and v4 in config before download/connect

3 participants