nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] File context attachments read directly from disk, ignoring unsaved editor buffers

Open akramcodez opened this issue 1 month ago • 1 comments

Description

When expanding context attachments (e.g. @[file] path/to/file), readCappedFile() reads the file from the filesystem using Node's fs.statSync and fs.readSync. If the user has made unsaved edits in an active VS Code editor, those changes are completely ignored and the LLM receives outdated disk contents.

Environment

  • OS: Linux (reviewed); macOS / Windows potentially affected
  • Node version: >= 22.0.0
  • Nanocoder version: 1.31.0

Steps to Reproduce

  1. Open a file in VS Code and make edits without saving.
  2. In the Nanocoder chat box, type @filename, select the matching file from the completion dropdown, then submit a question about the unsaved contents.
  3. Observe the response.

Expected Behavior

The extension should check vscode.workspace.textDocuments first. If an open document matches the file path, its in-memory buffer (doc.getText()) should be used (subject to the same byte cap), falling back to disk only if the document is not open in VS Code.

Actual Behavior

The extension reads directly from the filesystem, sending the unedited file content to the model.

Additional Context

  • [x] No matching open issue found in issue search performed on 2026-10-12
  • [x] Relevant code paths inspected at commit d5ff9c37

Implementation Notes (optional)

  • Files:
    • plugins/vscode/src/chat-webview-provider.ts:796-825
    • plugins/vscode/src/context-attachment.ts:38-65
  • Prioritize vscode.workspace.textDocuments.find(d => d.uri.fsPath === filePath)?.getText() over readCappedFile.
  • Apply the same MAX_CONTEXT_FILE_BYTES cap to the in-memory buffer content.

akramcodez avatar Oct 12 '26 11:10 akramcodez

hey @akramcodez @addyCooks , would like to work on this could you please assign this to me.

karthikponna avatar Oct 12 '26 12:10 karthikponna