Skip to content

feat: Implement session step recording, history lifecycle#36

Merged
Winify merged 8 commits intomainfrom
feature/session-recording
Mar 18, 2026
Merged

feat: Implement session step recording, history lifecycle#36
Winify merged 8 commits intomainfrom
feature/session-recording

Conversation

@Winify
Copy link
Copy Markdown
Collaborator

@Winify Winify commented Mar 16, 2026

Proposed changes

  • Session history is exposed via MCP resources (wdio://sessions, wdio://session/current/steps) so clients can inspect recorded steps without tool calls.
  • The index resource will advertise available URI templates to make session
    navigation fully discoverable.
  • Generated WebdriverIO JS code will branch on session type (browser | ios | android) to emit platform-correct commands, and preserve all recorded params to avoid silent data loss on playback.
  • Error steps will be wrapped in try/catch rather than commented out, keeping replayed scripts structurally faithful to the original session.

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have squashed commits that belong together
  • I have tested with Claude Desktop (or another MCP-compatible client)
  • I have read the CONTRIBUTING doc
  • I have added the necessary documentation for new/changed tools (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Further comments

Reviewers: @webdriverio/project-committers

Base automatically changed from feature/attach-emulate-tools to main March 17, 2026 07:22
@Winify Winify marked this pull request as ready for review March 17, 2026 07:24
Winify added 3 commits March 17, 2026 08:58
…verIO code generation

- Added `RecordedStep` and `SessionHistory` types for session tracking.
- Introduced `withRecording` HOF and `appendStep` for step logging.
- Extended browser and app session management to initialize and maintain session histories, including transition sentinels and lifecycle markers.
- Developed WebdriverIO JavaScript code generator from recorded steps.
- Registered MCP resources for session indexing and step inspection.
- Added corresponding tests and updated design documentation.
@Winify Winify force-pushed the feature/session-recording branch from abcf3a4 to 630201b Compare March 17, 2026 07:58
wdio-bot and others added 2 commits March 17, 2026 08:01
…ort details

- Added documentation for session step recording, MCP resources, and generated WebdriverIO JS scripts.
- Updated file structure and descriptions to include recording, code generation, and MCP resource components.
- Highlighted session recording as a feature in the README.
};
return `const browser = await remote(${indentJson(config)});`;
}
case 'navigate':
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Winify I see you have added multiple actions here still lot of them are missing are those going to be added in future?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I did not want to capture every tool calling, just driver/browser interactions that induce change

What actions d you think could be good candidates?

Copy link
Copy Markdown
Collaborator Author

@Winify Winify Mar 17, 2026

Choose a reason for hiding this comment

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

You are right, I added the sessions after the initial commit, and it became jumbled, will take a look

return textContent ? (textContent as any).text : 'Unknown error';
}

export function withRecording(toolName: string, callback: ToolCallback): ToolCallback {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All existing tools return errors like "Error closing session: ..." or "Error: ...", so this works today, but it is a brittle string-prefix check that will silently miss errors from any future tool that uses a different format (e.g. "Failed to...", "Unable to find...").

Suggestion: Use the MCP SDK's isError field if available, or introduce a convention: tools should set result.isError = true when returning errors, as the SDK supports this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I will take a look at this

I wanted to refactor the tools' response data for a while now, but somehow always fell short

@mccmrunal
Copy link
Copy Markdown

mccmrunal commented Mar 17, 2026

Please take a look at these below points too

  1. The start_browser and start_app_session tools are not wrapped with withRecording() in server.ts
  2. SessionHistory is never cleared ( might lead to memory leak)

@Winify
Copy link
Copy Markdown
Collaborator Author

Winify commented Mar 17, 2026

Please take a look at these below points too

  1. The start_browser and start_app_session tools are not wrapped with withRecording() in server.ts
  2. SessionHistory is never cleared ( might lead to memory leak)
  1. SessionHistory is always appended to existing sessions, start_browser and start_app_session tools are what creating these sessions, so I did not find it useful to describe the sessionHistory of the tool that creates said history
  2. The mcp state is ephemeral, if the server restarts then it just cleans itself

Do you think there will be long-lived sessions where it could pose a problem? I do not think it should be dangerous even with a couple sessions with couple hundred steps

Winify added 3 commits March 17, 2026 17:25
@Winify
Copy link
Copy Markdown
Collaborator Author

Winify commented Mar 17, 2026

@mccmrunal I have added some fixes

@mccmrunal
Copy link
Copy Markdown

@mccmrunal I have added some fixes

Great updates @Winify! Pulled the latest and went through all the changes , most of the concerns are resolved. I think we can move ahead for now . You can merge this.

@Winify Winify merged commit 222e9c3 into main Mar 18, 2026
2 checks passed
@Winify Winify deleted the feature/session-recording branch March 19, 2026 17:38
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.

3 participants