What happens
In a SuperRepo project, every function-backed action fails on its first call after deploy, before any function code runs:
FunctionExecutionFailed
TypeError: Cannot read properties of undefined (reading 'length')
at getRuntimeMetadataOntologyRid (.../@foundry/functions-typescript-runtime/dist/runtime/utils.js:104)
at setUpClients (.../runtime/utils.js:81)
at FunctionsTypeScriptRuntimeResource.executeFunction (...)
Cause (as far as I can tell)
foundry build function-tswritesvar/conf/metadata.jsonwith a singular field:"ontologyRid": "ri.ontology.main.ontology.0000".@foundry/functions-typescript-runtimereads a plural array:runtimeMetadata.ontologyRids.length. The field is missing, so it throws.- Versions seen: CLI 0.329.0 locally and 0.343.0 in the CI image, runtime 0.311.0 as pinned by the template, and 0.356.0, the newest on the registry, which reads it the same way.
To reproduce
- Create a SuperRepo from the template.
- Add a function-backed action.
- Tag and deploy through CI.
- Apply the action through the API. It fails with the error above.
Workaround
After pnpm deploy and before foundry build function-ts, patch the bundled runtime so it accepts both field names. Add this line at the top of getRuntimeMetadataOntologyRid in build/deploy/node_modules/@foundry/functions-typescript-runtime/dist/runtime/utils.js:
runtimeMetadata.ontologyRids ??= runtimeMetadata.ontologyRid ? [runtimeMetadata.ontologyRid] : [];
With it, function-backed actions run and their edits apply.
Question: Is the platform meant to rewrite metadata.json at install time? Or should the CLI and the runtime agree on this field name?