Tencent/WeKnora · error

attachment %s was not found in this session

Error message

attachment %s was not found in this session

What it means

ResolveForPrompt looks up each document via repo.GetScoped(tenantID, sessionID, documentID). GetScoped may return (nil, nil) — the document exists nowhere visible to this tenant/session — so the service reports the attachment as not found in this session.

Source

Thrown at internal/application/service/temporary_document.go:617

	if len(documentIDs) > types.MaxTemporaryAttachmentsPerMessage {
		return nil, fmt.Errorf("a message can use at most %d attachments", types.MaxTemporaryAttachmentsPerMessage)
	}
	perDocumentBudget := temporaryDocumentPromptBudget
	if len(documentIDs) > 0 {
		perDocumentBudget = temporaryDocumentPromptBudget / len(documentIDs)
	}
	seen := make(map[string]struct{}, len(documentIDs))
	for _, documentID := range documentIDs {
		if _, duplicate := seen[documentID]; duplicate {
			continue
		}
		seen[documentID] = struct{}{}
		document, err := s.repo.GetScoped(ctx, tenantID, sessionID, documentID)
		if err != nil {
			return nil, err
		}
		if document == nil {
			return nil, fmt.Errorf("attachment %s was not found in this session", documentID)
		}
		if document.Status != types.TemporaryDocumentStatusReady {
			if document.Status == types.TemporaryDocumentStatusFailed {
				return nil, fmt.Errorf("attachment %s failed to parse: %s", document.FileName, document.ErrorMessage)
			}
			return nil, fmt.Errorf("attachment %s is still being processed", document.FileName)
		}
		content, selected, total := selectTemporaryDocumentContentWithBudget(document, query, perDocumentBudget)
		result.Attachments = append(result.Attachments, types.MessageAttachment{
			ID: document.ID, URL: document.ResourceRef, FileName: document.FileName,
			FileType: document.FileType, FileSize: document.FileSize, Content: content,
			ContentMode: map[bool]string{true: "full", false: "selected_chunks"}[selected == total],
			TokenCount:  document.TokenCount, SelectedChunks: selected, TotalChunks: total,
		})
		// Image-type attachments always expose their image so vision models can
		// see it directly; text documents only attach extracted images when the
		// question is visual, to avoid gratuitous multimodal latency.
		if docparser.IsImageFormat(document.FileType) || isVisualDocumentQuery(query) {

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Ensure the client sends only document IDs created in the current session
  2. Re-upload the attachment if it expired or was consumed
  3. Verify tenant/session scoping on the client side matches the lookup
  4. Check temporary document retention/cleanup settings
Defensive patterns

Strategy: validation

Validate before calling

// client: only send IDs returned by this session's upload
if !sessionUploads.Has(documentID) { skip }

Try / catch

if err != nil || doc == nil {
    if strings.Contains(fmt.Sprint(err), "was not found in this session") {
        // drop stale ID or re-upload
    }
}

Prevention

When it happens

Trigger: Calling ResolveForPrompt with a documentID that was never created in this session, belongs to another session/tenant, was garbage-collected (expired temporary document), or an already-used document consumed after its single-use lifetime.

Common situations: Client reuses document IDs from a previous session; message references attachments after temporary document TTL expiry; ID typo or cross-tenant ID leakage; document auto-deleted after prompt resolution.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/03e2a7b5c418e112. Report an issue: GitHub.