mastra-ai/mastra · error · Error
Harness session "${sessionId}" was not found
Error message
Harness session "${sessionId}" was not found What it means
`HarnessStorage.updateSession` loads the session record by id and throws this error when `loadSession` returns nothing. It guarantees updates only apply to sessions that actually exist in the harness storage backend. All pending-item helpers (`appendPendingItem`, `updatePendingItem`, `removePendingItem`) funnel through it, so a missing session surfaces here.
Source
Thrown at packages/core/src/storage/domains/harness/base.ts:21
export abstract class HarnessStorage extends StorageDomain {
constructor() {
super({
component: 'STORAGE',
name: 'HARNESS',
});
}
abstract loadSession(sessionId: string): Promise<SessionRecord | null>;
abstract saveSession(record: SessionRecord): Promise<void>;
abstract listSessions(): Promise<SessionRecord[]>;
async updateSession(sessionId: string, updates: SessionRecordUpdate): Promise<SessionRecord> {
const record = await this.loadSession(sessionId);
if (!record) {
throw new Error(`Harness session "${sessionId}" was not found`);
}
const next: SessionRecord = {
...record,
...updates,
id: record.id,
createdAt: record.createdAt,
lastActivityAt: updates.lastActivityAt ?? new Date(),
};
await this.saveSession(next);
return next;
}
async appendPendingItem(sessionId: string, item: HarnessPendingItemRecord): Promise<SessionRecord> {
const record = await this.loadSession(sessionId);
if (!record) {
throw new Error(`Harness session "${sessionId}" was not found`);
}View on GitHub (pinned to 75dd419e61)
Solutions
- Create the session first (e.g. `createSession`) and use the returned record's id for subsequent updates.
- Check session existence with `loadSession(sessionId)` or `listSessions()` before updating.
- Confirm you are pointing at the same storage instance/backend where the session was created.
- Log/inspect the sessionId being used; verify it is not stale from an earlier run.
Example fix
// before
await harnessStorage.updateSession('sess-abc', { status: 'completed' }); // throws if absent
// after
const existing = await harnessStorage.loadSession('sess-abc');
if (existing) {
await harnessStorage.updateSession('sess-abc', { status: 'completed' });
} Defensive patterns
Strategy: try-catch
Validate before calling
const record = await storage.loadSession(sessionId);
if (!record) throw new Error(`Refusing to update missing session ${sessionId}`); Type guard
function hasSession(r: SessionRecord | null | undefined): r is SessionRecord {
return r != null && typeof r.id === 'string';
} Try / catch
try {
await storage.updateSession(sessionId, updates);
} catch (e) {
if (e instanceof Error && e.message.includes('was not found')) {
await storage.createSession({ id: sessionId, ...baseFields });
await storage.updateSession(sessionId, updates);
return;
}
throw e;
} Prevention
- Persist sessions in a durable backend if they must survive restarts.
- Always obtain sessionIds from createSession's return value.
- Check loadSession before batch update operations.
- Include sessionId in error logs to spot stale ids quickly.
When it happens
Trigger: Calling `updateSession(sessionId, updates)` with a sessionId that was never created, was already deleted, or exists only in a different storage backend/instance.
Common situations: Reusing a sessionId from a previous process run against a fresh in-memory store; using an id from one harness backend while updating another (e.g. Postgres vs in-memory); truncated or transformed ids; cleanup job deleted the session before the update arrived.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Harness session "${sessionId}" was not found
- Harness pending item "${item.id}" already exists on session
- Harness pending item "${pendingItemId}" was not found on ses
- AcpAgent does not support resuming suspended generate calls
- AcpAgent does not support resuming suspended stream calls
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/5c58002e1cdadeaa.
Report an issue: GitHub.