{"record":{"id":"03e2a7b5c418e112","repo":"Tencent/WeKnora","slug":"attachment-s-was-not-found-in-this-session","errorCode":null,"errorMessage":"attachment %s was not found in this session","messagePattern":"attachment (.+?) was not found in this session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/service/temporary_document.go","lineNumber":617,"sourceCode":"\tif len(documentIDs) > types.MaxTemporaryAttachmentsPerMessage {\n\t\treturn nil, fmt.Errorf(\"a message can use at most %d attachments\", types.MaxTemporaryAttachmentsPerMessage)\n\t}\n\tperDocumentBudget := temporaryDocumentPromptBudget\n\tif len(documentIDs) > 0 {\n\t\tperDocumentBudget = temporaryDocumentPromptBudget / len(documentIDs)\n\t}\n\tseen := make(map[string]struct{}, len(documentIDs))\n\tfor _, documentID := range documentIDs {\n\t\tif _, duplicate := seen[documentID]; duplicate {\n\t\t\tcontinue\n\t\t}\n\t\tseen[documentID] = struct{}{}\n\t\tdocument, err := s.repo.GetScoped(ctx, tenantID, sessionID, documentID)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif document == nil {\n\t\t\treturn nil, fmt.Errorf(\"attachment %s was not found in this session\", documentID)\n\t\t}\n\t\tif document.Status != types.TemporaryDocumentStatusReady {\n\t\t\tif document.Status == types.TemporaryDocumentStatusFailed {\n\t\t\t\treturn nil, fmt.Errorf(\"attachment %s failed to parse: %s\", document.FileName, document.ErrorMessage)\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"attachment %s is still being processed\", document.FileName)\n\t\t}\n\t\tcontent, selected, total := selectTemporaryDocumentContentWithBudget(document, query, perDocumentBudget)\n\t\tresult.Attachments = append(result.Attachments, types.MessageAttachment{\n\t\t\tID: document.ID, URL: document.ResourceRef, FileName: document.FileName,\n\t\t\tFileType: document.FileType, FileSize: document.FileSize, Content: content,\n\t\t\tContentMode: map[bool]string{true: \"full\", false: \"selected_chunks\"}[selected == total],\n\t\t\tTokenCount:  document.TokenCount, SelectedChunks: selected, TotalChunks: total,\n\t\t})\n\t\t// Image-type attachments always expose their image so vision models can\n\t\t// see it directly; text documents only attach extracted images when the\n\t\t// question is visual, to avoid gratuitous multimodal latency.\n\t\tif docparser.IsImageFormat(document.FileType) || isVisualDocumentQuery(query) {","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/service/temporary_document.go#L599-L635","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the client sends only document IDs created in the current session","Re-upload the attachment if it expired or was consumed","Verify tenant/session scoping on the client side matches the lookup","Check temporary document retention/cleanup settings"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// client: only send IDs returned by this session's upload\nif !sessionUploads.Has(documentID) { skip }","typeGuard":null,"tryCatchPattern":"if err != nil || doc == nil {\n    if strings.Contains(fmt.Sprint(err), \"was not found in this session\") {\n        // drop stale ID or re-upload\n    }\n}","preventionTips":["Track uploaded document IDs per session client-side","Re-upload after TTL expiry or single-use consumption","Never reuse IDs across sessions or tenants"],"tags":["not-found","session-scope","attachment"],"backgroundTag":"resource-not-found","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}