Skip to content

fix(gateway): harden artifact RPCs#74926

Merged
BunsDev merged 12 commits intomainfrom
meow/74898-artifact-rpc-hardening
May 1, 2026
Merged

fix(gateway): harden artifact RPCs#74926
BunsDev merged 12 commits intomainfrom
meow/74898-artifact-rpc-hardening

Conversation

@BunsDev
Copy link
Copy Markdown
Member

@BunsDev BunsDev commented Apr 30, 2026

Summary

Duplicate triage

Validation

  • pnpm test src/gateway/server-methods/artifacts.test.ts packages/sdk/src/index.test.ts -- --reporter=verbose
  • pnpm protocol:check
  • pnpm exec oxfmt --check --threads=1 docs/concepts/openclaw-sdk.md CHANGELOG.md packages/sdk/src/client.ts packages/sdk/src/index.test.ts packages/sdk/src/index.ts packages/sdk/src/types.ts src/gateway/server-methods/artifacts.ts src/gateway/server-methods/artifacts.test.ts
  • git diff --check
  • OPENCLAW_TESTBOX=1 pnpm check:changed via Testbox tbx_01kqeka3th39zq2pwpp2d3eeqh / https://github.com/openclaw/openclaw/actions/runs/25152198814

Closes #74706.
Refs #74898, #74769, #74804, #74786.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Apr 30, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented Apr 30, 2026

Codex review: found issues before merge.

What this changes:

The PR adds SDK-facing Gateway artifacts.list/get/download RPCs, read-scope registration, protocol and Swift models, SDK oc.artifacts helpers/types/docs, changelog coverage, and task-scope lookup/download-source hardening.

Maintainer follow-up before merge:

Protected maintainer-labeled MEMBER PR with a P2 behavioral blocker and an overlapping open artifact RPC alternative; this needs normal maintainer PR review and a chosen provenance contract, not an automated ClawSweeper repair lane.

Security review:

Security review cleared: Security review cleared: the diff adds read-scoped transcript artifact RPCs and SDK/docs/types without new dependencies, workflow changes, secrets handling, lifecycle hooks, package resolution changes, or server-side URL fetching.

Review findings:

  • [P2] Preserve provenance before filtering scoped artifacts — src/gateway/server-methods/artifacts.ts:226-230
Review details

Best possible solution:

Land one canonical maintainer-approved artifact RPC implementation that keeps the read-scope gating, SDK/docs/protocol synchronization, and unsafe download guardrails, while either persisting and reading real run/task provenance before filtering or narrowing the public contract until that provenance exists.

Do we have a high-confidence way to reproduce the issue?

Yes. On PR head, read ordinary session messages through current readSessionMessages() semantics, then call collectArtifactsFromMessages() with a runId or taskId; messages without explicit run/task metadata are skipped even though the same artifacts appear for sessionKey.

Is this the best way to solve the issue?

No, not as-is. The RPC direction is maintainable, but the advertised run/task query surface is not backed by persisted transcript provenance, so the safer fix is to add that provenance or defer/narrow those scopes.

Full review comments:

  • [P2] Preserve provenance before filtering scoped artifacts — src/gateway/server-methods/artifacts.ts:226-230
    The new run/task API resolves the owning session and then filters every transcript message by message metadata, but current readSessionMessages() only attaches id/seq and no writer persists run/task provenance. Ordinary artifacts can therefore appear for sessionKey and disappear for advertised runId/taskId queries; please persist/read explicit provenance before filtering, or defer/narrow the scoped contract.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.87

What I checked:

Likely related people:

  • steipete: Git blame for the current SDK artifact placeholder, transcript metadata reader, and task status access files points to commit c5bc4b6, which is the shallow current-main baseline this PR builds on. (role: current-main maintainer; confidence: medium; commits: c5bc4b689264; files: packages/sdk/src/client.ts, src/gateway/session-utils.fs.ts, src/tasks/task-status-access.ts)
  • tmimmanuel: The PR commit list and related feat(gateway): add artifact RPCs #74898 identify tmimmanuel as the original artifact RPC contributor whose work this maintainer hardening PR builds on. (role: source artifact-RPC contributor; confidence: medium; commits: 5cf62c0bea65, ba19dc906360; files: src/gateway/server-methods/artifacts.ts, src/gateway/protocol/schema/artifacts.ts, apps/macos/Sources/OpenClawProtocol/GatewayModels.swift)
  • vincentkoc: The provided timeline shows vincentkoc assigned, and the PR commit list includes their task-access routing change that is central to taskId scope behavior. (role: recent PR-branch maintainer; confidence: medium; commits: ef3d9c140374; files: src/tasks/task-status-access.ts, src/gateway/server-methods/artifacts.ts)

Remaining risk / open question:

  • The open related feat(gateway/sdk): artifact RPCs with cursor pagination, type filter, and provenance fix #75208 proposes a different artifact RPC path with an explicit provenance fix plus pagination/type filtering, so maintainers need to choose the canonical artifact RPC direction before landing overlapping work.
  • The desired product contract for run/task artifact queries remains unsettled: strict provenance needs transcript writer/reader changes, while session-derived fallback would make current transcripts useful but less precise.

Codex review notes: model gpt-5.5, reasoning high; reviewed against e47a7448e90f.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens and completes the SDK-facing Gateway artifact RPC surface by enforcing explicit transcript provenance for artifact queries, improving download-source safety, and wiring the corresponding App SDK helpers/types/docs.

