Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read properties of undefined (reading 'role') #3732

Open
3 tasks done
fulco813 opened this issue Jan 15, 2025 · 15 comments
Open
3 tasks done

Cannot read properties of undefined (reading 'role') #3732

fulco813 opened this issue Jan 15, 2025 · 15 comments
Assignees
Labels
area:chat Relates to chat interface area:indexing Relates to embedding and indexing ide:jetbrains Relates specifically to JetBrains extension kind:bug Indicates an unexpected problem or unintended behavior

Comments

@fulco813
Copy link

fulco813 commented Jan 15, 2025

Before submitting your bug report

Relevant environment info

- OS: MacOS
- Continue version: 0.0.85
- IDE version: IntelliJ 2024.3.1
- Model: Ollama
- config.json:
  
{
  "models": [
    {
      "title": "Qwen2",
      "provider": "ollama",
      "model": "qwen2:latest",
      "apiBase": "http://127.0.0.1:11434"
    }
  ],
  "tabAutocompleteModel": {
    "title": "Starcoder2",
    "provider": "ollama",
    "model": "starcoder2:latest",
    "apiBase": "http://127.0.0.1:11434"
  },
  "contextProviders": [
    {
      "name": "code",
      "params": {}
    },
    {
      "name": "docs",
      "params": {}
    },
    {
      "name": "diff",
      "params": {}
    },
    {
      "name": "terminal",
      "params": {}
    },
    {
      "name": "problems",
      "params": {}
    },
    {
      "name": "folder",
      "params": {}
    },
    {
      "name": "codebase",
      "params": {}
    }
  ],
  "slashCommands": [
    {
      "name": "share",
      "description": "Export the current chat session to markdown"
    },
    {
      "name": "cmd",
      "description": "Generate a shell command"
    },
    {
      "name": "commit",
      "description": "Generate a git commit message"
    }
  ]
}

Description

I ran the latest code and when trying to talk to the local model I got the following error:
image

TcpMessenger.ts:80

Error running handler for "llm/streamChat": 
TypeError: Cannot read properties of undefined (reading 'role') at xUt 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1627:1562) at FyA._compileChatMessages 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1629:6103) at FyA.streamChat 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1661:256) at streamChat.next (<anonymous>) at u 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8779:7151) at process.processTicksAndRejections 
(node:internal/process/task_queues:95:5) at async 
/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8784:1054 {stack: "TypeError: Cannot read properties 
of undefined (re…TypeScript/continue/binary/out/index.js:8784:1054", message: "Cannot read properties of undefined 
(reading 'role')"}

And when I run [Start Core Dev Server],I got this error:

CodebaseIndexer.ts:305

Error: Failed to generate embeddings for 19 chunks with provider: A::all-MiniLM-L6-v2::500: Error: `local_files_only=true` 
or `env.allowRemoteModels=false` and file was not found locally at 
"/Users/fulco/Desktop/Project/TypeScript/continue/binary/models/all-MiniLM-L6-v2/tokenizer.json". at D0e.getEmbeddings 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8022:1239) at process.processTicksAndRejections 
(node:internal/process/task_queues:95:5) at async D0e.computeRows 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8022:410) at async D0e.update 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8022:2909) at async zQA.indexFiles 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8747:4909) at async zQA.refreshDirs 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8747:2993) at async $QA.refreshCodebaseIndex 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8779:14577) {stack: "Error: Failed to generate 
embeddings for 19 chunks…peScript/continue/binary/out/index.js:8779:14577)", message: "Failed to generate embeddings 
for 19 chunks with p…e/binary/models/all-MiniLM-L6-v2/tokenizer.json".", cause: Error: `local_files_only=true` or 
`env.allowRemoteModels=false` and file was not found locally at "…}

To reproduce

No response

Log output

