Compute modules do not pickup optional fileds with @sinclair/typebox

When I define optional params like the following:

const Schemas = {
  askVickie: {
    input: Type.Object({
      query: Type.String(),
      userId: Type.String(),
      threadId: Type.Optional(Type.String()),
    }),
    output: Type.Object({
      status: Type.Integer(),
      message: Type.String(),
      executionId: Type.String(),
      taskList: Type.Optional(Type.String()),
      error: Type.Optional(Type.String()),
    })
  },

Compute modules does not register the optional types. I have to use the UI to mark them as nullable. Which is annoying because it then displays a warning that the current definition of the function has diverged from the inferred schema.

Thank you for reporting this! This should be fixed in @palantir/compute-module version 0.2.9. Please let me know if this fixes the behavior as you expect.

1 Like

That worked, ty! I will mark your solution as correct.

While your solution technically worked after upgrading the lib I now get errors like:

Retrying "executeTaskList" tool call (run tool failed). Correction message: "There was an error while attempting to run this tool. ServiceException: CUSTOM_CLIENT (AipTools:FunctionRuntimeError): {errorMessage=Optional[Found unexpected value for function return type], params={value=true, returnType=string}, stacktrace=Optional[SafeError: Found unexpected value for function return type
    at t [as constructor] (FunctionsIsolateRuntimePackage:2:1385658)
    at new t (FunctionsIsolateRuntimePackage:2:583224)
    at t.unexpected..."

{
    "errorTitle": "Failed to apply changes due to the following error: Optional[Found unexpected value for function return type]",
    "errorMessage": "There was a runtime error in the Function that backs this Action Type",
    "additionalProperties": {
        "parameters": [
            {
                "humanReadableLabel": "Function RID",
                "humanReadableValue": "ri.function-registry.main.function.e3e8f0a5-040c-4e92-9c52-de270c21322e"
            },
            {
                "humanReadableLabel": "Function version",
                "humanReadableValue": "RuleAndExecutedFunctionVersions{ruleFunctionVersion: 10.0.2, executedFunctionVersion: Optional[10.0.2]}"
            },
            {
                "humanReadableLabel": "Parameter values",
                "humanReadableValue": "\"{value=true, returnType=string}\""
            },
            {
                "humanReadableLabel": "Stack trace",
                "humanReadableValue": "Optional[SafeError: Found unexpected value for function return type\n    at t [as constructor] (FunctionsIsolateRuntimePackage:2:1385658)\n    at new t (FunctionsIsolateRuntimePackage:2:583224)\n    at t.unexpectedValueForType (FunctionsIsolateRuntimePackage:2:1134108)\n    at u (FunctionsIsolateRuntimePackage:2:1240400)\n    at a (FunctionsIsolateRuntimePackage:2:1240326)\n    at Object.string (FunctionsIsolateRuntimePackage:2:1084317)\n    at Object.visit (FunctionsIsolateRuntimePackage:2:671682)\n    at v.validateAndTransformResult (FunctionsIsolateRuntimePackage:2:1083760)\n    at Object.optionalType (FunctionsIsolateRuntimePackage:2:1087375)\n    at Object.visit (FunctionsIsolateRuntimePackage:2:672180)]"
            }
        ],
        "docsUrl": "<HOSTNAME>/docs/foundry/functions/user-facing-error",
        "errorDetails": {
            "errorCode": "CUSTOM_CLIENT",
            "errorId": "83b49ae4-e8f8-4367-8d12-8f0044b2122f",
            "errorName": "Actions:FunctionExecutionRuntimeError"
        }
    }
}

There is nothing wrong with my function either. If I manually call it from the compute module passing the same inputs everything is fine. This is for sure Foundry’s API barfing on some new signature. Please help as this is blocking production.


The input params of the function in question

Code for the function in question. As you can see this is used to back the action my app is trying to call. There return type for this function void. So the only thing I can figure is that Foundry is inspecting the call the the compute module function (xReasonGetNextState), and since I upgraded the optional values in the return type are blowing up the validation.

@Edits(ComputeModuleFunctionExecutions)
@OntologyEditFunction()
@ExternalSystems({ sources: [FoundryApis] })
public async updateState(
    plan: string = '',
    forward: boolean = true,
    executionId: string = '',
    inputs: string = '{}',
    xreason: string = SupportedEngines.COMS): Promise<void> {

    const result = await xReasonGetNextState({plan, forward, executionId, inputs, xreason});

    const executionWrapper = Objects.create().computeModuleFunctionExecutions(uuidv4());
    executionWrapper.status = 200;
    executionWrapper.results = JSON.stringify(result);
    executionWrapper.functionName = 'xReasonGetNextState';
    executionWrapper.dateTimeExecuted = Timestamp.fromJsDate(new Date());
}

reverting to 2.0.7 resolved the issue.

Actually the error is still occurring intermittently. Did something change in functions overnight? I have no idea why the error would randomly occur unless there is a rolling update taking place and it just takes a while to update all the replicas.

This may be due to caching within the Action’s function due to the compute module output definition changing – could you delete and re-create the compute module function?

What do you mean? do you mean in my functions repo remove the imported compute module function the reimport it?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.