Skip to content

fix: recover from session start failures in the AFDX agent preview @W-22434854@#204

Merged
marcelinollano merged 4 commits into
mainfrom
ml/W-22434854-buttons-stuck-on-session-failure
May 14, 2026
Merged

fix: recover from session start failures in the AFDX agent preview @W-22434854@#204
marcelinollano merged 4 commits into
mainfrom
ml/W-22434854-buttons-stuck-on-session-failure

Conversation

@marcelinollano
Copy link
Copy Markdown
Collaborator

@marcelinollano marcelinollano commented May 11, 2026

What does this PR do?

Fixes recovery from session start failures in the AFDX agent preview.

  • Title-bar Refresh and Reset (clear-all) icons no longer get stuck after a session start failure. The webview's isSessionStarting and the agentforceDX:sessionStarting context flag are cleared on error, compilationError, clearMessages, and refreshAgents.
  • Compilation errors now render the same error screen as other failures (icon + bold title + muted subtitle + Go Back button) instead of plain text inside the chat transcript.
  • Error titles are short and distinct: "Agent deactivated", "Agent not found", "Permission denied", "Compilation failed", "Something went wrong". The subtitle holds the human-readable explanation for known cases or the raw server error for the generic case.
  • The agent selector stays mounted while the error screen is showing, so clicking Go Back returns to a populated dropdown with controls enabled.
  • Multi-line compiler output is preserved in the subtitle (white-space: pre-wrap).

What issues does this PR fix or reference?

@W-22434854@

Functionality Before

  • Compilation errors showed as a centered system message with no recovery affordance.
  • Other failure types used full-paragraph bold titles, with the raw server error string shown as the subtitle.
  • After clicking Go Back from the error screen, the dropdown briefly re-loaded and the top start button stayed disabled because the selector remounted from scratch.
  • The title-bar Refresh and Reset icons stayed hidden after early session-start failures.

Functionality After

  • All failure types render the same error screen with short titles and explanatory subtitles.
  • Refresh and Reset icons are reachable from the error screen and recover the view to a usable state.
  • Clicking Go Back keeps the agent selector populated and its controls enabled.
  • Compilation error subtitles render multi-line compiler output correctly.

Testing Setup Notes

Automated

  • npm run test:backend (381 tests) and npm run test:frontend (387 tests) pass. Updated assertions in test/views/agentCombined/handlers/webviewMessageHandlers.test.ts and test/webview/AgentPreview.messages.test.tsx.

Manual verification

  1. Open an agent script project in the Extension Development Host. Select an agent that has a syntax error and click Start Simulation. Expected: error screen with icon, "Compilation failed" title, multi-line compiler output as subtitle, Go Back button. Title-bar Refresh and Reset icons are visible.
  2. From step 1, click Go Back. Expected: returns to the agent selector with the same agent selected, dropdown not loading, top start button enabled.
  3. From step 1, click the title-bar Refresh icon instead. Expected: agents list reloads and the view returns to the placeholder.
  4. From step 1, click the title-bar Reset icon. Expected: clears the error and returns to the agent placeholder for the same agent.
  5. Authenticate to an org and select a deactivated agent, then Start Live Test. Expected: title "Agent deactivated" with the activation guidance as the subtitle.
  6. Repeat with a 403/permission scenario and a 404/deleted agent. Expected: titles "Permission denied" and "Agent not found" with the matching explanation.
  7. Successful session start regression: select a healthy agent and Start Simulation. Expected: no error screen flashes; chat loads; stop and restart work.

When a session start fails, the webview's isSessionStarting flag and
the agentforceDX:sessionStarting context were not reliably cleared,
leaving the title-bar Refresh and Reset buttons unresponsive.

- Always clear setSessionStarting(false) in the backend error handler,
  not just when an agent instance had been created.
- In the webview, clear isSessionStarting on compilationError,
  clearMessages, and refreshAgents in addition to the existing error
  handler.

W-22434854
Compilation errors were rendered as plain text inside the chat
transcript. Route them through the same error screen as other session
start failures, with an icon and a Go Back button. The bold title is
now always "Something went wrong" with the specific cause shown as
details below, so the entry point to recovery is consistent across all
error types.

Keep the agent selector mounted while the error screen is showing so it
does not refetch the agents list and disable its controls when the user
clicks Go Back.

W-22434854
The error screen has a bold title and a muted subtitle. The previous
copy used a long sentence as the title and the raw server error as the
subtitle, which read poorly and exposed stack-like text to users.

Move the human-readable explanation into the subtitle and use short,
recognizable titles for known cases. The generic case still shows the
raw server error in the subtitle, since there is no curated copy to
display there.

W-22434854
@marcelinollano marcelinollano changed the title fix: recover from session start failures in the AFDX agent preview fix: recover from session start failures in the AFDX agent preview @W-22434854@ May 11, 2026
The compilation error subtitle contains EOL-separated lines from
logCompilationError, but the <p> element collapsed them into a single
space. Apply white-space: pre-wrap so multi-line compiler output reads
correctly.

W-22434854
@marcelinollano marcelinollano requested a review from npiccolo May 13, 2026 16:30
Copy link
Copy Markdown
Contributor

@npiccolo npiccolo left a comment

Choose a reason for hiding this comment

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

Manual testing ✅

Setup: Extension Development Host launched from ml/W-22434854-buttons-stuck-on-session-failure, agent script project afdx-pro-code-testdrive opened in the test window.

Compilation error recovery
Selected TestVerboseAgent, introduced a syntax error, clicked Start Simulation. Error screen appeared with "Compilation failed" as the bold title and the compiler output as the subtitle. Title-bar Refresh and Reset icons were visible and responsive. Clicking Go Back returned to the agent selector with the agent still selected, dropdown not loading, Start button enabled and ready.

Happy path regression
Restored the agent file, selected TestVerboseAgent, clicked Start Simulation. Chat loaded cleanly with no error flash. Sent a message and received a correct response. Clicked Stop then Start Simulation again — restarted cleanly with no stuck state.

Automated tests: npm run test:backend (381/381) and npm run test:frontend (387/387) all pass.

LGTM ✅

@marcelinollano marcelinollano merged commit 5019e7a into main May 14, 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.

2 participants