/usr/local/bin/node /Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js
Debugger listening on ws://127.0.0.1:58541/108920eb-93c1-4708-8421-9eaf00986a7a
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
[binary] Waiting for connection
Server listening on port 3000
[binary] Connected
[binary] Core started
Chunk to delete wasn't found in the table:  file:///Users/fulco/Desktop/Project/TypeScript/continue/manual-testing-sandbox/.idea
Chunk to delete wasn't found in the table:  file:///Users/fulco/Desktop/Project/TypeScript/continue/manual-testing-sandbox/nested-folder
error when indexing:  Error: Failed to generate embeddings for 19 chunks with provider: A::all-MiniLM-L6-v2::500: Error: `local_files_only=true` or `env.allowRemoteModels=false` and file was not found locally at "/Users/fulco/Desktop/Project/TypeScript/continue/binary/models/all-MiniLM-L6-v2/tokenizer.json".
    at D0e.getEmbeddings (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8022:1239)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async D0e.computeRows (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8022:410)
    at async D0e.update (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8022:2909)
    at async zQA.indexFiles (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8747:4909)
    at async zQA.refreshDirs (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8747:2993)
    at async $QA.refreshCodebaseIndex (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8779:14577) {
  [cause]: Error: `local_files_only=true` or `env.allowRemoteModels=false` and file was not found locally at "/Users/fulco/Desktop/Project/TypeScript/continue/binary/models/all-MiniLM-L6-v2/tokenizer.json".
      at xUA (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:6761:17581)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async mV (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:6761:18487)
      at async Promise.all (index 0)
      at async GMn (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:6762:9884)
      at async kp.from_pretrained (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:6777:11279)
      at async Promise.all (index 0)
      at async Ics (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:6777:12887)
      at async ccs (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:6777:12484)
      at async A.getInstance (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:6777:32647)
}
Indexing failed with error:  Error: Failed to generate embeddings for 19 chunks with provider: A::all-MiniLM-L6-v2::500: Error: `local_files_only=true` or `env.allowRemoteModels=false` and file was not found locally at "/Users/fulco/Desktop/Project/TypeScript/continue/binary/models/all-MiniLM-L6-v2/tokenizer.json". D0e.getEmbeddings, async D0e.computeRows, async D0e.update, async zQA.indexFiles, async zQA.refreshDirs, async $QA.refreshCodebaseIndex
Error running handler for "llm/streamChat":  TypeError: Cannot read properties of undefined (reading 'role')
    at xUt (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1627:1562)
    at FyA._compileChatMessages (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1629:6103)
    at FyA.streamChat (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1661:256)
    at streamChat.next (<anonymous>)
    at u (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8779:7151)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8784:1054
TypeError: Cannot read properties of undefined (reading 'role')
    at xUt (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1627:1562)
    at FyA._compileChatMessages (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1629:6103)
    at FyA.streamChat (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1661:256)
    at streamChat.next (<anonymous>)
    at u (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8779:7151)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8784:1054
Error running handler for "llm/streamChat":  TypeError: Cannot read properties of undefined (reading 'role')
    at xUt (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1627:1562)
    at FyA._compileChatMessages (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1629:6103)
    at FyA.streamChat (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1661:256)
    at streamChat.next (<anonymous>)
    at u (/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8779:7151)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8784:1054
@dosubot dosubot bot added area:chat Relates to chat interface area:indexing Relates to embedding and indexing ide:jetbrains Relates specifically to JetBrains extension kind:bug Indicates an unexpected problem or unintended behavior labels Jan 15, 2025
@AfterStories
Copy link

AfterStories commented Jan 20, 2025

Very confusing, I got the same error again.chat feature can't work
This time, I cleared the cache in intellij and nothing worked

TypeError: Cannot read properties of undefined (reading 'role')
    at e6t (C:\Users\hzheng057\Desktop\Code\Continue-Main\continue\binary\out\index.js:1627:1562)
    at EWt._compileChatMessages (C:\Users\hzheng057\Desktop\Code\Continue-Main\continue\binary\out\index.js:1629:5951)
    at EWt.streamChat (C:\Users\hzheng057\Desktop\Code\Continue-Main\continue\binary\out\index.js:1661:356)
    at streamChat.next (<anonymous>)
    at u (C:\Users\hzheng057\Desktop\Code\Continue-Main\continue\binary\out\index.js:8780:7194)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async C:\Users\hzheng057\Desktop\Code\Continue-Main\continue\binary\out\index.js:8785:1054



Image

