SuperRepo: deployed TypeScript functions fail with "Cannot read properties of undefined (reading 'length')" in getRuntimeMetadataOntologyRid

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-ts writes var/conf/metadata.json with a singular field: "ontologyRid": "ri.ontology.main.ontology.0000".
  • @foundry/functions-typescript-runtime reads 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

  1. Create a SuperRepo from the template.
  2. Add a function-backed action.
  3. Tag and deploy through CI.
  4. 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?

Hey @rahulgarg we appreciate the detailed bug report. I took a look into this and I think this should actually be resolved in v0.346.0 of the Foundry CLI. Try running this:

foundry update self

It’s possible the CLI will complain about functionsTypescriptRuntimeVersion being too low. If so, just update it to the version it tells you (for example, "0.311.0"). Let me know if this helps solve your issue!