Cancel workflow if infinite activity fails

How can I cancel my workflow with status completed if my infinite activity fails or timeout.

Cancelling results in status cancelled. If you want status completed, you return from the workflow function.

try {
  await callActivityFoo()
} catch (e) {
  // dont throw e, the activity failure

my infinite activity fails or timeout

Just to add, there is no “infinite” activity execution as you seen since you have to specify at least one timeout (StartToClose and/or ScheduleToClose) timeouts in activity options.

For long-running activities specify a the longest possible StartToCloseTimeout and a short HeartBeatTimeout (your activity must heartbeat periodically within this heartbeat period). This way your activity can execute for a very long time but still be able to fail fast if needed.