Skip to content

fix(contracts): malformed image and response context no longer blocks message send - #43386

Open
saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:hunter/c-70ac64d8d1
Open

saphid wants to merge 1 commit into
pingdotgg:mainfrom
saphid:hunter/c-70ac64d8d1

Conversation

@saphid

@saphid saphid commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Problem

An image or response context record with explicit undefined in optional metadata makes JSON encoding reject the entire message with Expected JSON value. Image source, response subagents and their environmentId, nested snapshot metadata, and citation comments bypass the existing validation that should drop malformed records and preserve valid siblings.

Deterministic repro on origin/main (cc61cdb1e434ec4468468487abee5c422b535be4)

From packages/contracts, run node --input-type=module with this standard input:

import * as Schema from 'effect/Schema';
import { OrchestrationMessageContext } from './src/composerContext.ts';
const encode = Schema.encodeUnknownSync(Schema.toCodecJson(OrchestrationMessageContext));
const valid = { version: 1, contextId: 'ctx_1', kind: 'skill', label: '$x', name: 'x' };
const image = { version: 1, contextId: 'ctx_2', kind: 'image', label: 'a.png', attachmentId: 'att_1', name: 'a.png', mimeType: 'image/png', sizeBytes: 10 };
const response = {
  version: 1, contextId: 'ctx_2', kind: 'response', label: 'Reply', itemId: 'item-1',
  citation: { version: 1, environmentId: 'env-1', threadId: 't1', messageId: 'm1', text: 'Reply', start: 0, end: 5, prefix: '', suffix: '' },
};
const source = {
  kind: 'snap-shot', capturedAt: '2026-01-01T00:00:00.000Z', appName: 'App', windowTitle: 'Win', accessibleText: 'Save',
  accessibility: { format: 'element-tree', coordinateSpace: 'captured-image', imageSize: { width: 100, height: 100 }, truncated: false,
    root: { role: 'button', bounds: null, state: { active: true }, children: [] } },
};
for (const [name, record] of [
  ['image.source', { ...image, source: undefined }],
  ['response.subagents', { ...response, subagents: undefined }],
  ['response.subagents[].environmentId', { ...response, subagents: [{ threadId: 't2', title: 'sub', environmentId: undefined }] }],
  ['image.source.accessibleText', { ...image, source: { ...source, accessibleText: undefined } }],
  ['image.source.accessibility.root.state.active', { ...image, source: { ...source, accessibility: { ...source.accessibility, root: { ...source.accessibility.root, state: { active: undefined } } } } }],
  ['response.citation.comment', { ...response, citation: { ...response.citation, comment: undefined } }],
  ['valid image source', { ...image, source }],
  ['valid response comment', { ...response, citation: { ...response.citation, comment: 'Check this' } }],
]) {
  try { console.log(name + ': ' + JSON.stringify(encode({ version: 1, records: [valid, record] }))); }
  catch (error) { console.log(name + ': ' + error.message); }
}

Observed: all six malformed cases print Expected JSON value at ["records"][1]. Expected: each malformed case encodes { version: 1, records: [valid] }, dropping only ctx_2 and preserving ctx_1. The two valid controls must preserve both records.

Change

Use Schema.optionalKey for the three fields and validate embedded snapshot sources and assistant citations as JSON at the composer-context boundary, so explicit undefined fails record validation before the outer JSON codec runs. Extend the existing wire-encoding regression test with six malformed fixtures and valid snapshot/citation controls. The standalone attachment and citation schemas retain their existing semantics. This shared contract applies to server, web, desktop, and mobile messages across providers and local/remote connections; no UI, RPC shape, or translation changes are needed.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • The extended regression failed on base with SchemaError: Expected JSON value at ["records"][1].
  • The complete composerContext.test.ts passed three consecutive runs on the fix (8/8 tests each).
  • vp run check:changed exited 0.
  • Real Node codec before/after transcript: all six malformed cases throw on base and encode cleanly with ctx_1 preserved after the fix; valid snapshot-source and citation-comment controls preserve both records.
  • Not shown: live WebSocket send, persistence round trip, provider execution, web/desktop/mobile interaction.

Authored by GPT-6.1 Sol (Codex); reviewed by Gemini 4 Neon (Antigravity).

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Composer context schemas now constrain image sources and response citations to JSON-compatible values and reject explicit undefined in selected optional fields. Wire tests cover valid image and response records and malformed records with missing optional values.

Changes: Composer context validation

Layer / File(s) Summary
Schema constraints and wire validation
packages/contracts/src/composerContext.ts, packages/contracts/src/composerContext.test.ts
Image sources and response citations now require JSON-compatible values. Optional image and response fields use optional-key validation. Wire tests cover valid records and cases with malformed optional values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: yash-singh1

Merge Risk: Minimal · up to 19042

This change stops malformed optional image or response context fields from blocking message send, and valid sibling records are preserved. No merge-blocking risk was identified in the reviewed schema and test changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: malformed image and response context records with explicit undefined no longer block message send. The changeset adds optionalKey and JSON validation to composerContex…
Description check Passed The description follows the template's Problem, Change, Scope, and Verification sections. The Problem section gives a reproduction and expected behavior. The Change section explains the schema fix and…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: malformed image and response context records with explicit undefined no longer block message send. The changeset adds optionalKey and JSON validation to composerContext.ts and extends its wire-encoding test, so the title matches. It is long at 82 characters, but it is clear and specific.

Full details: Description check

Explanation

The description follows the template's Problem, Change, Scope, and Verification sections. The Problem section gives a reproduction and expected behavior. The Change section explains the schema fix and why no UI or RPC change is needed. Scope states it is a small bug fix and explains why no issue is linked. Verification lists focused test results, a failing base run, and a transcript, and it states what was not checked. The template's agent-attribution line is present. The Scope section does not link an issue, which the template allows for small obvious fixes. The Verification transcript is an external gist, and the description embeds no screenshots, which is acceptable because this is not a UI change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 12c1152 and 19042fb.

Files selected for processing: 2

  • packages/contracts/src/composerContext.test.ts
  • packages/contracts/src/composerContext.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant