Repository navigation
Fix OpenAI tool format overrides (Fixes #1943) #1949
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
packages/cli/src/runtime/providerMutations.issue1943.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /** | ||
| * @issue #1943 - /toolformat is not persisted into profile ephemerals | ||
| * | ||
| * Behavioral tests for setActiveToolFormatOverride() writing to both | ||
| * SettingsService AND Config ephemeral settings, so the tool-format value | ||
| * is captured during profile saves. | ||
| * | ||
| * Before the fix, only settingsService.updateSettings() was called. | ||
| * After the fix, config.setEphemeralSetting('tool-format', value) is also called, | ||
| * mirroring the pattern used by updateActiveProviderBaseUrl. | ||
| */ | ||
|
|
||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
|
|
||
| const mockConfig = { | ||
| setEphemeralSetting: vi.fn(), | ||
| getEphemeralSetting: vi.fn().mockReturnValue(undefined), | ||
| }; | ||
|
|
||
| const mockSettingsService = { | ||
| updateSettings: vi.fn().mockResolvedValue(undefined), | ||
| getProviderSettings: vi.fn().mockReturnValue({}), | ||
| }; | ||
|
|
||
| const mockProviderManager = { | ||
| getActiveProvider: vi.fn().mockReturnValue({ name: 'openai' }), | ||
| getActiveProviderName: vi.fn().mockReturnValue('openai'), | ||
| }; | ||
|
|
||
| vi.mock('./runtimeAccessors.js', () => ({ | ||
| getCliRuntimeServices: () => ({ | ||
| config: mockConfig, | ||
| settingsService: mockSettingsService, | ||
| providerManager: mockProviderManager, | ||
| }), | ||
| _internal: { | ||
| getActiveProviderOrThrow: () => ({ name: 'openai' }), | ||
| getProviderSettingsSnapshot: () => ({}), | ||
| }, | ||
| })); | ||
|
|
||
| import { setActiveToolFormatOverride } from './providerMutations.js'; | ||
|
|
||
| describe('setActiveToolFormatOverride ephemeral persistence (issue #1943)', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mockSettingsService.getProviderSettings.mockReturnValue({}); | ||
| }); | ||
|
|
||
| it('writes "openai" to config.setEphemeralSetting when setting toolFormat to "openai"', async () => { | ||
| await setActiveToolFormatOverride('openai'); | ||
|
|
||
| expect(mockSettingsService.updateSettings).toHaveBeenCalledWith('openai', { | ||
| toolFormat: 'openai', | ||
| }); | ||
| expect(mockConfig.setEphemeralSetting).toHaveBeenCalledWith( | ||
| 'tool-format', | ||
| 'openai', | ||
| ); | ||
| }); | ||
|
|
||
| it('writes "auto" to config.setEphemeralSetting when clearing override', async () => { | ||
| await setActiveToolFormatOverride(null); | ||
|
|
||
| expect(mockSettingsService.updateSettings).toHaveBeenCalledWith('openai', { | ||
| toolFormat: 'auto', | ||
| }); | ||
| expect(mockConfig.setEphemeralSetting).toHaveBeenCalledWith( | ||
| 'tool-format', | ||
| 'auto', | ||
| ); | ||
| }); | ||
|
|
||
| it('writes "auto" to config.setEphemeralSetting when explicitly setting to "auto"', async () => { | ||
| await setActiveToolFormatOverride('auto'); | ||
|
|
||
| expect(mockSettingsService.updateSettings).toHaveBeenCalledWith('openai', { | ||
| toolFormat: 'auto', | ||
| }); | ||
| expect(mockConfig.setEphemeralSetting).toHaveBeenCalledWith( | ||
| 'tool-format', | ||
| 'auto', | ||
| ); | ||
| }); | ||
|
|
||
| it('writes "kimi" to config.setEphemeralSetting when setting toolFormat to "kimi"', async () => { | ||
| await setActiveToolFormatOverride('kimi'); | ||
|
|
||
| expect(mockSettingsService.updateSettings).toHaveBeenCalledWith('openai', { | ||
| toolFormat: 'kimi', | ||
| }); | ||
| expect(mockConfig.setEphemeralSetting).toHaveBeenCalledWith( | ||
| 'tool-format', | ||
| 'kimi', | ||
| ); | ||
| }); | ||
|
|
||
| it('calls both settingsService and config (mirrors updateActiveProviderBaseUrl pattern)', async () => { | ||
| await setActiveToolFormatOverride('openai'); | ||
|
|
||
| // Both should be called exactly once | ||
| expect(mockSettingsService.updateSettings).toHaveBeenCalledTimes(1); | ||
| expect(mockConfig.setEphemeralSetting).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: vybestack/llxprt-code
Length of output: 268
🏁 Script executed:
Repository: vybestack/llxprt-code
Length of output: 15754
🏁 Script executed:
Repository: vybestack/llxprt-code
Length of output: 4593
🏁 Script executed:
Repository: vybestack/llxprt-code
Length of output: 22172
🌐 Web query:
Node.js IncomingMessage close event complete property res.complete premature connection closed promise resolve finish pipe file never finish hang💡 Result:
In Node.js, the
IncomingMessage.completeproperty is a boolean that indicates whether an HTTP message was fully received and successfully parsed [1][2]. It is commonly used to detect if a connection was terminated prematurely (i.e., before the complete message was delivered) by checking its value during thecloseevent [1][3]. Handling premature connection closures and stream hangs requires understanding how Node.js manages HTTP streams: 1. Detecting Premature Closure: You can checkres.completeinside thecloseevent listener to determine if the message was truncated [1][3]. Ifres.completeis false, the connection was likely terminated unexpectedly [1][2].javascript res.on('close', () => { if (!res.complete) { console.error('The connection was terminated while the message was still being sent'); } });2. Avoiding Stream Hangs: Usingres.pipe(destination)can lead to issues where the destination stream does not finish if the source (IncomingMessage) encounters a premature closure [3][4]. Since Node.js 13.0,res.pipe()may not automatically calldst.end()if the response is truncated [3]. 3. Recommended Practices: - Usestream.pipelineinstead of manual.pipe()calls [3][4].stream.pipelineis designed to handle cleanup, errors, and premature closures automatically, ensuring that errors are propagated and resources are not leaked [3]. - If you are waiting for a process to complete, rely onstream.finishedor thefinishevent of the destination stream rather than just theendevent of theIncomingMessage[4]. - If your application involves complex streaming (e.g., pipelines where you need to detect errors early), verify if you are accidentally destroying theIncomingMessage(often viafor awaitloops or manual socket destruction), which can prevent proper completion events [5]. If you find that your application hangs or does not finish, ensure that you are not manually handlingendevents in a way that ignorescloseorerrorevents, as a premature closure will emitclosebut may not emitendorfinishin the expected manner [3][6][7]. Using modern stream utilities helps maintain consistent behavior across different Node.js versions [3].Citations:
🌐 Web query:
@types/node IncomingMessage complete boolean property💡 Result:
In the Node.js TypeScript definitions provided by
@types/node, the IncomingMessage interface includes a boolean property named complete [1][2]. The message.complete property indicates whether a complete HTTP message has been received and successfully parsed [2][3]. It is commonly used to verify if a client or server fully transmitted a message before the connection was terminated [2][4]. For example, when listening for the end event on an IncomingMessage object, you can check this property to detect incomplete transfers [2][5]: const req = http.request({ /*... */ }, (res) => { res.resume; res.on('end', => { if (!res.complete) { console.error('The connection was terminated while the message was still being sent'); } }); }); This property has been part of the Node.js http module since version 0.3.0 [2][6].Citations:
Handle premature HTTP response closes in
downloadFile()downloadFile()settles only onfile.on('finish')(resolve) andfile/res'error'(reject). If the server/socket closes mid-transfer without triggering'error', there’s no'close'/'aborted'handler, so the Promise can hang and leave a partial file.Proposed fix
// Handle response stream errors res.on('error', (err) => { cleanupAfterFileClosed(file, err, cleanupAndReject); }); + res.on('close', () => { + if (!res.complete && !settled) { + cleanupAfterFileClosed( + file, + new Error('Download connection closed before completion'), + cleanupAndReject, + ); + } + }); res.pipe(file); file.on('finish', () => { if (!settled) { settled = true; file.close(resolve as () => void); }📝 Committable suggestion
🤖 Prompt for AI Agents