diegosouzapw/OmniRoute · error · LeaseContextError

LEASE_CONTEXT_INVALID

LEASE_CONTEXT_INVALID

Error message

Malformed lease owner

What it means

LeaseContextError thrown by parseLeaseOwnerHeader() when the lease-owner header is present but its value fails validation (malformed owner identifier, not merely missing). Guards lease bookkeeping against garbage owner ids that would corrupt attribution.

Solutions

  1. Send a well-formed lease owner identifier in LEASE_OWNER_HEADER (check expected format in leaseContext.ts)
  2. Re-generate the owner id if the client stored a corrupted value
  3. Validate owner ids at creation time so malformed ones never reach lease headers
  4. Return 400 to the caller with the lease error code for diagnostics
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/sse/services/leaseContext.ts:54 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/6a1ced66f41266a7. Report an issue: GitHub.

Appendix: source

Thrown at src/sse/services/leaseContext.ts:54

export function validateExclusiveLeaseKeyConfiguration(
  metadata: LeaseKeyMetadata | null | undefined
): void {
  if (!isExclusiveLeaseManagedKey(metadata)) return;
  if (!metadata?.allowedConnections?.length)
    throw new LeaseContextError(
      403,
      "LEASE_KEY_CONFIGURATION_INVALID",
      "Exclusive lease keys require explicit allowed connections"
    );
}

export function parseLeaseOwnerHeader(headers: Headers): string {
  const leaseOwnerId = headers.get(LEASE_OWNER_HEADER)?.trim() ?? "";
  if (!leaseOwnerId)
    throw new LeaseContextError(400, "LEASE_CONTEXT_REQUIRED", "Explicit lease owner required");
  if (!LEASE_OWNER_PATTERN.test(leaseOwnerId))
    throw new LeaseContextError(400, "LEASE_CONTEXT_INVALID", "Malformed lease owner");
  return leaseOwnerId;
}

export function parseManagedLeaseRequestContext(headers: Headers): ManagedLeaseRequestContext {
  const leaseOwnerId = parseLeaseOwnerHeader(headers);
  const rawGeneration = headers.get(LEASE_GENERATION_HEADER)?.trim() ?? "";
  if (!/^[1-9]\d*$/.test(rawGeneration))
    throw new LeaseContextError(400, "LEASE_CONTEXT_INVALID", "Positive lease generation required");
  const generation = Number(rawGeneration);
  if (!Number.isSafeInteger(generation))
    throw new LeaseContextError(
      400,
      "LEASE_CONTEXT_INVALID",
      "The lease generation header is invalid"
    );
  return { leaseOwnerId, generation };
}

View on GitHub (pinned to a179ffed5b)