Skip to content

Conversation

@lmac-1
Copy link
Collaborator

@lmac-1 lmac-1 commented Nov 7, 2025

Description

This PR improves the history panel experience in the collaborative editor by fixing critical bugs that prevented navigation to the "view all history" page and adding a version mismatch warning to prevent user confusion.

Closes #3814 and point 1 of #3940

History page 500 error when navigating from collaborative editor

image
  • Frontend: Fix workflow ID extraction in MiniHistory - was taking "collaborate" instead of the actual UUID from /w/:id/collaborate URLs
  • Backend: Handle nil case in humanize_workflow when workflow not found
  • Impact: "View History" button now works from collaborative editor

Feature: Version mismatch warning banner

Shows a warning when viewing latest workflow but selected run was executed on an older version. Prevents confusion when workflow structure has changed since the run executed. Appears when:

  • Run selected AND viewing "latest" AND versions differ

Example message:

image

⚠️ This run was executed on version 66, but you're viewing version 67. Steps shown may not match the current workflow structure.

Testing

  • All existing tests passing
  • 8 new unit tests for version mismatch detection hook

Validation steps

Version mismatch warning:
You have two choices

  1. Pick an existing workflow where the structure has changed over time in the last 20 runs
  2. Make an update to an existing workflow and click Save

Once you have a workflow where the latest version is different to previous version:

  1. Select an old run while viewing "latest" -> Banner appears
  2. Switch to matching snapshot version -> Banner disappears
  3. Deselect run -> Banner disappears

Bug fix:

  1. Open workflow in collaborative editor -> Click the little icon next to "View full history" (marked in screenshot above)
  2. Verify history page loads AND that it has the correct content (it previously crashed)

Additional notes for the reviewer

I tried to make the banner look similar to existing banner in LiveView using Tailwind colours.

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our Responsible AI Policy

Pre-submission checklist

  • I have performed a self-review of my code.
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

@github-project-automation github-project-automation bot moved this to New Issues in v2 Nov 7, 2025
@lmac-1 lmac-1 requested review from stuartc and taylordowns2000 and removed request for taylordowns2000 November 7, 2025 14:54
@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.66%. Comparing base (7ef09a6) to head (ead8c72).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3941      +/-   ##
==========================================
+ Coverage   88.64%   88.66%   +0.02%     
==========================================
  Files         422      422              
  Lines       18913    18913              
==========================================
+ Hits        16766    16770       +4     
+ Misses       2147     2143       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lmac-1 lmac-1 requested review from stuartc and taylordowns2000 and removed request for stuartc November 7, 2025 16:48
@lmac-1
Copy link
Collaborator Author

lmac-1 commented Nov 7, 2025

This one is ready for review @stuartc @taylordowns2000 @theroinaochieng ☺️. Probably one for Monday now.

@lmac-1
Copy link
Collaborator Author

lmac-1 commented Nov 7, 2025

@stuartc I decided to put the version mismatch stuff in a hook to not overcomplicate components. There's also a test to test the logic of the hook.

Copy link
Member

@taylordowns2000 taylordowns2000 left a comment

Choose a reason for hiding this comment

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

the history navigation link works perfectly, but I'm seeing two bugs in the version matching stuff:

  1. when going to an old run, it should take you to that version—not keep you on latest and show the mismatch banner. (play around with this feature on the legacy canvas to see how it should work.)
  2. i'm seeing all the nodes collapse into the middle.

Both of these show up in the video here: https://www.loom.com/share/5fd45ef0e7bf4911a56bf511c03729c4

@github-project-automation github-project-automation bot moved this from New Issues to In review in v2 Nov 12, 2025
@elias-ba elias-ba self-requested a review November 12, 2025 20:04
Copy link
Contributor

@elias-ba elias-ba left a comment

Choose a reason for hiding this comment

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

Hey @lmac-1 this is looking great to me from a code point of view. I alkso clicked tested and it looks great. I will leave the UI approvals to Taylor. @taylordowns2000 just wanna flag that the nodes collapsing issue might be out of scope of this work. It has became rare now but it's still happening from time to time in the app on main. I think we may need to have a proper issue for it and do deep diagnostic for it. I do think that it's deeply related to nodes positionning and layout algorithm.

@elias-ba elias-ba force-pushed the history-tidying-bugs branch 2 times, most recently from 5a92ab4 to 899f337 Compare November 12, 2025 20:36
@lmac-1
Copy link
Collaborator Author

lmac-1 commented Nov 13, 2025

