Skip to content

fix: agent preview session lifecycle continuity @W-22497762@#210

Merged
marcelinollano merged 1 commit into
mainfrom
ml/w-22497762-agent-preview-loading-continuity
May 16, 2026
Merged

fix: agent preview session lifecycle continuity @W-22497762@#210
marcelinollano merged 1 commit into
mainfrom
ml/w-22497762-agent-preview-loading-continuity

Conversation

@marcelinollano
Copy link
Copy Markdown
Collaborator

Summary

@W-22497762@

App now owns a single source of truth for the Agent Preview session-transition lifecycle (isSessionStarting, isSessionTransitioning, isStopPending) and threads it down to both AgentSelector (for button disabled state) and AgentPreview (for input disabled state). This eliminates several visible glitches when starting, stopping, and switching between Simulation and Live Test, and removes a redundant "Agent preview reset." VS Code toast.

Before

  • Tabs flicker visible → hidden → visible when stopping a simulation, switching to Live Test, and clicking Start.
  • The chat area goes blank for a frame with the tabs still floating above it during the same transition.
  • The loading state briefly disappears between Start click and the backend's first sessionStarting message.
  • The Start/Stop button re-enables momentarily during loading (between optimistic stop and backend ack, between sessionEnded and sessionStarting on a restart, between Stop click and sessionEnded).
  • After clicking Stop, the chat input stays interactive while the session is stopping. Typing into it activates the Send button.
  • Hitting "Go Back" on a session error screen pops a "Agent preview reset." VS Code toast even though the UI itself already reflects the reset.

After

  • Tabs are visible whenever an agent is selected; no flicker on transitions.
  • Chat area shows a continuous loading spinner across sessionEnded → sessionStarting during a restart.
  • Loading state appears on the very next render after the click, before any backend round-trip.
  • Start/Stop button stays disabled continuously from click through sessionStarted (and from Stop click through sessionEnded).
  • Chat input disables immediately on Stop click, before the backend confirms sessionEnded.
  • No toast on error reset.

Testing

Automated

  • npm run test:frontend — 456 passing (was 434 before this branch). Newly added:
    • test/webview/App.sessionLifecycle.test.tsx (11 tests) covers Start, Stop, clearMessages gating during transitions, error/recovery paths (error, compilationError, refreshAgents all clear isStopPending), and prop wiring to AgentSelector / AgentPreview.
    • 6 new tests in test/webview/AgentSelector.test.tsx for the new isSessionTransitioning disabled wiring on the SplitButton, published-agent button, Stop button, and agent dropdown, plus mode-switch behavior.
    • 4 new tests in test/webview/AgentPreview.sendMessage.test.tsx for the new handleSendMessage guards (parentIsSessionActive, isStopPending, isSessionTransitioning).
    • 1 new test in test/webview/AgentPreview.placeholder.test.tsx verifying the placeholder Start button delegates to parentOnStartSession when provided.
  • npm run test:backend — 386 passing. Includes a fix to test/services/coreExtensionService.test.ts that mocks @salesforce/core's ConfigAggregator and Org so the fallback path no longer reaches into the host's ~/.sfdx config and a real Salesforce connection during tests.

Manual

  1. Open the AFDX Agent Preview view and pick an agent script. Confirm tabs (Preview / Tracer) appear once an agent is selected.
  2. Click "Start Simulation". Confirm the loading spinner appears immediately on click and stays continuously visible until the welcome message arrives. Confirm the Start button is disabled the entire time.
  3. With the simulation active, type a message. Confirm the input is enabled and Send works.
  4. Click "Stop Simulation". Confirm:
    • The Start button is disabled until the backend acknowledges the stop.
    • The textarea is immediately not typeable (placeholder switches to "Type something to start the simulation...").
    • Try clicking into the textarea and pressing keys — nothing happens, and the Send button stays disabled.
  5. Open the mode dropdown, switch to Live Test, click "Start Live Test". Confirm:
    • Tabs do NOT flicker.
    • The chat area does NOT go blank with tabs floating above it.
    • The loading spinner is continuous from click → live test session ready.
    • The button stays disabled the entire time.
  6. Repeat the live → simulation switch with an active session. Same expectations as step 5.
  7. Trigger a session error (e.g. point at an agent that fails to compile). Click "Go Back" on the error screen. Confirm there is NO "Agent preview reset." VS Code information toast.

App now owns a single source of truth for the session-transition
lifecycle (isSessionStarting, isSessionTransitioning, isStopPending) and
threads it down to both AgentSelector and AgentPreview. This fixes:

- Tab flicker when switching between simulation and live test
- Blank chat area with floating tabs during transitions
- Loading state gaps between click and backend acknowledgement
- Start/Stop buttons re-enabling momentarily during loading
- Chat input remaining interactive after Stop click

Also removes the noisy "Agent preview reset." VS Code toast and adds 22
new tests covering the lifecycle behavior. Mocks @salesforce/core in the
coreExtensionService test so the fallback path no longer reaches into
the host's ~/.sfdx config.
@marcelinollano marcelinollano requested a review from npiccolo May 14, 2026 22:55
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-22497762-agent-preview-loading-continuity, agent script project afdx-pro-code-testdrive opened in the test window.

Tabs appear on agent select — Preview and Tracer tabs appear immediately on agent selection with no flicker.

Loading spinner is immediate — spinner appears on the next render after clicking Start, before any backend round-trip. Start button stays disabled continuously through sessionStarted.

Chat input during active session — input enabled and Send works normally.

Stop disables input immediately — chat input becomes non-typeable instantly on Stop click, before backend confirms sessionEnded. Start button stays disabled until ack.

No tab flicker on mode switch — switching Simulation → Live Test and Live Test → Simulation produces no tab flicker, no blank chat area, continuous loading spinner.

No "Agent preview reset." toast — triggering a compilation error and clicking Go Back produces no VS Code information toast.

Automated tests: npm run test:backend (386/386) and npm run test:frontend (456/456) all pass.

LGTM ✅

@marcelinollano marcelinollano merged commit bee0816 into main May 16, 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