paperclipai/paperclip · error

realizeWorkspace occurred before acquireLease for environmen

Error message

realizeWorkspace occurred before acquireLease for environment ${environmentId}

What it means

Test-helper assertion in assertWorkspaceRealizationLifecycle: a realizeWorkspace event exists for the environmentId, but its timestamp precedes the acquireLease event's. The recorded events show workspace realization happening before the lease was acquired, violating the acquire-then-realize ordering the assertion enforces.

Source

Thrown at packages/plugins/sdk/src/testing.ts:291

  if (!release) throw new Error(`No releaseLease/destroyLease event found for environment ${environmentId}`);
  if (acquire.timestamp > release.timestamp) {
    throw new Error(`acquireLease occurred after release for environment ${environmentId}`);
  }
  return { acquire, release };
}

/** Assert that workspace realization occurred between lease acquire and release. */
export function assertWorkspaceRealizationLifecycle(
  events: EnvironmentEventRecord[],
  environmentId: string,
): EnvironmentEventRecord {
  const lifecycle = assertLeaseLifecycle(events, environmentId);
  const realize = events.find(
    (e) => e.type === "realizeWorkspace" && e.environmentId === environmentId,
  );
  if (!realize) throw new Error(`No realizeWorkspace event found for environment ${environmentId}`);
  if (realize.timestamp < lifecycle.acquire.timestamp) {
    throw new Error(`realizeWorkspace occurred before acquireLease for environment ${environmentId}`);
  }
  if (realize.timestamp > lifecycle.release.timestamp) {
    throw new Error(`realizeWorkspace occurred after release for environment ${environmentId}`);
  }
  return realize;
}

/** Assert that an execute call occurred within the lease lifecycle. */
export function assertExecutionLifecycle(
  events: EnvironmentEventRecord[],
  environmentId: string,
): EnvironmentEventRecord[] {
  const lifecycle = assertLeaseLifecycle(events, environmentId);
  const execEvents = events.filter(
    (e) => e.type === "execute" && e.environmentId === environmentId,
  );
  if (execEvents.length === 0) {
    throw new Error(`No execute events found for environment ${environmentId}`);

View on GitHub (pinned to 01ad858492)

Solutions

  1. Fix lifecycle ordering so realizeWorkspace happens after acquireLease.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/plugins/sdk/src/testing.ts:291 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of paperclipai/paperclip@01ad858492 (2026-08-18). Data as JSON: /api/errors/9de14af8cb5564f2. Report an issue: GitHub.