Hey @taylordowns2000 thanks for the Loom, yes that makes sense, will take a look! I didn't realise that the version should update at the top.

And for the nodes collapsing, I have also been seeing it a bit in other bits of dev work that I'm working on in other branches / main, but not sure what are the exact steps to replicate. Seems to be a bit random. As @elias-ba suggested, it might be worth diving deeper into that in a separate issue. Will try to keep an eye out for it though to see what is causing it.

@lmac-1
Copy link
Collaborator Author

lmac-1 commented Nov 13, 2025

I think I've fixed the node position bug... but would appreciate some help in understanding how 😅

I was able to consistently reproduce the collapsing nodes issue across multiple branches using these steps:

  1. Select a run from the history panel with a "Failed" status.
  2. Refresh the page.
  3. The nodes will appear collapsed at position (0,0).
  4. If you then select a different run and return to the failed run, the nodes display correctly.

I looked into this with Claude, and it suggested the fix I implemented here in this branch in adc80d9. The fix works, but I don't fully understand why: The change suppresses the "could not auto-calculate position" warnings when the positions cache is empty on initial render (which is expected before layout runs). But removing these console.warn() calls also fixes the visual issue where nodes appear collapsed - not just the console spam. My theory is that the console operations during the render cycle were causing some kind of timing/performance issue that prevented the layout system from completing before React painted the nodes. But I'm not confident in this explanation. @elias-ba - do you have insight into why removing these warnings would fix the visual positioning issue? Is there something about how ReactFlow or the layout system interacts with synchronous operations during render that I'm missing?

@taylordowns2000 can you retest where you saw the error? It should happen when you have a run selected with a non-successful status and then refresh the page.

@lmac-1
Copy link
Collaborator Author

lmac-1 commented Nov 13, 2025

Okay @taylordowns2000, I think I have fixed everything you mentioned:

  1. Clicking on runs now automatically updates the version in the header
  2. If you then manually select "Latest", the warning appears as expected

I also improved the warning logic so it appears whenever you're viewing a different version than the run's version, not just when viewing "latest". For example:

  1. You select a run that was executed on version 4
  2. The header automatically switches to v4 (no warning - versions match)
  3. You manually change to "Latest" (version 5) → Warning appears: "This run was executed on version 4, but you're viewing version 5..."
    4.You manually change to version 3 → Warning still appears: "This run was executed on version 4, but you're viewing version 3..."

This gives you flexibility to compare runs against any workflow version while staying aware of mismatches.

Copy link
Member

@taylordowns2000 taylordowns2000 left a comment

Choose a reason for hiding this comment

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

Fantastic! Thanks, @lmac-1 !

lmac-1 and others added 2 commits November 13, 2025 17:11
Display warning banner when viewing latest workflow version but selected
run was executed on an older version. This prevents user confusion when
workflow structure has changed since the run executed (jobs added,
removed, or modified).

Features:
- VersionMismatchBanner component using bg-yellow-100 styling to match
  other warning elements (VersionDropdown, credential badges)
- useVersionMismatch hook encapsulating detection logic
- Full-width banner at top of canvas, consistent with LiveView alerts
- 8 passing tests covering all edge cases and null safety

The banner shows when:
- A run is selected from history
- Viewing "latest" workflow (not a specific snapshot)
- Run's version differs from current workflow version

Fix history page 500 error and workflow filtering

Fixes two related bugs that prevented the history page from loading when
navigating from the collaborative editor:

1. Backend: Fix MatchError crash in humanize_workflow
   - Handle nil case when Enum.find doesn't find the workflow
   - Previously crashed with "no match of right hand side value: nil"
   - Now returns empty string when workflow not found

2. Frontend: Fix workflow ID extraction in MiniHistory
   - Extract workflow ID from position [1] instead of last element
   - Previously took "collaborate" instead of the actual workflow UUID
   - Now works for both /w/:id and /w/:id/collaborate URLs

The bug occurred when clicking "View History" from the collaborative
editor because the frontend was sending workflow_id="collaborate" which
the backend couldn't find, causing a 500 error.

Add test coverage for missing workflow in humanize_search_params

Adds test case to cover the nil branch when a workflow_id filter
references a workflow that doesn't exist in the workflows list.

Fix node position warnings and layout jumps on initial render

When viewing workflow runs (especially failed runs), nodes would trigger
"could not auto-calculate position" warnings during initial render and
briefly appear at incorrect positions before jumping to their correct layout.
This happened after page refresh when the positions cache starts empty before
the layout system runs, which is expected behavior.

