android / android/appfunctions
[Bug]: cmd app_function execute-app-function fails to convert JSON numbers into nullable Double parameters (code 1001)
- Dominant language
- Kotlin
- Stars
- 191
- Forks
- 36
- Avg merge
- 13d 16h
- Merged PRs (30d)
- 2
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues (also searched: Double, quantity, number, parameters JSON, cmd app_function — no match)
### Is there a StackOverflow question about this issue?
- [x] I have searched StackOverflow
### What happened?
Filing here for visibility since maintainers triage this repo; happy to move it to issuetracker.google.com component 1709065 if that's the preferred venue — this is about the **platform/Jetpack shell tooling**, not the samples.
**Environment:** `androidx.appfunctions:1.0.0-alpha10` (+ `appfunctions-compiler` via KSP 2.3.10), `@AppFunctionServiceEntryPoint` architecture, emulator `system-images;android-36.1;google_apis;x86_64`, compileSdk 37 / targetSdk 36. Production KMP app (Kotlin, kotlin-inject; no Hilt).
**Function under test** — registration is correct (`list-app-functions` shows full typed metadata incl. KDoc descriptions) and binder-side execution works (typed results and typed `AppFunctionException`s round-trip):
```kotlin
@AppFunctionSerializable(isDescribedByKDoc = true)
data class AddItemParams(
val itemName: String,
val listName: String? = null,
val quantity: Double? = null, // <- the field that breaks
val unit: String? = null,
val brand: String? = null,
)
@AppFunction(isDescribedByKDoc = true)
internal suspend fun addItemToGroceryList(params: AddItemParams): AddedItem
```
**Repro:**
```
adb shell "cmd app_function execute-app-function \
--package \
--function '.BaseSpotAppFunctionService#addItemToGroceryList' \
--parameters '{\"params\": {\"itemName\": \"Apples\", \"quantity\": 3.0}}' \
--timeout-duration 45"
```
**Actual:**
```
Error executing app function: android.app.appfunctions.AppFunctionException:
Parameter params should be the type of AppFunctionReferenceTypeMetadata(
referenceDataType=...$AddItemParams, isNullable=false,description=) (code 1001)
```
**Expected:** `3.0` (and integer-form `3`) convert into the nullable `Double` property, as the function metadata advertises the field as DOUBLE.
**Isolation:** the identical call with only String fields succeeds and creates the item:
```
--parameters '{"params": {"itemName": "Cheese", "listName": "Groceries"}}' -> OK, typed result
--parameters '{"params": {"itemName": "Apples", "listName": "Groceries", "quantity": 3.0}}' -> code 1001
--parameters '{"params": {"itemName": "Butter", "listName": "Groceries", "unit": "pack"}}' -> OK
```
So the failure tracks the numeric field, not the JSON envelope. Real agents constructing `AppFunctionData` binder-side appear unaffected — but the adb shell path is exactly what the AppFunctions agent skill prescribes for local evaluation, so any function with numeric parameters is currently untestable from the shell.
**Minor adjacent papercut (arguably WAI):** the default execute deadline is shorter than a cold service start + first network fetch, so the first-ever invocation reports `Timed out`, which reads as a hang. `--timeout-duration` fixes it; a larger default or a first-run hint would save new adopters the same false diagnosis.
### Relevant logcat output
```shell
Error executing app function: android.app.appfunctions.AppFunctionException: Parameter params should be the type of AppFunctionReferenceTypeMetadata(referenceDataType=com.tarek.spot.appfunctions.BaseSpotAppFunctionService$AddItemParams, isNullable=false,description=) (code 1001). See logcat for more details.
```
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Contributor guide
Research direction
Start with the `cmd app_function execute-app-function` entry point and reproduce the supplied calls using nullable `Double` values, integer-form numbers, and String-only fields. Trace the parameter conversion path for the JSON envelope and compare it with binder-side execution. Done means both `3.0` and `3` populate the nullable `Double` field without code 1001, while existing String parameters still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100