Tasks and outcomes
A task is one thing a user is trying to do, such as answering a practice question. Record how it starts, what happens and how it ends, and Relay rebuilds it into a complete trajectory.
Record a task
Call startTask() when the user begins. Every event you record on the task carries its taskId, in order. End it with complete() or abandon(); after that the task refuses further events.
import { createRelay, type LearningTaskEvents } from "@relaysdk/sdk";
const relay = createRelay<LearningTaskEvents>({ publicKey, endpoint, attest });
const task = relay.startTask({ taskType: "practice_question", subject: "maths", difficulty: "intermediate" });
task?.track("task.action", { action: "answer_submitted", attempt: 1, correct: false });
task?.track("task.feedback", { feedbackType: "incorrect_marker", attempt: 1 });
task?.track("task.retry", { attempt: 2 });
task?.track("task.action", { action: "answer_submitted", attempt: 2, correct: true });
task?.complete({ outcome: "success", attempts: 2 });Like everything else, startTask() returns null unless the user has opted in. Inside a session, use session.startTask() so task events share the session's sequence.
Standard task events
Every task schema uses the same event names, so trajectories look the same whatever the app. Fields are bounded and never free text.
| Event | Meaning |
|---|---|
| task.started | A task began. Carries the task type and its context. |
| task.action | The user took a defined action, such as submitting an answer. |
| task.feedback | The app gave feedback, such as a hint or an explanation. |
| task.error | The task hit an error. |
| task.retry | The user tried again. |
| task.completed | The task finished, with an outcome. |
| task.abandoned | The task ended without being completed. |
Each schema defines its own task types, context fields and actions. See learning_task in Event schemas.
Verify the outcome from your backend
The browser can say a task succeeded, but only your backend knows, for example because it marked the answer. Confirm the outcome with your server credential. Relay counts an outcome as verified only when this matches what the browser reported.
import { createRelayServer } from "@relaysdk/sdk/server";
const relay = createRelayServer({ secretKey: process.env.RELAY_SECRET_KEY!, endpoint: process.env.NEXT_PUBLIC_RELAY_ENDPOINT! });
// After grading, using the same subject you attest with and the task id from the browser:
await relay.verifyOutcome({ subject: user.id, taskId, outcome: "success", attempts: 2 });The first outcome recorded for a task is kept. Sending a different one later is refused with outcome_already_recorded. If your backend and the browser disagree, the trajectory is marked as a conflict and is never included in a dataset.
What Relay builds
Relay rebuilds each task from its accepted events, in order: the task type and context, every step with its timing, attempts, retries, feedback, errors and the outcome. Tasks can arrive across several batches and are rebuilt as new events arrive.
| Status | Meaning |
|---|---|
| completed | Started and completed. Has an outcome. |
| abandoned | Started and abandoned. Never counted as a success. |
| in_progress | Started, not ended yet. |
| incomplete | No start was received. Never counted as a finished task. |
Each trajectory also gets explainable quality checks: it has a start and end, every step passed validation, no step was rejected or quarantined, steps and timestamps are in order, the context is complete, the outcome is consistent, and it is not a duplicate.