fix: engine cannot give response to the second user request with stre…#701
fix: engine cannot give response to the second user request with stre…#701lihaiyin88 wants to merge 1 commit intomlc-ai:mainfrom
Conversation
|
thanks a lot for the contribution. Would it be possible for you to provide a script for reproducing the issue / elaborate on the issue? Thank you! |
There was a problem hiding this comment.
Pull Request Overview
This PR restructures the streaming generation method in MLCEngine to ensure the model lock is always released once, fixing an issue where the engine could not handle a second streaming request.
- Flattened multiple nested
try/catchblocks into a singletry+finallyaround the main logic. - Converted inner helper functions (
_countTrailingReplacementChar,_getChunk) to arrow function expressions. - Removed redundant
lock.release()calls spread across catches; now released once infinally.
Comments suppressed due to low confidence (2)
src/engine.ts:706
- This TODO is still open—either implement the usage support for non-chat completions or file a tracking issue to ensure it isn't overlooked.
// TODO(Charlie): support usage for completion
src/engine.ts:483
- Add a test case that performs two consecutive streaming requests (with and without errors) to verify the lock is always released and reacquired correctly.
genConfig: GenerationConfig,
| // Since it is an async generator, we need to do fine-grained try-catch to ensure lock is | ||
| // released only when errors occur. Then release at the very end when no error occurs. | ||
| // TODO: This makes code less readable, is there a better way to do this? | ||
| const lock = this.loadedModelIdToLock.get(model)!; |
There was a problem hiding this comment.
Consider adding a brief comment above this try/finally to clarify its scope is for lock acquisition and release, improving future readability.
| const lock = this.loadedModelIdToLock.get(model)!; | |
| const lock = this.loadedModelIdToLock.get(model)!; | |
| // Acquire the lock and ensure its release in the `finally` block. |
Hey there! So sorry for the super late reply! 😊 |
see title