langgenius/dify · warning · NotFound

Child chunk not found.

Error message

Child chunk not found.

What it means

Raised in the DELETE child-chunk handler after segment and child-chunk resolution when SegmentService.get_child_chunk_by_segment_ref returns None for the given child_chunk_id under the resolved segment_ref. The target child chunk does not exist or was already deleted, so the controller returns NotFound (HTTP 404).

Source

Thrown at api/controllers/console/datasets/datasets_segments.py:908

        DatasetService.check_dataset_model_setting(dataset)
        # check document
        document_id_str = str(document_id)
        document = DocumentService.get_document(dataset_id_str, document_id_str, session=session)
        if not document:
            raise NotFound("Document not found.")
        # The role of the current user in the ta table must be admin, owner, dataset_operator, or editor
        if not current_user.is_dataset_editor:
            raise Forbidden()
        try:
            DatasetService.check_dataset_permission(dataset, current_user, session)
        except services.errors.account.NoPermissionError as e:
            raise Forbidden(str(e))
        segment_id_str = str(segment_id)
        segment_ref, _ = _get_segment_for_document(session, dataset, document, segment_id_str)
        child_chunk_id_str = str(child_chunk_id)
        child_chunk = SegmentService.get_child_chunk_by_segment_ref(child_chunk_id_str, segment_ref, session=session)
        if not child_chunk:
            raise NotFound("Child chunk not found.")
        try:
            SegmentService.delete_child_chunk(child_chunk, dataset, session)
        except ChildChunkDeleteIndexServiceError as e:
            raise ChildChunkDeleteIndexError(str(e))
        return "", 204

    @setup_required
    @login_required
    @account_initialization_required
    @cloud_edition_billing_resource_check("vector_space")
    @cloud_edition_billing_rate_limit_check("knowledge")
    @console_ns.doc(params=SegmentDocParams.DATASET_DOCUMENT_CHILD_CHUNK)
    @console_ns.expect(console_ns.models[ChildChunkUpdatePayload.__name__])
    @console_ns.response(200, "Child chunk updated successfully", console_ns.models[ChildChunkDetailResponse.__name__])
    @with_current_user
    @with_current_tenant_id
    @rbac_permission_required(RBACResourceScope.DATASET, RBACPermission.DATASET_EDIT)
    @with_session

View on GitHub (pinned to ef8544b173)

Solutions

  1. Treat a 404 on delete as success if the goal was removal (the chunk is already gone).
  2. Refresh the child-chunk list to confirm current ids before deleting.
  3. Guard against concurrent deletes with a UI lock or re-fetch before the destructive call.

Example fix

// before
DELETE .../child_chunks/{already_deleted_id}  -> 404
// after
GET .../child_chunks  -> list current ids
if id present: DELETE .../child_chunks/{id}
else: no-op (already removed)
Defensive patterns

Strategy: try-catch

Validate before calling

async function deleteChildChunkIfPresent(ids) {
  const list = await fetch(`/console/api/datasets/${ids.datasetId}/documents/${ids.documentId}/segments/${ids.segmentId}/child_chunks`).then(r => r.json());
  if (!(list.data || []).some(c => c.id === ids.childChunkId)) return {skipped: true};
  return fetch(`/console/api/datasets/${ids.datasetId}/documents/${ids.documentId}/segments/${ids.segmentId}/child_chunks/${ids.childChunkId}`, {method: 'DELETE'});
}

Type guard

const isValidChildChunkId = (id) => typeof id === 'string' && /^[0-9a-fA-F-]{36}$/.test(id);

Try / catch

try { await deleteChildChunk(ids); }
catch (e) { if (e.status === 404 && /Child chunk not found/.test(e.message)) return; /* idempotent success */ throw e; }

Prevention

When it happens

Trigger: DELETE .../child_chunks/{child_chunk_id} where the child chunk was already removed, belongs to a different segment, or the id is wrong.

Common situations: Double-delete from a UI that did not refresh; concurrent delete by another user; id mismatch after re-segmentation.

Related errors


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