Skip to content

fix(shared): persist and reuse MCP report name across platform reconnects#2305

Open
yuyutaotao wants to merge 3 commits intomainfrom
codex/add-report-name-handling-in-cli
Open

fix(shared): persist and reuse MCP report name across platform reconnects#2305
yuyutaotao wants to merge 3 commits intomainfrom
codex/add-report-name-handling-in-cli

Conversation

@yuyutaotao
Copy link
Copy Markdown
Collaborator

Motivation

  • Ensure different platform CLIs and device initializations reuse the same report so subsequent act/agent executions append to a single report instead of creating duplicates.
  • Provide a single, simple persisted state file under midscene_run to communicate the current reportFileName between separate CLI/process invocations.

Description

  • Add packages/shared/src/mcp/report-file-name.ts with readPersistedReportFileName() and persistReportFileName() to read/write ./midscene_run/current-report-name.
  • Export the new helper from packages/shared/src/mcp/index.ts and add reportFileName?: string to the BaseAgent type in packages/shared/src/mcp/types.ts.
  • Extend BaseMidsceneTools with getPersistedReportFileName() and persistAgentReportFileName() to centralize reading and writing the persisted name in packages/shared/src/mcp/base-tools.ts.
  • Pass the persisted reportFileName into agent creation and persist the agent's reportFileName after initialization for Web (bridge/puppeteer/CDP), iOS, Android, and Computer MCP tool managers (updated files under packages/web-integration, packages/ios, packages/android, packages/computer).
  • Add unit tests for the new persistence helpers in packages/shared/tests/unit-test/report-file-name.test.ts covering normal read/write and empty-name validation.

Testing

  • Ran pnpm run lint which completed successfully.
  • Ran the focused unit test pnpm --filter @midscene/shared exec vitest --run tests/unit-test/report-file-name.test.ts and it passed.
  • Built affected packages with npx nx build @midscene/shared, @midscene/ios, @midscene/computer, and @midscene/web, all succeeded in this environment.
  • npx nx build @midscene/android failed in this environment due to network ENETUNREACH during the scrcpy prebuild download (environment-specific, unrelated to code change).
  • Full npx nx test @midscene/shared in this environment reported failures in unrelated existing shared tests that require extra prebuilt artifacts (IIFE bundle / tool-generator), while the new focused tests passed.

Codex Task

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 8, 2026

Deploying midscene with  Cloudflare Pages  Cloudflare Pages

Latest commit: 69a4a1e
Status: ✅  Deploy successful!
Preview URL: https://ca2fe4d5.midscene.pages.dev
Branch Preview URL: https://codex-add-report-name-handli.midscene.pages.dev

View logs

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2948b1b8ec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +5 to +8
const REPORT_NAME_STATE_FILE = 'current-report-name';

function getReportNameStateFilePath() {
return path.join(getMidsceneRunBaseDir(), REPORT_NAME_STATE_FILE);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Isolate persisted report name per MCP session

Persisting the active report to a single global file (midscene_run/current-report-name) makes every new MCP connection in the same working directory reuse the same report indefinitely, because this state is never scoped or rotated. In practice, unrelated runs (or a second MCP client started later) will append into prior sessions, merging independent executions and corrupting report boundaries/results.

Useful? React with 👍 / 👎.

Base automatically changed from codex/add-append-report-functionality to main April 8, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants