Skip to content

fix: address critical safety gaps (SR-17, SR-25, SR-31)#27

Merged
avrabe merged 6 commits intomainfrom
fix/critical-safety-gaps
Mar 14, 2026
Merged

fix: address critical safety gaps (SR-17, SR-25, SR-31)#27
avrabe merged 6 commits intomainfrom
fix/critical-safety-gaps

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Mar 14, 2026

Summary

Addresses the three highest-priority gaps from the weighted STPA gap analysis:

  • SR-31 (CRITICAL): Fail-fast detection of multiply-instantiated modules in the merger. Previously, if a component instantiated the same core module twice, the merger silently produced corrupt output. Now returns DuplicateModuleInstantiation error. (GAP-P2-1)

  • SR-25 (HIGH): Resource handle support in P2 component wrapper. Adds ImportResolution enum to classify imports into WASI instances, [export]-prefixed resources, and internal resources. Emits canon resource.drop/new/rep operations with resource type dedup. Resources fixture now passes component validation. (GAP-P2-2)

  • SR-17 (HIGH): String transcoding verification with 36 tests across parser, resolver, adapter, and integration layers. Covers all 3×3 encoding pairs (UTF-8, UTF-16, CompactUTF16), default behavior, and cross-encoding adapter transcoding. (GAP-P2-3)

Also includes updated weighted gap analysis and refreshed traceability matrix.

Test plan

  • 157 unit tests pass (154 existing + 3 new SR-31)
  • 42 integration tests pass (including 8 wit-bindgen runtime fixtures)
  • SR-31: test_duplicate_module_instantiation_rejected, test_single_instantiation_accepted, test_no_instances_accepted
  • SR-17: 36 tests covering encoding parsing, transcoding detection, and cross-encoding adapter generation
  • SR-25: Resources fixture passes component validation (core module + component levels)
  • All pre-commit hooks pass (fmt, clippy, tests)

🤖 Generated with Claude Code

avrabe and others added 6 commits March 14, 2026 16:22
Add weighted-gap-analysis.md cross-referencing BA RFC #46 discussion
with current STPA gaps. Update traceability matrix to reflect actual
test coverage (195 tests, 14 fixtures). Add SR-31 (multiply-instantiated
module detection), LS-M-5, GAP-7, GAP-8. Mark GAP-4 resolved.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add support for resource-related imports in the P2 component wrapper,
enabling the resources wit-bindgen fixture to pass component validation.

The fused core module can have three categories of resource imports:
- [export]-prefixed modules (e.g., [export]imports, [export]exports)
  with [resource-drop], [resource-new], and [resource-rep] operations
  for locally-defined component resources
- Non-WASI modules with unresolvable [resource-drop] fields for
  internal inter-component resource lifecycle
- WASI instance resource drops (already handled)

For local resources, the wrapper now:
1. Aliases the destructor function from the fused module exports
2. Defines a component-level resource type with that destructor
3. Generates canon resource.drop/new/rep core functions
4. Caches resource types so each unique (interface, resource) pair
   gets exactly one type definition

Key changes:
- ImportResolution enum replaces flat (u32, String) tuples
- parse_resource_field() extracts operation and name from field names
- has_non_resource_op check updated to exclude resource-new/rep
- Tests upgraded from graceful degradation to hard assertions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
36 tests across parser, resolver, adapter, and integration:
- Parser: CanonStringEncoding parsing, default/override behavior (11 tests)
- Adapter: canon_to_string_encoding, alignment, needs_transcoding (10 tests)
- Resolver: string_transcoding flag, 3×3 encoding matrix (14 tests)
- Integration: UTF-8 caller ↔ UTF-16 callee adapter transcoding (1 test)

Closes SR-17 verification gap identified in weighted gap analysis.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add check_no_duplicate_instantiations() to merger that detects when
the same core module is instantiated more than once within a component.
Returns DuplicateModuleInstantiation error instead of silently producing
corrupt output. Called at the start of Merger::merge().

Addresses critical gap GAP-P2-1 from weighted gap analysis (LS-M-5).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…upport

Bump wasmparser/wasm-encoder/wasmprinter to 0.230 to gain support for
the 0x67 (FixedSizeList) component type encoding contributed by Christof
Petig. API migration:

- ComponentFuncType.results → .result (single result type)
- F32Const/F64Const now take Ieee32/Ieee64 instead of raw floats
- New ComponentDefinedType variants: FixedSizeList, Future, Stream
- New PrimitiveValType::ErrorContext, CanonicalOption::Async/Callback
- ThreadSpawn → ThreadSpawnRef

FixedSizeList(element_type, length) is an inline fixed-length array:
- align = element align, size = element stride * length
- No heap pointers (unlike variable-length List which is ptr+len)
- Handled in all canonical ABI functions (size, align, flat count,
  pointer positions, conditional pointers, return area slots)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add rivet.yaml with stpa + aspice + dev schemas, cross-repo links
  to kiln and synth
- Convert safety-requirements.yaml to generic-yaml format (artifacts
  with type, links, fields)
- Fix hazards.yaml: move H-8/H-9/H-10 from sub-hazards to hazards
  section (they're top-level hazards, not refinements)
- Add hazards field to all 19 loss scenarios for Rivet traceability
- Generate .rivet/agent-context.md

Rivet validates: 213 artifacts, 88.7% coverage, 0 errors.
STPA traceability is 100% for all rules (hazard→loss, constraint→hazard,
UCA→hazard, UCA→controller, controller-constraint→UCA).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@avrabe avrabe merged commit 6cf75f9 into main Mar 14, 2026
3 checks passed
@avrabe avrabe deleted the fix/critical-safety-gaps branch March 14, 2026 20:21
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.

1 participant