Skip to content

feat(core): record exact model input screenshots - #2856

Closed
quanruzhuoxiu wants to merge 1 commit into
mainfrom
feat/model-input-screenshot-evidence
Closed

feat(core): record exact model input screenshots#2856
quanruzhuoxiu wants to merge 1 commit into
mainfrom
feat/model-input-screenshot-evidence

Conversation

@quanruzhuoxiu

Copy link
Copy Markdown
Collaborator

Summary

  • record the exact image bytes passed to each model request after preprocessing
  • annotate model-input screenshots with a SHA-256 digest for report verification
  • reuse existing screenshot objects when the model receives identical bytes
  • deduplicate retry recordings while preserving parent runtime callbacks

Stack

This is PR 3 of 4 for the WebP foundation split. It is intentionally based on main and can be reviewed and merged independently from #2854 and #2855.

The original foundation PR #2851 remains unchanged as a rollback option.

Validation

  • pnpm exec nx run-many -t build -p @midscene/shared @midscene/core
  • pnpm --filter @midscene/core test (124 files, 1,347 passed, 8 skipped)
  • pnpm run type-check:tests
  • pnpm run lint

@quanruzhuoxiu
quanruzhuoxiu force-pushed the feat/model-input-screenshot-evidence branch from 2b30d4f to c970fa9 Compare July 24, 2026 07:47
@quanru
quanru marked this pull request as ready for review July 27, 2026 07:20

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

Copy link
Copy Markdown

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: c970fa95c0

ℹ️ 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".

uiScreenshot &&
screenshotContentHash(uiScreenshot.base64) === contentHash
? uiScreenshot
: ScreenshotItem.create(imageBase64, Date.now());

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 Preserve WebP when wrapping model inputs

When an input is WebP—as explicitly exercised by the new recorder test—this creates a ScreenshotItem that silently classifies it as PNG. Its rawBase64 accessor only removes PNG/JPEG prefixes, so file-backed report serialization decodes the entire data:image/webp;base64,... URI as base64 and writes corrupt bytes; inline references also advertise the wrong MIME type. Extend ScreenshotItem and ScreenshotRef to preserve the actual format rather than wrapping arbitrary data:image/* as PNG.

AGENTS.md reference: AGENTS.md:L9-L12

Useful? React with 👍 / 👎.

continue;
}

const uiScreenshot = task.uiContext?.screenshot ?? sourceScreenshot;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reuse matching screenshot-sequence items

When a UIObserver assertion supplies uiContext.screenshotSequence, extraction sends every buffered frame to the model, but this lookup considers only the representative screenshot. Each earlier frame therefore receives a new ScreenshotItem ID, after which recordAndReleaseScreenshotSequence adds the original frame objects to the same task. Because report persistence deduplicates by ID rather than content hash, multi-frame assertions persist and render every earlier screenshot twice; match against screenshotSequence as well before creating a new item.

Useful? React with 👍 / 👎.

@quanru

quanru commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Closing this outdated implementation. The final model image bytes are now determined at the model-request preparation boundary, while this PR hooks older task-level call sites and no longer guarantees that the recorded image matches the payload sent to the provider. Exact request payloads can already be inspected through model-call recording. If report-visible model input evidence is still needed, it should be redesigned on top of the current request pipeline rather than rebasing this implementation.

@quanru quanru closed this Aug 26, 2026
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