Changes:

  • Adds Gateway RPC handlers for artifacts.list/get/download that project artifacts from session transcript media blocks with safer URL handling.
  • Extends Gateway protocol schemas/types, method discovery, and scope gating for the new artifact RPCs.
  • Wires oc.artifacts.* in @openclaw/sdk, updates docs, and updates generated Swift protocol models.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/gateway/server-methods/artifacts.ts New artifact RPC handlers + transcript artifact collection + download/source normalization/guardrails
src/gateway/server-methods/artifacts.test.ts Adds unit coverage for list/get/download + runId scoping + URL safety behaviors
src/gateway/server-methods.ts Registers artifactsHandlers into core gateway handler map
src/gateway/server-methods-list.ts Adds artifact RPCs to advertised method list
src/gateway/method-scopes.ts Gates artifact RPCs behind operator read scope
src/gateway/protocol/schema/artifacts.ts Introduces protocol schemas for artifact query params and results
src/gateway/protocol/schema.ts Re-exports artifact schema module
src/gateway/protocol/schema/protocol-schemas.ts Registers artifact schemas into the protocol schema registry
src/gateway/protocol/schema/types.ts Adds artifact-related SchemaType<> aliases
src/gateway/protocol/index.ts Adds artifact param validators and exports types/schemas for protocol consumers
packages/sdk/src/types.ts Adds SDK artifact query/result types and extends ArtifactSummary fields
packages/sdk/src/index.ts Re-exports new SDK artifact types
packages/sdk/src/client.ts Implements oc.artifacts.list/get/download() via RPC calls
packages/sdk/src/index.test.ts Adds SDK-level test asserting artifact RPC calls are issued correctly
docs/concepts/openclaw-sdk.md Documents oc.artifacts readiness and usage examples
apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift Updates generated Swift models for new artifact protocol types
apps/macos/Sources/OpenClawProtocol/GatewayModels.swift Updates generated Swift models for new artifact protocol types
CHANGELOG.md Notes Gateway/SDK artifact RPC + helper availability

Comment thread src/gateway/server-methods/artifacts.test.ts
Comment thread src/gateway/server-methods/artifacts.test.ts
Comment thread packages/sdk/src/client.ts Outdated
Comment thread src/gateway/server-methods/artifacts.ts
Comment thread src/gateway/server-methods/artifacts.ts Outdated
@BunsDev
Copy link
Copy Markdown
Member Author

BunsDev commented Apr 30, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

@copilot apply changes based on the comments in this thread

Applied all changes from the review thread in commit 1ac5dec8:

  • artifacts.ts:268-273: resolveQuerySessionKey now uses getTaskById(taskId) to fetch the task from the registry and returns task.requesterSessionKey (falling back to resolveSessionKeyForRun(task.runId)). Also added messageTaskId priority in resolveMessageTaskId.
  • artifacts.ts:157-158: The directBase64 candidate array already correctly excludes data: strings, so non-base64 data URLs in content/data can't produce mode: "bytes" with invalid data.
  • artifacts.test.ts:157: Fixed the broken taskId test — replaced wrong loadSessionEntry("task-1") mock with getTaskById mock + full task shape, fixed labeltitle, switched to messageTaskId field, and added assertions for resolveSessionKeyForRun not called and loadSessionEntry called with the resolved session key.
  • artifacts.test.ts:211: Added a new test "treats non-base64 data URLs in the content field as unsupported downloads" to guard the resolveBlockDownload content-field path.
  • packages/sdk/src/client.ts:765-767: params is now required in list/get/download, with a requireArtifactQueryScope helper that throws a clear local error when no scope key is provided.

tmimmanuel and others added 9 commits April 30, 2026 18:03
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Fix taskId resolution: use getTaskById() from task registry to look up
  requesterSessionKey instead of calling resolveSessionKeyForRun(taskId).
  Falls back to resolveSessionKeyForRun(task.runId) when requesterSessionKey
  is absent. Fixes artifacts.*({ taskId }) failing to find a session when
  the taskId does not equal a sessionId/runId.

- Fix broken taskId test: replace wrong mock (loadSessionEntry with taskId),
  incorrect field names (label → title), and stale messageTaskId sentinel.
  Add getTaskById mock via vi.mock('../../tasks/task-registry.js').

- Add test for non-base64 data: URL in the content field to guard the
  resolveBlockDownload() fix (directBase64 excludes data: strings).

- Make ArtifactsNamespace.list/get/download params required so SDK consumers
  get a compile-time error instead of a runtime INVALID_REQUEST from the
  Gateway when no scope is provided.

Agent-Logs-Url: https://github.com/openclaw/openclaw/sessions/6c0d8f8e-4a4e-4c73-8456-22f289ee0e09

Co-authored-by: BunsDev <68980965+BunsDev@users.noreply.github.com>
@BunsDev BunsDev force-pushed the meow/74898-artifact-rpc-hardening branch from 188a500 to ef3d9c1 Compare April 30, 2026 23:03
@BunsDev BunsDev merged commit a102f4d into main May 1, 2026
102 checks passed
@BunsDev BunsDev deleted the meow/74898-artifact-rpc-hardening branch May 1, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway RPC: add SDK-facing artifacts APIs

5 participants