Skip to content

[Bug] Notes-summary cache hit crashes (500) — reads buffer.length after buffer is set to null #1728

Description

@vedant7007

Description

Re-summarizing a PDF that's already cached crashes with a 500: the cache-hit branch reads buffer.length after buffer has been set to null.

backend/controllers/notesSummaryController.js (~L145-156):

const fileSize = buffer.length;      // L145 — correct, captured before nulling
const base64Data = buffer.toString("base64");
buffer = null;                       // L147 — memory released
const existingSummary = await NotesSummary.findOne({ contentHash });
if (existingSummary) {
  return res.status(200).json({
    ...
    fileSize: buffer.length,         // L156 — TypeError: Cannot read properties of null (reading 'length')

Steps to Reproduce

Summarize any PDF whose contentHash already has a saved NotesSummary (i.e. anyone previously summarized that exact file) via POST /api/notes-summary/summarize. Execution enters the cache-hit branch and hits buffer.length on L156TypeError → caught by the outer handler → 500 "Failed to summarize notes." So the dedup/cache optimization breaks summarization for a perfectly valid PDF.

Root cause

When buffer = null (memory release) was introduced, the cache-hit branch wasn't updated. The non-cache success path (L234) already correctly uses the fileSize const.

Fix

Line 156 → fileSize, (use the const captured at L145) instead of fileSize: buffer.length.

Happy to fix if assigned.

Contributing as part of Elite Coders Summer of Code (ECSoC 2026).

Metadata

Metadata

Labels

claimedThis issue has been claimed by a contributor

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions