langgenius/dify · error · Error

reconnect stream body missing

Error message

reconnect stream body missing

What it means

Raised by DatasetsHitTestingBase.get_and_validate_dataset, a shared helper invoked by the hit-testing endpoints. Identical semantics to the inline dataset lookups: DatasetService.get_dataset(dataset_id, session) returned None. The helper additionally resolves the account via resolve_account_fallback and then runs check_dataset_permission, but the NotFound is purely an existence check on the dataset row.

Source

Thrown at cli/src/api/app-run.ts:99

    })
  }

  async reconnectStream(
    appId: string,
    workflowRunId: string,
    opts: StreamOptions = {},
  ): Promise<AsyncIterable<SseEvent>> {
    const url = `apps/${encodeURIComponent(appId)}/tasks/${encodeURIComponent(workflowRunId)}/events`
    const res = await this.http.stream(url, {
      searchParams: {
        include_state_snapshot: opts.includeStateSnapshot === true ? 'true' : 'false',
        continue_on_pause: 'false',
      },
      headers: { Accept: 'text/event-stream' },
      signal: opts.signal,
      throwOnError: true,
    })
    if (res.body === null) throw new Error('reconnect stream body missing')
    return normalizeDifyStream(parseSSE(res.body, opts.signal))
  }
}

View on GitHub (pinned to ef8544b173)

Solutions

  1. Confirm the dataset exists and is accessible to the current tenant via GET /datasets/{dataset_id} before calling hit-testing.
  2. Handle 404 responses in the client by refreshing the dataset list and clearing stale references.
  3. If scripting, assert the dataset_id is present in the listed datasets before issuing the hit-testing call.

Example fix

# before
dataset = DatasetsHitTestingBase.get_and_validate_dataset(session, dataset_id, user)
# after — guard at the caller with an explicit existence/permission pre-check
from services.dataset_service import DatasetService
if DatasetService.get_dataset(dataset_id, session) is None:
    return None  # caller surfaces a friendly "dataset missing" message
dataset = DatasetsHitTestingBase.get_and_validate_dataset(session, dataset_id, user)
Defensive patterns

Strategy: validation

Validate before calling

async function ensureDatasetForHitTesting(client, datasetId, tenantId) {
  const r = await client.get(`/console/api/datasets/${datasetId}`);
  if (r.status === 404) throw new Error('Dataset not available for hit testing');
  if (r.status === 403) throw new Error('No permission to test this dataset');
  return true;
}

Type guard

function isKnownDatasetId(id: string, knownIds: Set<string>): boolean {
  return knownIds.has(id);
}

Try / catch

try {
  await hitTesting(client, datasetId, query);
} catch (e) {
  if (e.response?.status === 404) { await refreshDatasetList(); return; }
  if (e.response?.status === 403) { notifyNoPermission(); return; }
  throw e;
}

Prevention

When it happens

Trigger: Calling any hit-testing endpoint (e.g. POST /datasets/{dataset_id}/hit-testing) with a dataset_id that has no row in the datasets table. The helper is invoked after request model validation, so malformed UUIDs are caught earlier by the route converter.

Common situations: Dataset was deleted between the user opening the hit-testing panel and submitting the query; wrong dataset_id passed from an orchestration script; tenant isolation returning None because the dataset belongs to a different tenant when the lookup is scoped elsewhere.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/d61efc6206c1b5fd. Report an issue: GitHub.