Skip to content

plan(sdk): harden malformed-success decode errors - #1698

Merged
samuv merged 1 commit into
mainfrom
plan/sdk-malformed-success-causes
Sep 21, 2026
Merged

samuv merged 1 commit into
mainfrom
plan/sdk-malformed-success-causes

Conversation

@samuv

@samuv samuv commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Define the TypeScript SDK's successful-response decoder boundary so malformed unary HTTP and ordinary SSE payloads cannot surface response content through ProtocolError.cause.
  • Preserve body-read, server, authentication, fetch/network, abort, cancellation, and stream/control behavior.
  • Record exact safe metadata, messages, lifecycle proofs, and documentation ownership before implementation.

Development stage

  • Plan / Interface — Bounded/Architectural behavioral and exact-interface contract; no implementation
  • Implementation — based on an approved, merged Plan / Interface PR
  • Combined — compact one-task Bounded/Architectural exception; no separate plan PR
  • Spike / Routine — acceptance-plan spine exempt

Contract linkage

  • Work classification: Architectural
  • Classification rationale: changes the durable public diagnostic and security policy at the TypeScript SDK HTTP successful-response boundary
  • Decision record: docs/adr/0348-typescript-sdk-malformed-success-decoding.md
  • Human waiver of spine: Yes — the directing user explicitly authorized the Implementation PR as the next gh stack layer without waiting for this PR to merge; neither PR is authorized to merge here
  • Acceptance plan: docs/acceptance/sdk-malformed-success-decoding.md
  • Human decisions resolved and recorded: Yes
  • Plan / Interface PR: plan(sdk): harden malformed-success decode errors #1698
  • Approved commit baseline: absent by explicit human exception; the stacked implementation will use this PR's exact committed contract
  • Combined/exemption rationale: N/A — delivery remains Split

Interface conformance

  • Successful-response JSON, well-known-type, and protobuf decode failures retain only SDK-authored messages plus code, HTTP transport, status, and a supplied request ID; they have no own cause property.
  • Post-header body-read failures and existing server, authentication, transport, abort, cancellation, and stream/control semantics retain their established causes and classification.
  • No protobuf, Go API, tool, CLI/config, event, persistence, or public TypeScript signature changes are proposed.

Issue relationship

Relates to #1694

Type of change

  • Behavioral/interface plan
  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation/process
  • Other (describe):

Test plan

Baseline checks

  • Acceptance-plan checker
  • Linting (task lint)
  • Offline test suite (task test)
  • Offline demo (go run ./cmd/mecademo)
  • Markdown changed: docs generation/link checks (CGO_ENABLED=0 task docs)
  • User docs/user-facing behavior changed: site build (task site:build)
  • Guarded engine API affected: compatibility check (task api:check)
  • Intentional engine API change: task api:update + engine/CHANGELOG.md
  • Landed plan: strict acceptance trace (task ac-trace-strict)
  • Final implementation review: /panel-review

task docs requires CGO_ENABLED=0 in this worktree because the host Xcode/macOS SDK linker rejects its own arm64e.x1-* architecture set; all documentation generation and strict link checks pass with CGO disabled.

Changes

File Change
docs/acceptance/sdk-malformed-success-decoding.md Scenario-first contract and exact acceptance proofs
docs/adr/0348-typescript-sdk-malformed-success-decoding.md Durable malformed-success diagnostic/security decision
docs/acceptance/README.md, docs/adr/README.md Plan and ADR index entries

User-facing change

None in this PR; it defines the contract for the stacked implementation.

Special notes for reviewers

The decoder boundary begins only after a unary body has been acquired. Response.json() combines body acquisition with JSON parsing, so the implementation must split response.text() from JSON.parse() to avoid stripping causes from body-read/network failures.

@samuv
samuv force-pushed the plan/sdk-malformed-success-causes branch from b838fe8 to b6e0582 Compare September 18, 2026 09:11
@samuv samuv changed the title plan/sdk malformed success causes plan(sdk): harden malformed-success decode errors Sep 18, 2026
@samuv
samuv added this pull request to stack #1701 September 18, 2026 09:51
@samuv samuv self-assigned this Sep 18, 2026
Define the cause-free successful-response decoder boundary while preserving body-read, server, authentication, transport, and cancellation causes.

Relates to #1694

Co-authored-by: Codex <[email protected]>
Signed-off-by: Samuele Verzi <[email protected]>
@samuv
samuv force-pushed the plan/sdk-malformed-success-causes branch from b6e0582 to c69d606 Compare September 21, 2026 08:38