Changes:
- Only log warning if positions map has data but parent still not found
- Silently default to {x: 0, y: 0} when positions cache is empty on first render
- Eliminates console spam and improves render performance for failed run views

Auto-switch workflow version when selecting run from history

When clicking a run in the MiniHistory panel, automatically switch the
workflow view to display the version that was used when that run executed.
This matches the LiveView editor behavior and eliminates confusion about
viewing mismatched versions.

Changes:
- Auto-detect run's workflow version and switch to it on selection
- Show version mismatch warning for ANY version mismatch, not just when
  viewing latest (fixes issue where warning didn't appear when manually
  switching between historical versions)
- URL now includes both run and version parameters (?run=<id>&v=<version>)

Fixes the issue where IDE header would show "latest" while viewing a run
from an older version, causing unnecessary version mismatch warnings.

Update CHANGELOG for PR #3941
Replace brittle URL parsing with clean navigation utilities that get
IDs from state instead of parsing window.location. Uses URLSearchParams
for proper query string encoding and provides reusable functions for
navigating to history and run pages.

- Extract navigation logic to dedicated utility module
- Get project/workflow IDs from hooks instead of URL parsing
- Add comprehensive test coverage for navigation utilities
- Update MiniHistory tests to mock new dependencies
@stuartc stuartc force-pushed the history-tidying-bugs branch from ead8c72 to a06f02d Compare November 13, 2025 15:11
@stuartc stuartc merged commit baeaef7 into main Nov 13, 2025
0 of 6 checks passed
stuartc pushed a commit that referenced this pull request Nov 13, 2025
Display warning banner when viewing latest workflow version but selected
run was executed on an older version. This prevents user confusion when
workflow structure has changed since the run executed (jobs added,
removed, or modified).

Features:
- VersionMismatchBanner component using bg-yellow-100 styling to match
  other warning elements (VersionDropdown, credential badges)
- useVersionMismatch hook encapsulating detection logic
- Full-width banner at top of canvas, consistent with LiveView alerts
- 8 passing tests covering all edge cases and null safety

The banner shows when:
- A run is selected from history
- Viewing "latest" workflow (not a specific snapshot)
- Run's version differs from current workflow version

Fix history page 500 error and workflow filtering

Fixes two related bugs that prevented the history page from loading when
navigating from the collaborative editor:

1. Backend: Fix MatchError crash in humanize_workflow
   - Handle nil case when Enum.find doesn't find the workflow
   - Previously crashed with "no match of right hand side value: nil"
   - Now returns empty string when workflow not found

2. Frontend: Fix workflow ID extraction in MiniHistory
   - Extract workflow ID from position [1] instead of last element
   - Previously took "collaborate" instead of the actual workflow UUID
   - Now works for both /w/:id and /w/:id/collaborate URLs

The bug occurred when clicking "View History" from the collaborative
editor because the frontend was sending workflow_id="collaborate" which
the backend couldn't find, causing a 500 error.

Add test coverage for missing workflow in humanize_search_params

Adds test case to cover the nil branch when a workflow_id filter
references a workflow that doesn't exist in the workflows list.

Fix node position warnings and layout jumps on initial render

When viewing workflow runs (especially failed runs), nodes would trigger
"could not auto-calculate position" warnings during initial render and
briefly appear at incorrect positions before jumping to their correct layout.
This happened after page refresh when the positions cache starts empty before
the layout system runs, which is expected behavior.

Changes:
- Only log warning if positions map has data but parent still not found
- Silently default to {x: 0, y: 0} when positions cache is empty on first render
- Eliminates console spam and improves render performance for failed run views

Auto-switch workflow version when selecting run from history

When clicking a run in the MiniHistory panel, automatically switch the
workflow view to display the version that was used when that run executed.
This matches the LiveView editor behavior and eliminates confusion about
viewing mismatched versions.

Changes:
- Auto-detect run's workflow version and switch to it on selection
- Show version mismatch warning for ANY version mismatch, not just when
  viewing latest (fixes issue where warning didn't appear when manually
  switching between historical versions)
- URL now includes both run and version parameters (?run=<id>&v=<version>)

Fixes the issue where IDE header would show "latest" while viewing a run
from an older version, causing unnecessary version mismatch warnings.

Update CHANGELOG for PR #3941
@stuartc stuartc deleted the history-tidying-bugs branch November 13, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Canvas: View a Run on the Canvas

5 participants