Skip to content

Commit fd513e7

Browse files
committed
fix: repair cursor delta landing gates
1 parent 7503260 commit fd513e7

4 files changed

Lines changed: 39 additions & 14 deletions

File tree

‎src/agents/agent-bundle-mcp-runtime.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ async function writeListToolsMcpServer(params: {
103103
hangToolCallsUntilRestartMarkerPath?: string;
104104
notifyListChangedOnInitialized?: boolean;
105105
notifyListChangedAfterFirstList?: boolean;
106+
notifyListChangedReleasePath?: string;
106107
notifyListChangedBeforeEveryListResponse?: boolean;
107108
exitOnListCall?: number;
108109
listToolsMethodNotFound?: boolean;
@@ -140,6 +141,7 @@ const hangToolCallsUntilRestartMarkerPath = ${JSON.stringify(
140141
)};
141142
const notifyListChangedOnInitialized = ${params.notifyListChangedOnInitialized === true};
142143
const notifyListChangedAfterFirstList = ${params.notifyListChangedAfterFirstList === true};
144+
const notifyListChangedReleasePath = ${JSON.stringify(params.notifyListChangedReleasePath)};
143145
const notifyListChangedBeforeEveryListResponse = ${params.notifyListChangedBeforeEveryListResponse === true};
144146
const exitOnListCall = ${params.exitOnListCall ?? 0};
145147
const listToolsMethodNotFound = ${params.listToolsMethodNotFound === true};
@@ -278,8 +280,20 @@ function handle(message) {
278280
},
279281
});
280282
if (notifyListChangedAfterFirstList && currentListCount === 1) {
281-
log("notify tools/list_changed");
282-
send({ jsonrpc: "2.0", method: "notifications/tools/list_changed" });
283+
void (async () => {
284+
while (notifyListChangedReleasePath) {
285+
const released = await fs
286+
.access(notifyListChangedReleasePath)
287+
.then(() => true)
288+
.catch(() => false);
289+
if (released) {
290+
break;
291+
}
292+
await new Promise((resolve) => setTimeout(resolve, 10));
293+
}
294+
log("notify tools/list_changed");
295+
send({ jsonrpc: "2.0", method: "notifications/tools/list_changed" });
296+
})();
283297
}
284298
};
285299
void (async () => {
@@ -1794,11 +1808,13 @@ process.on("SIGINT", shutdown);`,
17941808
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "bundle-mcp-refresh-exit-"));
17951809
const serverPath = path.join(tempDir, "server.mjs");
17961810
const logPath = path.join(tempDir, "server.log");
1811+
const notifyReleasePath = path.join(tempDir, "notify.release");
17971812
await writeListToolsMcpServer({
17981813
filePath: serverPath,
17991814
logPath,
18001815
capabilities: { tools: { listChanged: true } },
18011816
notifyListChangedAfterFirstList: true,
1817+
notifyListChangedReleasePath: notifyReleasePath,
18021818
exitOnListCall: 2,
18031819
});
18041820

@@ -1817,6 +1833,7 @@ process.on("SIGINT", shutdown);`,
18171833

18181834
try {
18191835
expect((await runtime.getCatalog()).tools).toHaveLength(1);
1836+
await fs.writeFile(notifyReleasePath, "release", "utf8");
18201837
await waitForFileText(logPath, "notify tools/list_changed", LIST_TOOLS_SERVER_LOG_TIMEOUT_MS);
18211838
await waitForPredicate(
18221839
() => runtime.peekCatalog() === null,

‎ui/src/pages/chat/chat-agent-id.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { scopedAgentParamsForSession } from "../../lib/sessions/index.ts";
2+
import {
3+
normalizeAgentId,
4+
parseAgentSessionKey,
5+
resolveUiSelectedGlobalAgentId,
6+
} from "../../lib/sessions/session-key.ts";
7+
import type { ChatState } from "./chat-state-contract.ts";
8+
9+
export function resolveChatAgentId(state: ChatState) {
10+
return normalizeAgentId(
11+
parseAgentSessionKey(state.sessionKey)?.agentId ??
12+
scopedAgentParamsForSession(state, state.sessionKey).agentId ??
13+
resolveUiSelectedGlobalAgentId(state),
14+
);
15+
}

‎ui/src/pages/chat/chat-state-route.ts‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import { loadLocalAssistantIdentity } from "../../app/assistant-identity.ts";
22
import { patchSettings } from "../../app/settings.ts";
33
import { isRenderableControlUiAvatarUrl } from "../../lib/avatar.ts";
4-
import { scopedAgentParamsForSession, type SessionCapability } from "../../lib/sessions/index.ts";
4+
import type { SessionCapability } from "../../lib/sessions/index.ts";
55
import {
66
areUiSessionKeysEquivalent,
77
isUiGlobalSessionKey,
88
isUiGlobalScopeConfigured,
99
normalizeAgentId,
10-
parseAgentSessionKey,
1110
resolveUiSelectedGlobalAgentId,
1211
uiSessionRowMatchesSelectedChat,
1312
} from "../../lib/sessions/session-key.ts";
14-
import type { ChatState } from "./chat-state-contract.ts";
13+
import { resolveChatAgentId } from "./chat-agent-id.ts";
1514
import type { ChatPageHost } from "./chat-state-host.ts";
1615

16+
export { resolveChatAgentId } from "./chat-agent-id.ts";
17+
1718
export function canCreateChatSession(state: ChatPageHost) {
1819
return (
1920
!state.chatLoading &&
@@ -65,14 +66,6 @@ export function saveRouteSessionSettings(state: ChatPageHost, sessionKey: string
6566
state.settings = patchSettings({ sessionKey, lastActiveSessionKey: sessionKey });
6667
}
6768

68-
export function resolveChatAgentId(state: ChatState) {
69-
return normalizeAgentId(
70-
parseAgentSessionKey(state.sessionKey)?.agentId ??
71-
scopedAgentParamsForSession(state, state.sessionKey).agentId ??
72-
resolveUiSelectedGlobalAgentId(state),
73-
);
74-
}
75-
7669
export function patchChatSessionLabel(
7770
state: ChatPageHost,
7871
sessions: Pick<SessionCapability, "patch">,

‎ui/src/pages/chat/session-message-apply.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
readSessionMessageSequence,
44
} from "@openclaw/gateway-client/browser";
55
import { asNonArrayRecord } from "@openclaw/normalization-core/record-coerce";
6+
import { resolveChatAgentId } from "./chat-agent-id.ts";
67
import type { ChatState } from "./chat-state-contract.ts";
7-
import { resolveChatAgentId } from "./chat-state-route.ts";
88
import { readChatSessionProjectionScope, reduceChatSessionProjection } from "./history-merge.ts";
99
import { persistedSteerTargetRunId, rolloverChatStream } from "./stream-causal-boundary.ts";
1010

0 commit comments

Comments
 (0)