Skip to content

fix(kilnd,component): reject arg-arity mismatch instead of zero-filling + reporting wrong result as success (SR-53, closes #443) - #460

Merged
avrabe merged 1 commit into
mainfrom
fix/sr-53-arg-arity-fabricated-success-443
Jul 21, 2026
Merged

fix(kilnd,component): reject arg-arity mismatch instead of zero-filling + reporting wrong result as success (SR-53, closes #443)#460
avrabe merged 1 commit into
mainfrom
fix/sr-53-arg-arity-fabricated-success-443

Conversation

@avrabe

@avrabe avrabe commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

The bug (#443, #412 fabricated-reporting family)

kilnd invoked a param-taking export with zero-filled arguments when params couldn't be supplied and reported the wrong value as SUCCESS:

kilnd mod.wasm --function addone   →  ✓ returned I32(1)  (exit 0)   # addone(0), zero-filled
wasmtime run --invoke addone mod.wasm 5  →  6                        # correct

Second manifestation: a spec-invalid component whose canon lift declares a different param arity than its backing core function was ACCEPTED and run, though wasm-tools validate and wasmtime reject it. Only result arity was ever checked.

The fix (fail-loud on every surface)

  • kiln-runtime stackless engine (execute_function_body locals init): removed the "pad with default values" zero-fill and silent truncation of extra args — arg count ≠ declared param count is now an Err (runtime_type_mismatch).
  • kilnd execute_traditional_module: checks the export's declared param count before engine.execute and errors with function 'X' expects N argument(s) but none were supplied; kilnd cannot yet pass wasm function parameters. No CLI arg-passing flag added (kept minimal per the issue); zero-param entry points (_start, result-only exports) still run.
  • kiln-component direct hosting: the canon lift's REAL param types are now resolved into DirectExportTarget.params and the export's registered FunctionSignature.params (previously always empty), so the existing validate_function_args arity check fires; call_direct_export also checks param arity alongside its existing result-arity check.
  • Load-time validation: each lift's declared param arity is validated against the LIVE instantiated core module's function signature during from_parsed_internal — the mismatched component is rejected at load (exit 1), matching wasm-tools/wasmtime.

Tests (TDD, RED confirmed first)

  • kilnd/tests/arg_arity_tests.rs: no-args on 1-param export → Err; _start/zero-param exports still run; engine-level — missing arg Err, extra arg Err, dbl(5) = 10 correct.
  • kiln-component/tests/direct_export_arity_tests.rs: add with 0 args → Err; add(5,3) = 8 (this direction was ALSO broken before — correct args were rejected against the empty registered params); mismatched lift rejected at load.

Real-binary repro re-run: --function addone exits 1 with the actionable message; --invoke add pc.wasm (invalid lift) rejected at load, exit 1; valid component + correct args works.

rivet: SR-53 created (status: implemented, release v0.4.3). rivet validate: 0 errors (after rivet sync --local for the known stale gust cache).

Note: full cargo test -p kiln-component / -p kiln-runtime target sets have pre-existing bit rot on main (identical error counts on clean main, verified side by side); working invocation used: cargo test -p kiln-component --features std,kiln-execution --test direct_export_arity_tests plus the compilable maintained targets. No new clippy warnings (--no-deps counts identical to main for all three crates).

Closes #443

🤖 Generated with Claude Code

https://claude.ai/code/session_01FcTUZgts331Z1TK3q8YBQj

@avrabe
avrabe force-pushed the fix/sr-53-arg-arity-fabricated-success-443 branch from e18dcc5 to 8c8e7b5 Compare July 21, 2026 21:09
@github-actions

Copy link
Copy Markdown

🔍 Build Diagnostics Report

Summary

Metric Base Branch This PR Change
Errors 0 0 0
Warnings 5 5 0

🎯 Impact Analysis

Issues in Files You Modified

  • 0 new errors introduced by your changes
  • 0 new warnings introduced by your changes
  • 0 total errors in modified files
  • 0 total warnings in modified files
  • 0 files you modified

Cascading Issues (Your Changes Breaking Other Files)

  • 0 new errors in unchanged files
  • 0 new warnings in unchanged files
  • 0 unchanged files now affected

Note: "Cascading issues" are errors in files you didn't modify, caused by your changes (e.g., breaking API changes, dependency issues).

✅ No Issues Detected

Perfect! Your changes don't introduce any new errors or warnings, and don't break any existing code.


📊 Full diagnostic data available in workflow artifacts

🔧 To reproduce locally:

# Install cargo-kiln
cargo install --path cargo-kiln

# Analyze your changes
cargo-kiln build --output json --filter-severity error
cargo-kiln check --output json --filter-severity warning

…ng params (SR-53, #443)

kilnd invoked a param-taking export with ZERO-FILLED arguments whenever
params could not be supplied and reported the resulting wrong value as
SUCCESS (exit 0) — `kilnd mod.wasm --function addone` printed
`✓ returned I32(1)` (= addone(0)) where wasmtime computes addone(5)=6.
The #412 fabricated-reporting family on the function-invocation surface.

Fail-loud fixes, per CLAUDE.md (zero-filling missing params is exactly a
banned masking fallback):

- kiln-runtime stackless engine (execute_function_body locals init):
  remove the "pad with default values" zero-fill and the silent
  truncation of extra args; an argument count that does not match the
  function's declared parameter count is now an Err.
- kilnd execute_traditional_module: check the target export's declared
  param count BEFORE engine.execute and error with an actionable
  message ("function 'X' expects N argument(s) but none were supplied;
  kilnd cannot yet pass wasm function parameters"). No CLI arg-passing
  flag added — the primary fix is the fail-loud rejection. Zero-param
  entry points still run.
- kiln-component direct hosting: resolve the canon lift's REAL param
  types into DirectExportTarget.params and the export's registered
  FunctionSignature.params (previously always empty), so the existing
  validate_function_args arity check actually fires; call_direct_export
  additionally checks param arity alongside its existing result-arity
  check.
- Load-time validation: a spec-invalid component whose canon lift
  declares a different param arity than the backing core function is
  now REJECTED at instantiation (validated against the live
  instantiated core module's signature), matching wasm-tools validate
  and wasmtime, instead of accepted and run.

New RED->GREEN tests: kilnd/tests/arg_arity_tests.rs (4) and
kiln-component/tests/direct_export_arity_tests.rs (3), including
correct-answer assertions (dbl(5)=10, add(5,3)=8) and zero-param
still-runs coverage.

Closes #443

Implements: SR-53

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FcTUZgts331Z1TK3q8YBQj
@avrabe
avrabe force-pushed the fix/sr-53-arg-arity-fabricated-success-443 branch from 8c8e7b5 to d7f537e Compare July 21, 2026 21:41
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@avrabe
avrabe merged commit 6e24906 into main Jul 21, 2026
23 checks passed
@avrabe
avrabe deleted the fix/sr-53-arg-arity-fabricated-success-443 branch July 21, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant