Saturday, May 17, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

Replay Testing To Avoid Non-Determinism in Temporal Workflows

December 18, 2023
in Front-Tech
Reading Time: 4 mins read
0 0
A A
0
Share on FacebookShare on Twitter


Deploying an updated version of Temporal workflow code can result in errors if there are non-deterministic changes to the code. Determinism is verified during the “replay“ process that rebuilds the last known state of an ongoing workflow in order to continue its execution. Rebuilding execution state enables Temporal to support long-sleeping workflows and reliably relocate workflow executions to another worker when one crashes.

Replay doesn’t re-execute the commands recorded in the history. Instead, it uses the recorded results to reconstruct the state. While that history is playing back, if updated workflow code attempts a command that wasn’t expected at that point in the history, a non-determinism exception will be thrown.

We’ll review an example of a non-deterministic change and see how we can proactively check for them with replay testing. This article will use the Typescript SDK, but the Temporal SDKs for other languages behave similarly and offer comparable functionality.

It’s worth noting that since replay is a relatively expensive operation, Temporal doesn’t perform a replay every time a workflow execution progresses. Replays are only performed when the worker doesn’t have the execution state in its local cache of workflow states. Common scenarios for state cache misses are workflows picked up by a newly deployed worker, workflows that have been idle for long periods of time, or workflows that moved to a new worker after their original became unavailable.

Example of a Non-Deterministic Change

Consider a hypothetical e-commerce order processing workflow:

async function orderProcessingWorkflow(
account: Account,
products: Product[],
payment: PaymentInfo
) {
const processingResult = await processPaymentActivity(payment)

if (processingResult.successful) {
await sendUserNotificationActivity(account, products, payment)
await startShippingWorkflowActivity(products)
} else { … }
}

Now imagine this workflow required a change to make an additional call to a 3rd party anti-fraud platform before processing the payment of any new orders:

async function orderProcessingWorkflow(
account: Account,
products: Product[],
payment: PaymentInfo
) {
if (await isFraudulentActivity(account, products, payment)) {
throw ApplicationError.create({ message: ‘Fraud detected.’, nonRetryable: true })
}

const processingResult = await processPaymentActivity(payment)

if (processingResult.successful) { … } else { … }
}

When this change is deployed, the worker history replay process would expect the history to begin with isFraudluentActivity, but the recorded history will have started with processPaymentActivity. This mismatch results in the non-determinism exception being thrown on all workflow instances trying to resume execution, for example:

Unhandled rejection { runId: … }
DeterminismViolationError: Replay failed with a nondeterminism error. This means that the workflow code as written is not compatible with the history that was fed in.
Details: Workflow activation completion failed: Failure {
failure: Some(Failure {
message: “Nondeterminism(\”Activity machine does not handle this event: HistoryEvent(id: 5, ScheduleActivityTask)\”)”, … )
})
}

However, non-deterministic changes can often be avoided by writing your code so that any of the existing histories won’t end up making any unexpected commands during their replay process, like the sample below.

async function orderProcessingWorkflow(
account: Account,
products: Product[],
payment: PaymentInfo
) {
const checkForFraud = payment.checkForFraud ?? false

if (checkForFraud && await isFraudulentActivity(account, products, payment)) {
throw ApplicationError.create({ message: ‘Fraud detected.’, nonRetryable: true })
}

const processingResult = await processPaymentActivity(payment)

if (processingResult.successful) { … } else { … }
}

In the above example, a new checkForFraud property on the payment argument can be optionally provided. Any new workflow executions can pass in payment.checkForFraud = true and will, in turn, run the new isFraudlentActivity activity. Any ongoing workflow executions will have no payment.checkForFraud property and will skip the isFraudlentActivity during their replays, avoiding the non-determinism error.

Replay Testing

To proactively guard against non-determinism errors, you can add replay testing to your CI. Replay testing involves simulating the history replay process that the worker will do when resuming execution of a workflow and throwing an error at any non-deterministic changes encountered.

To run the simulation, you’ll need to have some workflow history to replay. The easiest way to do this is by manually sampling histories by downloading them in JSON form via the Temporal CLI:

tctl workflow show -w myWorkflowId -of ./myWorkflowId_history.json

or the Web UI:

The downloaded histories can then be replayed during testing runs with a simple script:

#!/usr/bin/env -S npx ts-node-esm
// replay_test.ts {history_file}
import fs from ‘fs’
import { Worker } from “@temporalio/worker”

const filePath = process.argv[2]
const history = JSON.parse(await fs.promises.readFile(filePath, ‘utf8’))
const workflowsPath = new URL(‘../src/workflows.ts’, import.meta.url).toString().replace(‘file://’, ”)

await Worker.runReplayHistory({ workflowsPath }, history)

However, in this case, the downloaded histories are yet another static test fixture developers need to keep up to date. As you change your workflow, you’ll need to update your saved test histories to ensure your replay testing is representative of the executions that will be resuming on the workers.

Rather than depend on static test fixtures alone, you can dynamically download



Source link

Tags: avoidNonDeterminismReplayTemporalTestingworkflows
Previous Post

Artificial intelligence can predict events in people’s lives

Next Post

CSPR Price Chart 📈 Casper Network CSPR 💥Waiting for Volume 💣CRYPTO NEWS 💲

Related Posts

The essential principles of a good homepage
Front-Tech

The essential principles of a good homepage

June 7, 2024
How to measure and improve user retention
Front-Tech

How to measure and improve user retention

June 6, 2024
Push Animation on Grid Items
Front-Tech

Push Animation on Grid Items

June 5, 2024
How to build a Rails API with rate limiting
Front-Tech

How to build a Rails API with rate limiting

June 4, 2024
Introduction to the B.I.A.S. framework
Front-Tech

Introduction to the B.I.A.S. framework

June 3, 2024
Blue Ridge Ruby is exactly what we need
Front-Tech

Blue Ridge Ruby is exactly what we need

June 3, 2024
Next Post
CSPR Price Chart 📈 Casper Network CSPR 💥Waiting for Volume 💣CRYPTO NEWS 💲

CSPR Price Chart 📈 Casper Network CSPR 💥Waiting for Volume 💣CRYPTO NEWS 💲

Wall Street eyes Adobe’s AI-driven growth By Investing.com

Wall Street eyes Adobe's AI-driven growth By Investing.com

ByteDance AI Research Introduces StemGen: An End-to-End Music Generation Deep Learning Model Trained to Listen to Musical Context and Respond Appropriately

ByteDance AI Research Introduces StemGen: An End-to-End Music Generation Deep Learning Model Trained to Listen to Musical Context and Respond Appropriately

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
Porfo: Revolutionizing the Crypto Wallet Landscape

Porfo: Revolutionizing the Crypto Wallet Landscape

October 9, 2023
23 Plagiarism Facts and Statistics to Analyze Latest Trends

23 Plagiarism Facts and Statistics to Analyze Latest Trends

June 4, 2024
A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

May 19, 2024
Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

November 20, 2023
Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

December 6, 2023
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In