I mainly did the following operations, and this error occurred :

  1. currently step code, running everything ok, not show error about role.

  2. pull new code from main, run ./scripts/install-dependencies.sh to install all dependencies for re-build, then run continue in intellij

  3. found the new main code has others issues,cause the chat failed ( Something went wrong: Cannot read properties of undefined (reading 'filter') #3782 ), so restore back to last commit by git

  4. now, back to the same code with step1, reinstall all dependencies for compilation

  5. chat send questions, show error about can't find role

  6. I try to create a new folder, clone the code in step 1 (it worked fine before), install all dependencies, run plugin, send question on chat webview, but the error message still appears: cannot find role

so,this means that the problem is not in the code project directory, but exists in some kind of public cache? This cache will be used during compilation, which may cause errors ? Even in the new cloned folder . Does the session or history exist in the cache of IntelliJ or Gradle??

I suspect that it was the failed chat that caused the plugin to fail to record the session properly, or an error occurred in the history record, causing this problem,Because I have rolled back the code to the last submission,The only difference is that before fallback code, there was a chat failure error in chat test

Even if I rolled back the code, when I sent the question again, the plugin might read the previous record from the session or history, and it could not read it properly, resulting in the error that the role could not be found

So, it seems that if a chat fails unexpectedly, the role error will appear the next time the question is sent.

I think history and session exists in the .continue-debug directory, so I tried to delete this directory before starting the plugin, but it didn't work, and it still reported an error that the role could not be found. How can I clear all the previous chat sessions or histories to verify my suspicion? Are they stored in the local storage in the webview?

@Patrick-Erichsen
@RomneyDa

This is my speculation, maybe the problem is not caused by history, please help to check it ,I know I often disturb you guys, Im so sorry, but I have encountered this problem many times, I hope it can be taken seriously

@AfterStories
Copy link

AfterStories commented Jan 20, 2025

Some debug reference information I think it is the reason of this issue , but maybe the code I checked below is not necessarily the cause of the problem, FYI:

According the error message , I tried to find the location of the error code, it is in \binary\out\index.js:1627:1562,
this is the compiled build code that can't be read normally, but according to the location provided by the error information,
the error code is:

.[0].role==="system"

After searching, I found that this code exists in core\llm\countTokens.ts Line 398

if (
(systemMessage && systemMessage.trim() !== "") ||
msgs?.[0].role === "system"
) {

@AfterStories
Copy link

AfterStories commented Jan 21, 2025

Image
I saw your fix bug PR had merged #3788, so I merged the latest main branch into my dev branch. And send question in chat box, but the error still here . Not only does the error message popup in the right bottom corner ,now there is also a popup on the UI showing the error message.

And , When I close the roles error message window and send the question again and again for many tests , sometime the role error message will not show , but the streaming API request only return only the first chunk data, then the request is stopped.

but sometimes role error appear, not call API ,so maybe this behavior seems really weird. It seems maybe two different phenomena caused by the same root problem.

when the the role error message not show,The message I post to API :
Image
then get stream chunk return from API
Image

only return a word "good" , then Stream request was stopped,It seems that the plugin actively closes the stream
I can be sure that there is no problem with my stream API, it works fine in any other client
Image

Actually, before you made this fix, my code was working fine (step 1 in my previous commit).
So I guess the ‘filter error’ caused some kind of wrong cache , then the wrong cache caused the ‘role error’

If the code is indeed no problem, is it possible that a compilation cache errors exists in may local , causing me to build incorrect results even though I use new code later, leading to this problem?

@Patrick-Erichsen

@fulco813
Copy link
Author

Same error after I merged the latest branch:

Image
TypeError: Cannot read properties of undefined (reading 'role') at r6t 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1619:1566) at xyA._compileChatMessages 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1621:6018) at xyA.streamChat 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:1653:356) at streamChat.next (<anonymous>) at u 
(/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8779:7069) at process.processTicksAndRejections 
(node:internal/process/task_queues:95:5) at async 
/Users/fulco/Desktop/Project/TypeScript/continue/binary/out/index.js:8784:1046 {stack: "TypeError: Cannot read properties of 
undefined (re…TypeScript/continue/binary/out/index.js:8784:1046", message: "Cannot read properties of undefined (reading 
'role')"}

@AfterStories
Copy link

AfterStories commented Jan 21, 2025

@fulco813
Have you ever had some unexpected errors in the chat feature ? maye without try catch to handle it, then there will be show this error about role.
I'm guessing this is related to unexpected chat errors causing history or session storage errors or failures, but I can't be sure the reason

@AfterStories
Copy link

AfterStories commented Jan 21, 2025

I just did a test to verify my guess that "some kind of wrong compilation cache" caused the error ,FYI

  1. I created a new folder called New , cloned the source code of the main branch
  2. Create a new project in IntelliJ and load the New folder
  3. Configure the API URL to my API
  4. Run ./scripts/install-dependencies.sh , then Run Continue task
    Can see the log shows that many gradle dependency packages are downloaded
  5. The plugin starts and runs good
    And you can see some logs in the Run Extension task:
> Task :processResources
> Task :compileKotlin
> Task :compileKotlin UP-TO-DATE
> Task :compileJava NO-SOURCE
> Task :classes
> Task :instrumentCode
> Task :instrumentedJar
> Task :jar
> Task :prepareSandbox

For comparison:

  1. The project in the Old folder that I customized dev , branch: dev_old , it has been running good before,
  2. merge origin/main into dev_old branch > run ./scripts/install-dependencies.sh > Run Continue task
  3. show ‘filter error’ that you had fixed(Something went wrong: Cannot read properties of undefined (reading 'filter') #3782),
  4. Roll back the code to before the merge, run ./scripts/install-dependencies.sh again > Run Continue task again
  5. In the UI, it still shows Somethin wet wrong: can't read filter
    (Why is this error cached in the UI even I have restart plugin?) Then I clicked ‘restart’ button to refresh the UI
  6. Send the question in chat box, show error : Cannot read properties of undefined (reading 'role')
  7. Create another folder, clone dev_old branch, install dependencies and run plugin
  8. Still show: Cannot read properties of undefined (reading 'role')

Log of Run Extension, you can see something like the following, the compilation is from cache:

> Task :processResources
> Task :compileKotlin
> Task :compileKotlin  FROM-CACHE
> Task :compileJava  FROM-CACHE
> Task :classes
> Task :instrumentCode
> Task :instrumentedJar
> Task :jar
> Task :prepareSandbox

As you can see, there are some FROM-CACHE, which shows that it is compiled from the cache. Even if I clone the same dev_old branch code in another folder, it seems to still build the same result.

But in the New folder, I just use origin/main branch code , it works very fine.

Through this phenomenon, I can think of two possibilities:

  1. Is there some state data cached in the React App in Gui?
    Because I saw that in step 5, after restarting the plug-in, the error prompt is still displayed in the UI.

If the React App State data of the GUI is cached, then the state may store broken/incorrectly formatted/wrong history session data. When an unexpected error occurs (such as filter error), the wrong session history data reads the history to build the chat data, resulting in msg being an empty array, a role error.

2 Gradle-related dependency packages are stored in C://username/.gradle of windows computer

It seems to be shared by all projects. As long as the gradle-related configuration uses the corresponding dependency package, it will be obtained from here.
Is there any cache here, causing the directory where the dev_old code exists to refer to the broken cache for construction when it is running.

Maybe my idea is completely wrong, just for reference information

@AfterStories
Copy link

AfterStories commented Jan 22, 2025

My latest debug information, hope it helps:
gui\src\redux\thunks\streamResponse.ts Line 120
const updatedHistory = getState().session.history;

I found that when role error occurs, history is obtained from session in this code, but get the empty array updatedHistory = [ ]

Therefore, the history in the messages variable constructed by the constructMessages method is also empty, causing the subsequent streamNormalInput method to use an empty message
Line 138: unwrapResult(await dispatch(streamNormalInput(messages)));

My idea is, if there has been an unexpected error chat, there is no exception handling, and the wrong session is recorded (such as #3782, I had the role error after this 'filter' error)

After this, even if I rebuild/restart the plugin, the session still exists and get empty array updatedHistory = [ ] when send question,so can't find role in empty history array

@AfterStories
Copy link

Now I think it is indeed some kind of session cache in the plugin, because I found that when I deleted the entire folder C:\Users\username\.continue, if the session data existed in it, all the chat data should have been cleared.

But when I packaged the new code as installation zip package , and installed it again in an intellij IDEA, the old chat data was still displayed ! This means that the old session data is not stored in C:\Users\username\.continue

This makes me more suspicious that the role problem is due to an unexpected chat error , and a broken session has been stored, so when a new question is asked, an empty array is obtained when obtaining the history message, and the role cannot be read.

@Patrick-Erichsen
Copy link
Collaborator

@RomneyDa I believe this may be related to a session titles bug you recently fixed?

@AfterStories
Copy link

AfterStories commented Jan 24, 2025

Hi , @RomneyDa Thanks you!
I saw you said that this issue will be fixed in #3725
But I saw that #3725 was merged earlier than when we reported the bug, so I think our code should have included the updated code you fixed. right? but we still occurred this error...
Or ... do you mean that to fix this 'role' error , need all of these together?
#3725
#3805
#3809
#3810
#3811

Could you please give a brief explanation of what caused this role error? Because it feels so strange...When I was testing, I found that if I ignored this role error and sent the question again, there is a certain probability that the role error will not occur, but the stream request will only return the first data fragment and then the stream will be stopped, and no return data will be displayed in the UI.

Then I cloned code to a new folder again and started local debugging. This problem did not occur, everything good. But after I packaged it into an installation package and sent it to a friend to install it in intellij, he role error appeared again on his computer.

@AfterStories
Copy link

AfterStories commented Jan 24, 2025

I may have found a temporary solution to this issue, as I mentioned before, I suspect the plugin has some kind of cache,
because even if I uninstall the plugin,
deleted the C:\Users\username\.continue folder,
restarted IntelliJ,

installed the plugin again. the previous chat history was still displayed again(Chat was available before),
but now it show role error message when send question

so I want to clear the cache manually because I think there may be some corrupted cache that caused this role problem and the problem of the stream being terminated for unknown reasons

Then I found , In my project folder opened by IntelliJ, there is a .idea\settings\system\plugins\ folder, which there is a zip file that seems to be related to the plugin:
\.idea\settings\system\plugins\continue-intellij-extension.zip

So I try to delete this file, and installed the plugin again, the Chat feature running good without any problems.

But I see that the contents of this zip package are the same as the installation package. Maybe its existence will cause some errors in IntelliJ cache?

@AfterStories
Copy link

AfterStories commented Jan 24, 2025

@RomneyDa I believe this may be related to a session titles bug you recently fixed?

I don't think this is related to the session title. When the chat is error, the session title generated in the chat history panel.

@Patrick-Erichsen
Copy link
Collaborator

@AfterStories you're still getting the role error after a clean uninstall/reinstall?

@RomneyDa
Copy link
Collaborator

@AfterStories you were right, the above PRs fixed messaging logic but not this specific error. This one is fixed here per your bug find
https://github.com/continuedev/continue/pull/3884/files

@AfterStories
Copy link

AfterStories commented Jan 29, 2025

Thank you so much for your still attention to this report. I noticed that in https://github.com/continuedev/continue/pull/3884/files, you enhance the readability of the msgs array.

I'm glad to see your reply. and now I'm currently on holidays, so I think I will do more tests to verify this fix, maybe next week.

I still suspect the root cause of the problem is: why does it generate such an empty msgs array when running in IntelliJ? The same code in core layer, the plugin running in vscode has never occurred this problem.

Because as I mentioned above, this problem is likely to probabilistic, not sure whether just enhancing the readability in countTokens.ts can really solve the root problem.
the same installation package by the ./gradlew buildPlugin ,It worked fine on my computer, but there was a problem on my friend's computer : the first time to sent a streaming request, only the first chuck data was returned and the streaming was stopped. UI not display anything,then sent a request again, a role error message appeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:chat Relates to chat interface area:indexing Relates to embedding and indexing ide:jetbrains Relates specifically to JetBrains extension kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants