Skip to content

Commit ec4ddfc

Browse files
luoxuanzaoQoder-AI
andauthored
fix(qoder): upgrade agent SDK for qodercli 1.1.81 (#96)
Upgrade the embedded Qoder Agent SDK to 1.0.58, paired with qodercli 1.1.81, and adapt the plugin to the SDK's process-wide daemon: pin the process carrier, pass launch env through options, restart the daemon on CLI/config changes and login, and fix renderer timer, session-id, and first-turn restart races found in real-app testing. Co-authored-by: QoderAI (Qwen 3.8 Max) <qoder_ai@qoder.com>
1 parent cded85e commit ec4ddfc

22 files changed

Lines changed: 238 additions & 93 deletions

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ version with its date and start a fresh empty `[Unreleased]` above it.
1111

1212
## [Unreleased]
1313

14+
### Fixed
15+
16+
- Upgraded the embedded Qoder Agent SDK so it stays compatible with qodercli
17+
1.1.81.
18+
1419
## [1.0.17] - 2026-10-10
1520

1621
### Changed

‎package-lock.json‎

Lines changed: 4 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@codemirror/state": "^6.5.0",
5757
"@codemirror/view": "^6.38.6",
5858
"@modelcontextprotocol/sdk": "~1.32.1",
59-
"@qoder-ai/qoder-agent-sdk": "^1.0.45",
59+
"@qoder-ai/qoder-agent-sdk": "^1.0.58",
6060
"tslib": "^2.8.1"
6161
},
6262
"overrides": {

‎scripts/renderer-safe-unref.js‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ const UNSAFE_TIMER_UNREF_PATTERNS = [
8282
'\n closeTimeout.unref?.();' +
8383
'\n })',
8484
},
85+
{
86+
name: 'qoder-sdk-daemon-heartbeat-watchdog',
87+
pattern: /this\.heartbeatWatchdog\.unref\(\)/g,
88+
replacement: 'this.heartbeatWatchdog.unref?.()',
89+
},
8590
];
8691

8792
const TIMER_CALL_PREFIXES = ['setTimeout(', 'setInterval('];
@@ -143,7 +148,8 @@ function findUnsafeTimerUnrefSites(contents) {
143148
continue;
144149
}
145150

146-
const unrefMatch = contents.slice(callEnd + 1).match(/^\s*\.unref\(\)/);
151+
const unrefMatch = contents.slice(callEnd + 1).match(/^\s*\.unref\(\)/)
152+
?? matchAssignedTimerUnref(contents, timerStart.startIndex, callEnd);
147153
if (unrefMatch) {
148154
const startIndex = timerStart.startIndex;
149155
const endIndex = callEnd + 1 + unrefMatch[0].length;
@@ -162,6 +168,20 @@ function findUnsafeTimerUnrefSites(contents) {
162168
return matches;
163169
}
164170

171+
function matchAssignedTimerUnref(contents, timerStartIndex, callEnd) {
172+
const assignment = contents
173+
.slice(Math.max(0, timerStartIndex - 128), timerStartIndex)
174+
.match(/([A-Za-z_$][A-Za-z0-9_$.]*)\s*=\s*$/);
175+
if (!assignment) {
176+
return null;
177+
}
178+
179+
const target = assignment[1].replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
180+
return contents
181+
.slice(callEnd + 1)
182+
.match(new RegExp(`^\\s*,\\s*${target}\\.unref\\(\\)`));
183+
}
184+
165185
function findNextTimerCall(contents, startIndex) {
166186
let nextMatch = null;
167187

‎scripts/smoke-qoder-sdk.mjs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env node
22

33
import {
4+
ProcessTransport,
45
qodercliAuth,
56
query,
7+
shutdownDaemon,
68
} from '@qoder-ai/qoder-agent-sdk';
79

810
/** Idle async input used for initialization-only SDK operations. */
@@ -38,6 +40,9 @@ async function main() {
3840
cwd: process.cwd(),
3941
model: 'auto',
4042
persistSession: false,
43+
// The plugin pins the process carrier so the user's installed CLI runs;
44+
// without this the SDK starts its bundled worker runtime instead.
45+
transport: ProcessTransport.default,
4146
...(cliPath ? { pathToQoderCLIExecutable: cliPath } : {}),
4247
},
4348
});
@@ -59,6 +64,8 @@ async function main() {
5964
} finally {
6065
input.end();
6166
await catalogQuery.close();
67+
// The daemon is process-wide and keeps Node alive until it is stopped.
68+
await shutdownDaemon();
6269
}
6370
}
6471

‎src/features/settings/ui/qoder-settings-tab.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export function renderQoderCliPathControl(
136136
await view?.getTabManager()?.broadcastToAllTabs(
137137
(service) => Promise.resolve(service.cleanup())
138138
);
139+
await qoderWorkspace.shutdownRuntime();
139140
void qoderWorkspace.agentCatalog.refresh();
140141
return true;
141142
};
@@ -196,6 +197,7 @@ export function renderQoderCliEditionControl(
196197
qoderWorkspace.cliResolver.reset();
197198
await qoderWorkspace.pluginManager.loadPlugins();
198199
await context.plugin.reloadConversationIndex();
200+
await qoderWorkspace.shutdownRuntime();
199201
void qoderWorkspace.agentCatalog.refresh();
200202
});
201203
});

‎src/qoder/commands/probe-runtime-commands.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { sortThinkingEfforts } from '../models/model-catalog';
1919
import type { QoderHostContext } from '../qoder-host-context';
2020
import { createCustomSpawnFunction } from '../runtime/custom-spawn';
21+
import { buildDaemonLaunchOptions } from '../runtime/qoder-daemon-launch';
2122

2223
const STDERR_TAIL_LIMIT = 4_000;
2324

@@ -190,8 +191,7 @@ export function buildProbeOptions(
190191
cwd: vaultPath,
191192
abortController,
192193
auth: qodercliAuth(),
193-
pathToQoderCLIExecutable: cliPath,
194-
env: { ...process.env, PATH: enhancedPath },
194+
...buildDaemonLaunchOptions(cliPath, enhancedPath),
195195
permissionMode: 'bypassPermissions',
196196
allowDangerouslySkipPermissions: true,
197197
settingSources: resolveQoderSettingSources(qoderSettings.loadUserSettings),

‎src/qoder/qoder-services.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { shutdownDaemon } from '@qoder-ai/qoder-agent-sdk';
2+
13
import { getVaultPath } from '../core/fs/path';
24
import type { ChatRuntime } from '../core/runtime/chat-runtime';
35
import type { VaultFileAdapter } from '../core/storage/vault-file-adapter';
@@ -47,6 +49,12 @@ export interface QoderServices {
4749
historyService: QoderConversationHistoryService;
4850
taskResultInterpreter: QoderTaskResultInterpreter;
4951
loginService: QoderLoginService;
52+
/**
53+
* Stops the SDK's process-wide daemon. Required after CLI path/edition
54+
* changes and login, because a running daemon keeps its original launch
55+
* configuration and credentials.
56+
*/
57+
shutdownRuntime(): Promise<void>;
5058
dispose(): void;
5159
createRuntime(): ChatRuntime;
5260
createTitleGenerationService(): QoderTitleGenerationService;
@@ -111,12 +119,16 @@ export async function createQoderServices(
111119

112120
const historyService = new QoderConversationHistoryService();
113121
const taskResultInterpreter = new QoderTaskResultInterpreter();
122+
const shutdownRuntime = async (): Promise<void> => {
123+
await shutdownDaemon().catch(() => {
124+
// Best-effort: a failed shutdown must not block settings/login flows.
125+
});
126+
};
114127
const loginService = new QoderLoginService(plugin, () => {
115128
if (disposed) return;
116-
// Always return to idle once the post-login refresh settles; keeping
117-
// 'succeeded' would render a stale "checking status" panel if the runtime
118-
// later becomes authRequired again in this session.
119-
void agentCatalog.refresh().then(() => {
129+
// Credentials are written by the CLI after the daemon may already have
130+
// started, so restart the daemon before re-probing the runtime.
131+
void shutdownRuntime().then(() => agentCatalog.refresh()).then(() => {
120132
if (!disposed) loginService.reset();
121133
});
122134
});
@@ -134,8 +146,10 @@ export async function createQoderServices(
134146
historyService,
135147
taskResultInterpreter,
136148
loginService,
149+
shutdownRuntime,
137150
dispose: () => {
138151
disposed = true;
152+
void shutdownRuntime();
139153
loginService.dispose();
140154
if (startupRetryTimer !== null) {
141155
window.clearTimeout(startupRetryTimer);

‎src/qoder/runtime/custom-spawn.ts‎

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,16 @@ import type { SpawnedProcess, SpawnOptions } from '@qoder-ai/qoder-agent-sdk';
22
import { type ChildProcess, spawn } from 'child_process';
33

44
import { cliPathRequiresNode, findNodeExecutable } from '../../core/env/environment';
5+
import {
6+
CUSTOM_PROVIDER_CLI_ENV,
7+
INTEGRATION_CLI_ENV,
8+
} from './qoder-daemon-launch';
59
import {
610
resolveWindowsCmdShimSpawnSpec,
711
terminateSpawnedProcess,
812
type WindowsCmdShimSpawnSpec,
913
} from './windows-cmd-shim';
1014

11-
/**
12-
* SDK-spawned sessions run qodercli in its "sdk" runtime mode, where
13-
* CLI-configured custom providers (self-defined base URLs) stay disabled
14-
* unless this opt-in is present — without it the CLI hides their models.
15-
*/
16-
const CUSTOM_PROVIDER_CLI_ENV = { QODER_SDK_CUSTOM_BASE_URL_BYOK: '1' } as const;
17-
18-
/**
19-
* Identifies this host integration to the CLI, which reports it as the
20-
* `integration_id` telemetry attribute. Only a UUIDv4 is accepted; any other
21-
* value is silently dropped.
22-
*/
23-
const INTEGRATION_CLI_ENV = {
24-
QODER_INTEGRATION_ID: '70457212-a449-4ae3-af1e-5fb9e00fafcf',
25-
} as const;
26-
2715
/**
2816
* Spawn qodercli in Obsidian's Electron process.
2917
*

‎src/qoder/runtime/qoder-chat-runtime.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ export class QoderChatRuntime implements ChatRuntime {
198198
this.sessionManager.clearHistoryRebuild();
199199
this.pendingForkSession = false;
200200
}
201-
this.messageChannel?.setSessionId(event.sessionId);
202201
if (event.agents) {
203202
try { this.getAgentCatalog().applySessionAgents(event.agents); } catch { /* non-critical */ }
204203
}
@@ -441,7 +440,6 @@ export class QoderChatRuntime implements ChatRuntime {
441440
this.messageChannel = new QoderMessageChannel();
442441

443442
if (resumeSessionId) {
444-
this.messageChannel.setSessionId(resumeSessionId);
445443
this.sessionManager.setSessionId(resumeSessionId, this.getScopedSettings().model);
446444
}
447445

@@ -874,10 +872,14 @@ export class QoderChatRuntime implements ChatRuntime {
874872
if (shouldUsePersistent) {
875873
// Start persistent query if not running
876874
if (!this.persistentQuery && !this.shuttingDown) {
875+
// Seed the launch config with this turn's external context so the
876+
// first applyDynamicUpdates() does not restart a query whose daemon
877+
// session is still opening.
877878
await this.startPersistentQuery(
878879
vaultPath,
879880
resolvedQoderPath,
880-
this.sessionManager.getSessionId() ?? undefined
881+
this.sessionManager.getSessionId() ?? undefined,
882+
effectiveQueryOptions?.externalContextPaths ?? this.currentExternalContextPaths
881883
);
882884
}
883885

@@ -1034,11 +1036,9 @@ export class QoderChatRuntime implements ChatRuntime {
10341036
}
10351037

10361038
private buildSDKUserMessage(prompt: string, images?: ImageAttachment[]): SDKUserMessage {
1037-
return buildQoderSDKUserMessage(
1038-
prompt,
1039-
this.sessionManager.getSessionId() || '',
1040-
images,
1041-
);
1039+
// The daemon owns the session id and stamps it onto each message; sending
1040+
// a stale one is rejected with a session_id mismatch.
1041+
return buildQoderSDKUserMessage(prompt, images);
10421042
}
10431043

10441044
/**

0 commit comments

Comments
 (0)