@kantord kantord left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review summary

Solid Architectural plan/interface PR — no blockers. Cross-checked the plan's claims against the actual TS SDK source and against the stacked implementation PR (#1700), and both hold up.

Verification performed

  • Ran the acceptance-plan checker (check-acceptance-plan.sh) against docs/acceptance/sdk-malformed-success-decoding.md: passes, with only the expected "no named Go test" warning (this plan is verified by vitest, not Go tests).
  • Ran task docs:check (matlatl strict link/anchor check): 0 broken links, 0 broken anchors, 0 orphans, 0 unreachable across 436 docs.
  • Grepped sdk/typescript/src/http.ts for the four decode sites the ADR describes (invalid JSON ×2, invalid response, invalid event) — they exist exactly as claimed, currently attaching the raw decoder exception as cause. The plan's premise is grounded in real code, not speculative.
  • Read the stacked implementation (#1700): it splits response.json() into response.text() (kept as a caused ProtocolError on read failure) followed by a separate JSON.parse() (cause-free on parse failure) — exactly the boundary ADR 0349 / Decision 4 requires between body-read failures and decoder rejections. SSE's JSON.parse(next.value.data) was already naturally separated from the stream-read step, so no equivalent split was needed there. The interface contract was implementable as written, and was implemented as written.

One factual error to fix

The PR body's "Decision record" line points at docs/adr/0348-typescript-sdk-malformed-success-decoding.md. That's wrong — the actual new file in this diff is docs/adr/0349-typescript-sdk-malformed-success-decoding.md. 0348 is a different, already-merged ADR (TypeScript SDK MCP authorization lifecycle, #1687). Looks like a stale copy/paste from before the ADR number was finalized. Worth fixing so a reviewer clicking the link doesn't land on the wrong document — the acceptance plan and ADR file itself correctly use 0349 throughout.

Non-blocking nit

The new docs/adr/README.md entry for 0349 is inserted out of numeric order (after 0348, before 0342). That section was already out of strict numeric order before this PR (0347/0348 were previously inserted the same way), so this isn't a new regression — just continuing existing disorder in that list. Not worth blocking on.

Process

  • Architectural classification is justified — this changes the durable security/diagnostic contract for ProtocolError at the SDK's HTTP boundary.
  • Correctly uses the acceptance-plan spine with a new ADR for the durable decision.
  • The documented "human waiver of spine" (allowing the implementation PR to stack without waiting for this plan PR to merge) matches docs/development-process.md's carve-out: it lifts only plan/interface merge-order ceremony, not verification or human merge authority — both PRs still explicitly require human merge.

Fully or partially written by an AI agent.

@samuv
samuv merged commit 498971e into main Sep 21, 2026
30 checks passed
@samuv
samuv deleted the plan/sdk-malformed-success-causes branch September 21, 2026 11:03
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Sep 21, 2026
2 tasks
JAORMX added a commit that referenced this pull request Sep 21, 2026
Merge origin/main at 686b5e5.

Incoming commits after the approved cleanup base:
- 79fae4d chore(catalog): refresh models.dev curated subset (#1721)
- 73309df chore(deps): bump anthropic-sdk-go (#1713)
- e14c88d slack-bot: DM manual permission approvals (#1707)
- 5b0db5a feat(sdk): add MCP authorization lifecycle (#1692)
- 39715ed chore(deps): bump SDK npm dependencies (#1715)
- 498971e plan(sdk): harden malformed-success decode errors (#1698)
- 9ac4798 slack-bot: relabel session approval (#1724)
- 8de41cd docs(process): route approved cleanup directly (#1720)
- a711451 release v0.0.39 (#1727)
- 44786d1 fix(sdk): sanitize malformed-success decode errors (#1700)
- 85f97fa release TypeScript SDK v0.3.0 (#1729)
- 6501b59 fix(ci): repair live compaction slot and metadata (#1728)
- 8047188 chore(deps): bump toolhive-core (#1712)
- 686b5e5 docs: add README diagrams (#1731)

Conflict resolutions preserve the MCP authorization lifecycle from main while
applying the approved alpha cleanup: Run and MCP continuation results consume
canonical payload usage only; removed EventCommon usage and deprecated aliases
stay removed. Keep the landed authorization acceptance record and both the
Unreleased cleanup note and released v0.3.0 changelog. Regenerate API reports
and user reference from the merged canonical TypeScript sources.

Co-Authored-By: mecatl <[email protected]>
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