Workflow not awaiting in inbound interceptor

I have a use case where I’d like to catch any workflow exceptions in the inbound workflow interceptor and await for a signal to proceed. I have something like this:

@Override public WorkflowOutput execute(WorkflowInput input) {
        try {
          logger.info("Executing workflow: " + Arrays.toString(input.getArguments()));
          return next.execute(input);
        } catch (Exception e) {
          logger.info("Workflow execution failed: " + e);
          Workflow.await(() -> retryWorkflow || failWorkflow);
          
          if (retryWorkflow) {
            retryWorkflow = false;
            Workflow.continueAsNew(input.getArguments());
          } else if (failWorkflow) {
            failWorkflow = false;
            throw Workflow.wrap(new Exception());
          }
        }
        return null;
      }

But it doesn’t wait, although I do see the log line Workflow execution failed: so it does go into the catch block but does not respect the await. Am I doing anything wrong?

This should work. What are the values of the retryWorkflow and failWorkflow fields?

I haven’t set them, so they must be the defaults. What should I change them to so this works?

I don’t know what you are trying to achieve. It looks like one of them is not false as await is not blocking.

Both are false and I think it is blocking on await but its not able to receive the signal for some reason. This is how I’ve implemented the handleSignal method

 @Override public void handleSignal(SignalInput input) {
        logger.info("Received signal: " + input.getSignalName());
        if (input.getSignalName().equals("retryWorkflow")) {
          logger.info("Received retryWorkflow signal");
          retryWorkflow = true;
        } else if (input.getSignalName().equals("failWorkflow")) {
          logger.info("Received failWorkflow signal");
          failWorkflow = true;
        }
        next.handleSignal(input);
      }

But when I send a signal to the workflow from the UI, its not being handled at all so the workflow just keeps awaiting until the timeout happens. I’m following the retry on signal interceptor example here samples-java/core/src/main/java/io/temporal/samples/retryonsignalinterceptor at main · temporalio/samples-java · GitHub to retry activities on failures, but I’d also like something similar for workflow failures which is what I’m trying to achieve here, but it doesn’t seem to work.

You said that you are implementing an interceptor. Adding a signal method to it is not going to work unless you explicitly register a signal handler. See samples-java/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryOnSignalWorkflowOutboundCallsInterceptor.java at 30db7dba46b5879ff64929749ccb54201addfd4e · temporalio/samples-java · GitHub

Ah yes, ok so that works now. How can I restart the workflow from the beginning with the same input upon receiving a signal?

Call next.execute again

Would it restart from the beginning or from where the point of failure?

From the beginning. When writing workflows think about them as normal code. So if you code threw an exception there is not way to restart a function from the point the exception was thrown.