new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Temporal · Concepts · all subjects

approval/escalation

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Python escalating approval workflow implementation

```python # workflows.py import asyncio from datetime import timedelta from temporalio import workflow from models import ApprovalData with workflow.unsafe.imports_passed_through(): from activities import send_escalation_email @workflow.defn class EscalatingApprovalWorkflow: def __init__(self) -> None: self.approval_data: ApprovalData | None = None self.escalated = False @workflow.run async def run(self, request_id: str, initial_timeout_seconds: int) -> str: try: # Wait for the first approval within the initial timeout await workflow.wait_condition( lambda: self.approval_data is not None, timeout=timedelta(seconds=initial_timeout_seconds), ) except asyncio.TimeoutError: # No response in time: escalate to a manager, then wait longer self.escalated = True await workflow.execute_activity( send_escalation_email, start_to_close_timeout=timedelta(seconds=10), ) try: # Extended wait for the escalated approval await workflow.wait_condition( lambda: self.approval_data is not None, timeout=timedelta(hours=24), ) except asyncio.TimeoutError: return "Escalation timeout - auto-rejected" decision = self.approval_data.decision approver = self.approval_data.approver escalation_note = " (escalated)" if self.escalated else "" return f"{decision} by {approver}{escalation_note}" @workflow.signal def submit_approval(self, data: ApprovalData) -> None: self.approval_data = data ``` This shows an escalating approval Workflow in Python that escalates to a manager on initial timeout and then waits with an extended timeout.

Go escalating approval workflow implementation

```go // workflow.go func EscalatingApprovalWorkflow(ctx workflow.Context, requestId string, initialTimeout time.Duration) (string, error) { var approvalData *ApprovalData escalated := false workflow.Go(ctx, func(ctx workflow.Context) { signalChan := workflow.GetSignalChannel(ctx, "submitApproval") signalChan.Receive(ctx, &approvalData) }) // Wait for the first approval within the initial timeout ok, err := workflow.AwaitWithTimeout(ctx, initialTimeout, func() bool { return approvalData != nil }) if err != nil { return "", err } if !ok { // No response in time: escalate to a manager, then wait longer escalated = true ao := workflow.ActivityOptions{ StartToCloseTimeout: 10 * time.Second, } actCtx := workflow.WithActivityOptions(ctx, ao) // Notify the manager via an Activity err = workflow.ExecuteActivity(actCtx, SendEscalationEmail).Get(ctx, nil) if err != nil { return "", err } // Extended wait for the escalated approval ok, err = workflow.AwaitWithTimeout(ctx, 24*time.Hour, func() bool { return approvalData != nil }) if err != nil { return "", err } if !ok { return "Escalation timeout - auto-rejected", nil } } escalationNote := "" if escalated { escalationNote = " (escalated)" } return fmt.Sprintf("%s by %s%s", approvalData.Decision, approvalData.Approver, escalationNote), nil } ``` This shows an escalating approval Workflow in Go that executes an Activity to send an escalation email on initial timeout.

Java escalating approval workflow implementation

```java // EscalatingApprovalWorkflowImpl.java public class EscalatingApprovalWorkflowImpl implements ApprovalWorkflow { private ApprovalData approvalData; private boolean escalated = false; @Override public String execute(String requestId, Duration initialTimeout) { // Wait for the first approval within the initial timeout boolean received = Workflow.await(initialTimeout, () -> approvalData != null); if (!received) { // No response in time: escalate to a manager, then wait longer escalated = true; sendEscalationNotification(); // Extended wait for the escalated approval received = Workflow.await( Duration.ofHours(24), () -> approvalData != null); if (!received) { return "Escalation timeout - auto-rejected"; } } String decision = approvalData.getDecision(); String approver = approvalData.getApprover(); String escalationNote = escalated ? " (escalated)" : ""; return decision + " by " + approver + escalationNote; } @Override public void submitApproval(ApprovalData data) { this.approvalData = data; } private void sendEscalationNotification() { ActivityOptions options = ActivityOptions.newBuilder() .setStartToCloseTimeout(Duration.ofSeconds(10)) .build(); NotificationActivities activities = Workflow.newActivityStub(NotificationActivities.class, options); activities.sendEscalationEmail(); } } ``` This shows an escalating approval Workflow in Java that sends an escalation notification via Activity and then waits with an extended timeout.

TypeScript escalating approval workflow implementation

```typescript // workflows.ts import * as wf from '@temporalio/workflow'; import type * as activities from './activities'; import { ApprovalData } from './types'; const { sendEscalationEmail } = wf.proxyActivities<typeof activities>({ startToCloseTimeout: '10 seconds', }); export const submitApprovalSignal = wf.defineSignal<[ApprovalData]>('submitApproval'); export async function escalatingApprovalWorkflow( requestId: string, initialTimeoutMs: number, ): Promise<string> { let approvalData: ApprovalData | undefined; let escalated = false; wf.setHandler(submitApprovalSignal, (data: ApprovalData) => { approvalData = data; }); // Wait for the first approval within the initial timeout let received = await wf.condition( () => approvalData !== undefined, initialTimeoutMs, ); if (!received) { // No response in time: escalate to a manager, then wait longer escalated = true; await sendEscalationEmail(); // Extended wait for the escalated approval received = await wf.condition( () => approvalData !== undefined, '24 hours', ); if (!received) { return 'Escalation timeout - auto-rejected'; } } const { decision, approver } = approvalData!; const escalationNote = escalated ? ' (escalated)' : ''; return `${decision} by ${approver}${escalationNote}`; } ``` This shows an escalating approval Workflow in TypeScript that calls an Activity to escalate and waits with an extended timeout.

Escalation pattern in approval workflows

When an initial approval times out, you may want to escalate the request to a manager rather than rejecting it outright. The escalation pattern adds an escalation step with an extended timeout: the Workflow first waits for the initial timeout, and if no Signal arrives, it sets an escalated flag, executes a notification Activity to alert the manager, and then waits again with a longer extended timeout (such as 24 hours). The final result includes an escalation note so the caller knows the request was escalated before approval.

Give your agent this brain