Repository navigation
feat(wasm): typed WIT tool response and bundled guest migration - #7703
henrypark133 wants to merge 8 commits into
Conversation
|
🚅 Deployed to the ironclaw-pr-7703 environment in ironclaw-ci-preview
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (2)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b74758abb
ℹ️ 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".
| RawSlackFailure::Transport(raw) if raw == "AuthRequired" => { | ||
| structured_error(&raw, ErrorKind::AuthRequired) | ||
| } | ||
| RawSlackFailure::Transport(raw) => structured_error(&raw, ErrorKind::OperationFailed), |
There was a problem hiding this comment.
Preserve host transport failure kinds
When the Slack host import returns host_http_network_denied, host_http_body_limit, host_http_timeout, or host_http_rate_limited, this arm now labels every value OperationFailed. Before the migration, the raw literal reached wasm_guest_error_kind and mapped respectively to NetworkDenied, OutputTooLarge, Executor, or Client; typed_wasm_guest_dispatch_error instead trusts the declared enum, so migrated guests lose the actionable failure class and downstream remediation. Map these known literals to their corresponding ErrorKind; the same regression appears in the transport_failure helpers for all four migrated Google guests.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Investigated and the premise does not hold. The strings named here (host_http_network_denied, host_http_timeout, …) are matched only inside the host's legacy string table in wasm_execution.rs; no production code anywhere constructs them — they are unreachable dead arms both before and after this migration. What a guest's host::http_request Err actually contains is credential_unavailable, request_denied, policy_denied, network_error, response_error, response_body_limit_exceeded (see ironclaw_wasm/src/host.rs::wasm_http_error + ironclaw_host_api/src/http.rs::stable_runtime_reason). Slack and the four Google packages collapsed all of those into a generic kind before this PR too — verified against git show 169a64d6d:.../api.rs. GitHub is the one package with granular transport kinds and its classification is a byte-for-byte port. So: no fidelity lost. Separately, you're pointing at something real — those five packages should classify transport reasons — but the fix is central (the host classifying its own generated reasons), not five more per-package tables. Tracked as follow-up, deliberately not smuggled into this PR.
| @@ -1,4 +1,4 @@ | |||
| package near:agent@0.3.0; | |||
| package near:agent@0.4.0; | |||
There was a problem hiding this comment.
Update the canonical WASM contract with the ABI bump
Changing the canonical package to 0.4.0 leaves docs/internal/reborn/contracts/wasm.md still requiring the 0.3.0 world, imports, and exports, while this crate's README and AGENTS guidance also identify tool.wit as 0.3.0. External guest authors following the contract will therefore keep producing legacy components; the fallback masks that mismatch only until its announced removal, after which the documented components stop loading. Update the owning contract and orientation files in this ABI-changing commit.
AGENTS.md reference: AGENTS.md:L160-L160
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed — crates/lanes/ironclaw_wasm/AGENTS.md, README.md, and docs/internal/reborn/contracts/wasm.md now document the near:agent@0.4.0 typed response and note the 0.3.0 fallback's removal.
henrypark133
left a comment
There was a problem hiding this comment.
Code Review (multi-agent)
Intent: Replace the WASM tool response stringly error channel with a typed WIT 0.4.0 variant, migrate all six bundled guests, keep a legacy 0.3.0 fallback until PR 4.
Stats: 10 findings (from 10 raw, 10 after dedup) across 8 files. Reviewers run: security, bugs, performance, tests, conventions, local-patterns, maintainability, approach. Reviewers failed: none. Body-only: 1
Security, performance, and approach returned zero findings; security specifically investigated the 401 thread-local capture, scrub boundedness, and non-401 restriction without confirming an issue.
Local Patterns
- Medium GitHub 401 message skips the sibling
bounded_message()convention (github/wasm-src/src/request.rs:31-40, confidence 85) (no diff position — body only) — every other package bounds guest messages to 512 chars before they leave the sandbox; the new thread-local capture stores the raw provider message unbounded.
Bugs
- Medium
instantiate_currentfailure always retried as legacy (ironclaw_wasm/src/runtime.rs:241-275, confidence 55) — candidate — validate claim. Non-version failures pay a second instantiation, the legacy error is discarded on double failure, and a component satisfying both worlds silently pins Legacy.
Maintainability
- Medium Typed guest-code sanitization duplicates the legacy decoder trio (
wasm_execution.rs:368-407, confidence 65) — the typed helpers are the permanent path, so this duplication survives the PR 4 legacy removal; extract shared helpers over (code, message, retry_after).
Conventions
- Medium
LEGACY_WIT_TOOL_VERSIONexported publicly with no downstream consumer (ironclaw_wasm/src/config.rs:7-14, confidence 65) — repo rule: no pub re-exports without consumers.
Tests
- Medium google-sheets 401→AuthRequired classification untested (
google-sheets/wasm-src/src/api.rs:101, confidence 85) - Medium google-slides 401→AuthRequired classification untested (
google-slides/wasm-src/src/api.rs:101, confidence 85) - Low sheets
format_cellsno_formatting_options path untested (confidence 75) - Low slides
format_textno_formatting_options path untested (confidence 75) - Low sheets
params_with_actioncaller-supplied-action guard untested (confidence 75) - Low slides
params_with_actioncaller-supplied-action guard untested (confidence 75)
| ) -> Result<WitToolExecution, WasmError> { | ||
| let started = Instant::now(); | ||
| let (mut store, instance) = | ||
| self.instantiate_current(&prepared.component, host, &prepared.limits)?; |
There was a problem hiding this comment.
Medium — instantiate_current failure always retried as legacy, masking non-version causes.
Candidate - validate claim: any current-world instantiation error unconditionally retries the legacy world; non-version failures pay a second instantiation, the legacy error is discarded on double failure, and a component satisfying both worlds silently pins to Legacy for its lifetime.
Fix: Gate the legacy retry on a version/import-mismatch signature in the current-world error; preserve the legacy error diagnostic.
There was a problem hiding this comment.
Fixed — the legacy retry is now gated on a version/import-mismatch signature in the current-world error, so a non-version instantiation failure returns immediately instead of silently degrading to the legacy path, and a double failure keeps both error messages instead of discarding the legacy one. Three unit tests pin the gate.
| &format!("{failure:?}"), | ||
| ); | ||
| guard.account_failed(Some(&execution.usage), wasm_resource_error)?; | ||
| return Err(typed_wasm_guest_dispatch_error( |
There was a problem hiding this comment.
Medium — Typed guest-code sanitization duplicates the legacy decoder trio.
sanitized_wasm_guest_code / typed_wasm_guest_cause / typed_wasm_guest_provider_diagnostic are near-byte copies of the legacy helpers in the same file; the typed trio is the permanent path so the duplication does not die with the PR-4 legacy removal.
Fix: Extract shared helpers over (code, message, retry_after) and have both typed and legacy call sites use them.
There was a problem hiding this comment.
Fixed — extracted shared provider_error_cause/provider_error_diagnostic helpers over (code, message, retry_after); the typed and legacy paths both delegate rather than each owning a copy. The legacy side keeps its stricter no-code-no-cause behavior via an explicit guard.
| } | ||
|
|
||
| fn api_status_error(service: &str, status: u16, body: &[u8]) -> String { | ||
| fn api_status_error(service: &str, status: u16, body: &[u8]) -> GuestFailure { |
There was a problem hiding this comment.
Medium — google-sheets 401→AuthRequired classification has no unit test.
New typed status-classification (401→AuthRequired, else Client) shipped with zero test modules in this package.
Fix: Add api_status_error tests for the 401 and non-401 branches.
There was a problem hiding this comment.
Fixed — api_status_error 401→AuthRequired and non-401→Client tests added to google-sheets.
| } | ||
|
|
||
| fn api_status_error(service: &str, status: u16, body: &[u8]) -> String { | ||
| fn api_status_error(service: &str, status: u16, body: &[u8]) -> GuestFailure { |
There was a problem hiding this comment.
Medium — google-slides 401→AuthRequired classification has no unit test.
Same gap as google-sheets: no #[cfg(test)] anywhere in the package despite new typed error paths.
Fix: Add api_status_error tests for the 401 and non-401 branches.
There was a problem hiding this comment.
Fixed — same tests added to google-slides.
| pub const WIT_TOOL_VERSION: &str = "0.3.0"; | ||
| /// | ||
| /// The runtime also accepts components compiled against the frozen legacy | ||
| /// [`LEGACY_WIT_TOOL_VERSION`] world through a binding-level fallback |
There was a problem hiding this comment.
Medium — LEGACY_WIT_TOOL_VERSION exported publicly with no downstream consumer.
pub const re-exported at crate root with zero consumers outside a doc comment; sibling LEGACY_TOOL_WIT is genuinely consumed, this one is not. Repo rule: no pub re-exports without downstream consumers.
Fix: Drop the pub re-export; keep pub(crate) until a consumer exists.
There was a problem hiding this comment.
Fixed by deletion — it was genuinely unused (dead even at pub(crate)), so the constant and its re-export are gone rather than downgraded.
|
|
||
| /// Format cells in a range. | ||
| pub fn format_cells(opts: FormatOptions<'_>) -> Result<FormatResult, String> { | ||
| pub fn format_cells(opts: FormatOptions<'_>) -> Result<FormatResult, GuestFailure> { |
There was a problem hiding this comment.
Low — format_cells no_formatting_options path untested.
Empty-fields early-return uncovered.
Fix: Add format_cells_rejects_when_no_formatting_options_specified.
There was a problem hiding this comment.
Fixed — format_cells_rejects_no_formatting_options added.
|
|
||
| /// Format text in a shape. | ||
| pub fn format_text(opts: FormatTextOptions<'_>) -> Result<UpdateResult, String> { | ||
| pub fn format_text(opts: FormatTextOptions<'_>) -> Result<UpdateResult, GuestFailure> { |
There was a problem hiding this comment.
Low — format_text no_formatting_options path untested.
Empty-fields early-return uncovered.
Fix: Add format_text_rejects_when_no_formatting_options_specified.
There was a problem hiding this comment.
Fixed — format_text_rejects_no_formatting_options added.
| } | ||
|
|
||
| fn params_with_action(params: &str, action: &str) -> Result<serde_json::Value, String> { | ||
| fn params_with_action(params: &str, action: &str) -> Result<serde_json::Value, GuestFailure> { |
There was a problem hiding this comment.
Low — params_with_action caller-supplied-action guard untested (sheets).
google-docs regression-tests this exact guard; sheets defines it untested.
Fix: Add params_with_action_rejects_caller_supplied_action.
There was a problem hiding this comment.
Fixed — params_with_action_rejects_caller_supplied_action added to google-sheets, mirroring google-docs.
| } | ||
|
|
||
| fn params_with_action(params: &str, action: &str) -> Result<serde_json::Value, String> { | ||
| fn params_with_action(params: &str, action: &str) -> Result<serde_json::Value, GuestFailure> { |
There was a problem hiding this comment.
Low — params_with_action caller-supplied-action guard untested (slides).
Same guard/gap as sheets.
Fix: Add params_with_action_rejects_caller_supplied_action.
There was a problem hiding this comment.
Fixed — same test added to google-slides.
|
All 10 review findings addressed in 9d9ba94: github 401 message bounded to the sibling 512-char convention (artifact rebuilt, digest updated); legacy-world retry now gated on a version/import-mismatch signature with both errors preserved on double failure (+3 gate tests); typed/legacy provider decode helpers deduplicated; unused LEGACY_WIT_TOOL_VERSION export deleted; sheets/slides gained the missing classification and guard tests. Full gate re-run green (wasm contract 66/66, services contract 120/120 incl. legacy fallback, auth-gate 18/18, architecture suite, freshness OK). |
|
@ironloopai review |
🧭 IronLoop Run · ReviewThis comment updates in place as the Run moves through its stages. 🟩 Final result · Completed
Manual command by hanakannzashi · attempt 1 of 3 · completed in 1m 22s IronLoop completed the review and posted it to GitHub. 🔗 Result |
There was a problem hiding this comment.
🔍 IronLoop review
🟢 No actionable findings
No additional findings beyond the materially equivalent issues already present in captured review threads. The typed ABI, legacy fallback, host normalization, and bundled guest migrations were inspected across the complete change.
Validation
- ✅ WASM artifact freshness — All six committed WASM artifacts match their source digests.
Review details
- Run:
fcd4b968-e524-480b-9a11-2fffc56f3f98 - Workflow: Review
- Attempts: 1
9d9ba94 to
c124793
Compare
henrypark133
left a comment
There was a problem hiding this comment.
Note: This review would normally be REQUEST_CHANGES (1 High-confidence finding: f-tests-3, high-severity missing error-path test) — submitted as COMMENT because GitHub disallows REQUEST_CHANGES on your own PR.
Code Review (multi-agent)
Intent: Replace the WASM tool contract's stringly-typed error channel with a typed WIT response variant and migrate all six bundled guest packages to it.
Stats: 10 findings (from 11 raw, 10 after dedup) across 7 files. Reviewers run: security, bugs, performance, tests, conventions, local-patterns, maintainability, approach. Reviewers failed: none. Body-only: 2
Tests
- Medium New api_status_error classifier untested in google-docs (unlike sheets/slides) (
crates/extensions/packages/google-docs/wasm-src/src/api.rs:101-121, confidence 75) — anchor: crates/extensions/packages/google-docs/wasm-src/src/api.rs:101
api_status_error is new in this PR and drives the closed error-kind classification for every non-transport Google Docs API failure: 401 -> AuthRequired with no message, non-401 -> Client with code api_status_{status} and a bounded message. Sibling packages google-sheets and google-slides both added direct unit tests for this exact function, but google-docs/api.rs has no equivalent test.
Also flagged by: security/Medium — Google guests embed raw provider response body into model-visible failure for al - Medium New api_status_error classifier untested in google-drive (unlike sheets/slides) (
crates/extensions/packages/google-drive/wasm-src/src/api.rs:112-132, confidence 75) — anchor: crates/extensions/packages/google-drive/wasm-src/src/api.rs:112
Same new classification function as google-docs, also missing a direct unit test here, while google-sheets and google-slides both cover it explicitly. - High 401 provider-message capture never tested with a malformed/non-JSON body (
crates/extensions/packages/github/wasm-src/src/request.rs:39-46, confidence 75) (no diff position — body only) — anchor: crates/extensions/packages/github/wasm-src/src/request.rs:39
set_last_error_message parses the 401 response body as JSON and silently falls back to None (via .ok()) if the body is not valid JSON or has no string message field. This fallback branch is never exercised: the only end-to-end test of the 401 message-capture path always sends a well-formed {"message":"Bad credentials"} body. Because set_last_error_message is #[cfg(not(test))], it can only be exercised through a compiled-artifact integration test, and this parse-failure branch has no coverage anywhere in the diff. - Medium 512-char message truncation boundary for the 401 provider-message capture is untested (
crates/extensions/packages/github/wasm-src/src/request.rs:26-31, confidence 60) (candidate — validate claim) (no diff position — body only) — anchor: crates/extensions/packages/github/wasm-src/src/request.rs:26
bounded_message truncates the captured 401 provider message to 512 chars via .chars().take(512) before it crosses the sandbox boundary. No test sends an oversized 401 body to verify the truncation actually happens at the guest-failure message field. - Medium Sandbox-exit scrub of the new 401 guest-failure message field is untested against credential-shaped text (
crates/kernel/ironclaw_host_runtime/tests/github_wasm_runtime_contract.rs:1812-1873, confidence 70) (candidate — validate claim) — anchor: crates/extensions/packages/github/wasm-src/src/request.rs:39
bundled_github_wasm_sanitizes_host_http_and_api_failures verifies credential material is scrubbed for a 403 response body, but message capture only fires on status 401, so this 403 case never exercises the new capture+scrub path. The PR body claims the sandbox-exit secret scrub applies to the typed failure's free-text fields, but no case sends a 401 body containing credential-shaped text to prove the leak detector actually redacts the newly-added message field. - Medium No crate-tier WAT fixture exercises WitToolOutcome::Failure/guest-failure (
crates/lanes/ironclaw_wasm/tests/wit_tool_runtime_contract.rs:1-300, confidence 75) — anchor: crates/lanes/ironclaw_wasm/tests/wit_tool_runtime_contract.rs:16
Both hand-encoded WAT fixtures in this file were re-derived for the 0.4.0 canonical-ABI layout but only ever encode the success(string) variant of the new response shape — there is no fixture encoding the failure(guest-failure) variant with its kind/code/message/retry_after_ms fields. Typed-failure coverage exists only at the higher integration tiers against real compiled artifacts, so a WIT/bindgen-level regression in the failure variant's canonical-ABI field layout could go undetected at the crate/unit tier. - Low Combined current+legacy instantiation failure branch in extract_metadata is untested (
crates/lanes/ironclaw_wasm/src/runtime.rs:259-267, confidence 60) (candidate — validate claim) — anchor: crates/lanes/ironclaw_wasm/src/runtime.rs:259
When current-world instantiation fails with a version-mismatch signature and the legacy-world retry also fails, extract_metadata returns a combined WasmError::InstantiationFailed with both error messages concatenated. No test drives a component that fails both instantiation attempts to verify this combined error path.
Conventions
- Medium WIT ABI version bump to 0.4.0 leaves crate AGENTS.md/README stale at 0.3.0 (
crates/lanes/ironclaw_wasm/src/config.rs:7-10, confidence 75) — anchor: AGENTS.md: "Update the owning contract/docs when behavior changes" (Change discipline); crates/lanes/ironclaw_wasm/AGENTS.md:16 and README.md:35
The diff bumps WIT_TOOL_VERSION to "0.4.0" and wit/tool.wit's package line to near:agent@0.4.0, but does not update crates/lanes/ironclaw_wasm/AGENTS.md:16 or crates/lanes/ironclaw_wasm/README.md:35, both of which still document wit/tool.wit as near:agent@0.3.0. AGENTS.md explicitly frames this crate as the ABI's owner. Root AGENTS.md (Change discipline) requires updating owning contract/docs when behavior changes; the version-bump CI script only cross-checks WIT_TOOL_VERSION against the .wit file, not against AGENTS.md/README.md prose.
Local Patterns
- Low UTF-8 decode failure inlined instead of factored like sibling google-drive helper (
crates/extensions/packages/google-docs/wasm-src/src/api.rs:93-98, confidence 75) — anchor: crates/extensions/packages/google-drive/wasm-src/src/api.rs:55-62
google-docs/api.rs, google-sheets/api.rs, and google-slides/api.rs each construct the invalid_utf8_response GuestFailure inline inside api_call's map_err closure. The sibling google-drive/api.rs, migrated in this same PR with near-identical boilerplate, factors the identical construction into a named utf8_decode_failure helper (google-drive/wasm-src/src/api.rs:55-62). All four files were freshly rewritten in this diff for the same typed-response migration, so this is a genuine new inconsistency. - Low insert_text's negative-index error bypasses the file's own input_failure helper (
crates/extensions/packages/google-docs/wasm-src/src/api.rs:281-289, confidence 65) (candidate — validate claim) — anchor: crates/extensions/packages/google-docs/wasm-src/src/api.rs:48-55
google-docs/api.rs defines input_failure(code, message) specifically to build ErrorKind::Input guest-failures with the message passed through bounded_message, and every other local-validation error in the file goes through it. insert_text's negative-index rejection instead constructs the GuestFailure literal by hand and skips bounded_message entirely, breaking the file's established convention.
| pub const WIT_TOOL_VERSION: &str = "0.3.0"; | ||
| /// | ||
| /// The runtime also accepts components compiled against the frozen legacy | ||
| /// world (`0.3.0`, `wit/legacy/tool_v0_3_0.wit`) through a binding-level |
There was a problem hiding this comment.
Medium — WIT ABI version bump to 0.4.0 leaves crate AGENTS.md/README stale at 0.3.0.
The diff bumps WIT_TOOL_VERSION to "0.4.0" and wit/tool.wit's package line to near:agent@0.4.0, but does not update crates/lanes/ironclaw_wasm/AGENTS.md:16 or crates/lanes/ironclaw_wasm/README.md:35, both of which still document wit/tool.wit as near:agent@0.3.0. AGENTS.md explicitly frames this crate as the ABI's owner. Root AGENTS.md (Change discipline) requires updating owning contract/docs when behavior changes; the version-bump CI script only cross-checks WIT_TOOL_VERSION against the .wit file, not against AGENTS.md/README.md prose.
Fix: Update the near:agent@0.3.0 references in crates/lanes/ironclaw_wasm/AGENTS.md:16 and crates/lanes/ironclaw_wasm/README.md:35 to near:agent@0.4.0 in this PR.
There was a problem hiding this comment.
Fixed — AGENTS.md, README.md, and the contracts doc are updated for 0.4.0 and the typed response shape.
|
|
||
| if response.status < 200 || response.status >= 300 { | ||
| return Err(api_status_error("Google Docs", response.status, &response.body)); | ||
| return Err(api_status_error( |
There was a problem hiding this comment.
Medium — New api_status_error classifier untested in google-docs (unlike sheets/slides).
api_status_error is new in this PR and drives the closed error-kind classification for every non-transport Google Docs API failure: 401 -> AuthRequired with no message, non-401 -> Client with code api_status_{status} and a bounded message. Sibling packages google-sheets and google-slides both added direct unit tests for this exact function, but google-docs/api.rs has no equivalent test.
Fix: Add api_status_error_401_maps_to_auth_required and api_status_error_non_401_maps_to_client unit tests to google-docs/api.rs mirroring the ones already present in google-sheets/google-slides.
Also flagged by: security/Medium
There was a problem hiding this comment.
Fixed — api_status_error classification tests added to google-docs.
| } | ||
|
|
||
| fn api_status_error(service: &str, status: u16, body: &[u8]) -> String { | ||
| fn api_status_error(service: &str, status: u16, body: &[u8]) -> GuestFailure { |
There was a problem hiding this comment.
Medium — New api_status_error classifier untested in google-drive (unlike sheets/slides).
Same new classification function as google-docs, also missing a direct unit test here, while google-sheets and google-slides both cover it explicitly.
Fix: Add api_status_error_401_maps_to_auth_required and api_status_error_non_401_maps_to_client unit tests to google-drive/api.rs.
There was a problem hiding this comment.
Fixed — same for google-drive.
| i32.store | ||
| i32.const 32) | ||
| ;; Encode `response` as the `success(string)` case of the near:agent@0.4.0 | ||
| ;; typed variant (see wasm_execution.rs SIMPLE_TOOL_WAT for the layout note). |
There was a problem hiding this comment.
Medium — No crate-tier WAT fixture exercises WitToolOutcome::Failure/guest-failure.
Both hand-encoded WAT fixtures in this file were re-derived for the 0.4.0 canonical-ABI layout but only ever encode the success(string) variant of the new response shape — there is no fixture encoding the failure(guest-failure) variant with its kind/code/message/retry_after_ms fields. Typed-failure coverage exists only at the higher integration tiers against real compiled artifacts, so a WIT/bindgen-level regression in the failure variant's canonical-ABI field layout could go undetected at the crate/unit tier.
Fix: Add a hand-encoded WAT fixture whose $execute exports the failure(guest-failure) discriminant with a populated kind/code/message/retry_after_ms, asserting WitToolOutcome::Failure(WitGuestFailure { .. }) with the expected field values.
There was a problem hiding this comment.
Fixed — added a FAILURE_TOOL_WAT fixture that encodes the failure case of the response variant, so a real component-model decode of WitToolOutcome::Failure is now exercised rather than only the success path.
| use ironclaw_wasm::{ | ||
| PreparedWitTool, RecordingWasmHostHttp, WasmHostError, WasmHttpResponse, WitToolExecution, | ||
| WitToolHost, WitToolRequest, WitToolRuntime, WitToolRuntimeConfig, | ||
| PreparedWitTool, RecordingWasmHostHttp, WasmHostError, WasmHttpResponse, WitGuestFailure, |
There was a problem hiding this comment.
Medium — Sandbox-exit scrub of the new 401 guest-failure message field is untested against credential-shaped text.
bundled_github_wasm_sanitizes_host_http_and_api_failures verifies credential material is scrubbed for a 403 response body, but message capture only fires on status 401, so this 403 case never exercises the new capture+scrub path. The PR body claims the sandbox-exit secret scrub applies to the typed failure's free-text fields, but no case sends a 401 body containing credential-shaped text to prove the leak detector actually redacts the newly-added message field.
Fix: Add a case sending a 401 response with body {"message":"bad credentials ghp_fake_fixture_token"}, asserting the resulting WitGuestFailure.message does not contain the raw token.
There was a problem hiding this comment.
Fixed, and it turned up a real gap. Added a regression pinning that a credential-shaped token embedded in a provider 401 message is scrubbed before reaching the guest-visible failure — which exposed that LeakDetector's github_token pattern required 36 trailing characters, letting shorter credential-shaped values through. The floor is now 16 (fail-closed for a prefix that can't be anything but a token), with its own regression test in ironclaw_safety.
| message.chars().take(MAX_MESSAGE_CHARS).collect() | ||
| } | ||
|
|
||
| /// A guest-side JSON encode/decode of an already-well-formed payload failed |
There was a problem hiding this comment.
Low — UTF-8 decode failure inlined instead of factored like sibling google-drive helper.
google-docs/api.rs, google-sheets/api.rs, and google-slides/api.rs each construct the invalid_utf8_response GuestFailure inline inside api_call's map_err closure. The sibling google-drive/api.rs, migrated in this same PR with near-identical boilerplate, factors the identical construction into a named utf8_decode_failure helper (google-drive/wasm-src/src/api.rs:55-62). All four files were freshly rewritten in this diff for the same typed-response migration, so this is a genuine new inconsistency.
Fix: Factor the UTF-8 decode failure into a named utf8_decode_failure(error: &std::string::FromUtf8Error) -> GuestFailure helper in google-docs/api.rs, google-sheets/api.rs, and google-slides/api.rs, mirroring google-drive/api.rs:55-62.
There was a problem hiding this comment.
Fixed — the UTF-8 decode-failure construction is factored the same way across google-docs/sheets/slides as it already was in google-drive.
| //! credential injection and rate limiting. The WASM tool never sees | ||
| //! the actual OAuth token. | ||
|
|
||
| use crate::exports::near::agent::tool::{ErrorKind, GuestFailure}; |
There was a problem hiding this comment.
Low — insert_text's negative-index error bypasses the file's own input_failure helper.
google-docs/api.rs defines input_failure(code, message) specifically to build ErrorKind::Input guest-failures with the message passed through bounded_message, and every other local-validation error in the file goes through it. insert_text's negative-index rejection instead constructs the GuestFailure literal by hand and skips bounded_message entirely, breaking the file's established convention.
Fix: Replace the manual GuestFailure { .. } literal at api.rs:281-289 with input_failure("invalid_index", format!("invalid index {index}: only -1 (append) or non-negative indexes are accepted")), matching the other input_failure call sites in the same file.
There was a problem hiding this comment.
Fixed — the negative-index error now routes through the file's own input_failure helper.
| Ok((description, schema, WitBindingVersion::Current)) | ||
| } | ||
| // Legacy fallback — removed in PR 4. A component compiled against | ||
| // the frozen 0.3.0 world fails the current-world instantiation on |
There was a problem hiding this comment.
Low — Combined current+legacy instantiation failure branch in extract_metadata is untested.
When current-world instantiation fails with a version-mismatch signature and the legacy-world retry also fails, extract_metadata returns a combined WasmError::InstantiationFailed with both error messages concatenated. No test drives a component that fails both instantiation attempts to verify this combined error path.
Fix: Add a test with a component whose imports name near:agent but do not satisfy either the current or legacy world, asserting the resulting WasmError::InstantiationFailed message contains both failure fragments.
There was a problem hiding this comment.
Fixed — a test now pins that when the version-mismatch retry also fails, both the current-world and legacy-world error messages survive in the returned error.
169a64d to
7fd29bc
Compare
Replace the option<string>/option<string> response record with a typed success/failure variant (near:agent@0.4.0): failure carries a closed error kind plus bounded optional code/message/retry-after. Hosts keep a legacy 0.3.0 binding fallback through the existing string decode until PR 4 removes it. The sandbox-exit secret scrub now applies to the typed failure's free-text fields. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
All six wasm-src packages emit the typed success/failure variant instead of JSON-in-string error envelopes; plain-string Google error paths are now classified into the closed error-kind vocabulary with bounded messages. Artifacts rebuilt from source; digests updated via the freshness script. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Stage-1 gap: the services-contract harness still emitted 0.3.0 imports. Fixtures now target the typed response layout; one deliberately-legacy fixture pins the 0.3.0 fallback until PR 4 removes it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…onse The typed-response migration left the GitHub guest's 401 path hardcoding `message: None` on the `guest-failure` (crates/extensions/packages/github/wasm-src/src/lib.rs) while the provider's response body (e.g. "Bad credentials") was discarded in `github_request` (request.rs). Capture the body's `message` field for the 401 case specifically and thread it onto the typed failure so both the bounded provider message and the stable code reach the auth-gate diagnostic and eventual model context. Scoped to 401 only, not every non-2xx status, to avoid widening what a guest-authored response body can put in front of the model. Also keeps lane doc comments vendor-neutral. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…dedupe decoders Bound the github guest's captured 401 provider message to the sibling 512-char convention and rebuild the artifact; retry the legacy world only on a version/import mismatch and keep both errors on double failure; share one provider code/message decode helper between the typed and legacy paths; drop the unconsumed legacy-version re-export; add sheets/slides unit tests for the new typed classification and guards. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Dedupe the Google Docs UTF-8 decode-failure builder and route the negative-index error through the shared input_failure() helper. - Add 401->auth-required / non-401->client coverage for Docs and Drive api_status_error, and a GitHub-specific regression pinning that a credential-shaped token in a 401 provider message is scrubbed before it reaches the guest-visible failure. - Add a real component-model regression that decodes the WitToolOutcome::Failure variant (prior fixtures only ever exercised Success), and one pinning that a double current+legacy world instantiation failure preserves both underlying error messages instead of dropping the first. - Update the wasm crate's AGENTS.md/README and docs/internal/reborn/contracts/wasm.md for the near:agent@0.4.0 typed response ABI and the legacy 0.3.0 fallback removed in PR 4.
The github_token pattern required 36 trailing characters, so a shorter credential-shaped value passed through unredacted — the gap that led the GitHub guest to capture provider messages only on 401. Lower the floor to 16 (fail-closed for a prefix that cannot be anything but a token) and raise the guest-message bound from 256 to 2048 bytes so real provider explanations survive to the model instead of being clipped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…igration The stringly and typed capture paths both survived the rebase, so the guest returned a pre-built envelope that was then wrapped again. Keep the typed thread-local path, drop the superseded pre-built envelope, and rebuild the artifact. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
c124793 to
6f873ef
Compare
|
Closing in favor of #7711, which now contains this work. Rationale: this PR introduced a 0.3.0 legacy-compatibility shim that #7711 deletes. Keeping them as separate PRs would ship an add-then-remove churn for a shim that never protected a released component — both were unmerged the whole time. Combined into one PR, the net diff simply has no shim, which is an honest representation of what actually changes. Every review comment here was addressed and answered on the thread before closing; those commits all ride along in #7711 (they are the same commits, rebased). Nothing is dropped. |
Summary
PR 3 of the capability-response-normalization plan (#7627), stacked on #7692. Replaces the WASM tool contract's stringly error channel —
record response { output: option<string>, error: option<string> }, with guests smuggling JSON envelopes through the error string and the host reparsing them — with a typed shape innear:agent@0.4.0:variant response { success(string), failure(guest-failure) } record guest-failure { kind: error-kind, code: option<string>, message: option<string>, retry-after-ms: option<u64> } enum error-kind { auth-required, input, output-too-large, executor, network-denied, client, operation-failed }Per commit:
wit/legacy/tool_v0_3_0.wit; dualbindgen!bindings with instantiate-current-then-legacy fallback (resolved once per prepared component, not per call); the sandbox-exit secret scrub now applies to the typed failure's free-text fields; host maps typed failures 1:1 onto the existingDispatchErrorvocabulary — no new taxonomy. Hand-encoded WAT test fixtures re-derived for the new canonical-ABI layout.Design decisions (plan §15): typed WIT immediately, no interim envelope (all guests are first-party and rebuilt in this PR — one migration instead of two); no shared guest SDK — typed bindings delete the JSON-envelope duplication on their own, and a shared crate outside
wasm-src/would silently escape the freshness digest.Test Strategy
reborn_integration_auth_gate18/18 — including the provider-401-context flagship test, now driven end-to-end through the rebuilt typed artifact.github_wasm_runtime_contract66/66 against the rebuilt artifact (credential-leak sanitization test unweakened);ironclaw_wasm51/51 including re-derived WAT fixtures;host_runtime_services_contract120/120 including the pinned legacy-fallback test; guest-side native tests green across all six packages;ironclaw_architecture_testsgreen (extension-specificity gate included). Known-unrelated: 2trace_commonsnetwork-egress failures (reproduce on clean main).Clippy
-D warningsclean on all touched crates (guest crates included); fmt clean;check-wasm-artifact-freshness.pyOK (6 packages).Compatibility / rollback
Old 0.3.0 components still run through the frozen legacy bindings + string decode (removal is PR 4, after this ships a release). All six committed artifacts move to 0.4.0 in this PR and match their sources by digest. Revert restores the 0.3.0-only world cleanly; PR 1/2 stand alone.
🤖 Generated with Claude Code