Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

refactor(protocol): deprecate legacy agentId conversation fallback

Jiayuan Zhang6969790c25c3
diff --git a/apps/desktop/src/main/electron-env.d.ts b/apps/desktop/src/main/electron-env.d.ts
index 3e56ba7a5b..510e2ed1be 100644
--- a/apps/desktop/src/main/electron-env.d.ts
+++ b/apps/desktop/src/main/electron-env.d.ts
@@ -161,7 +161,7 @@ type MessageSource =
interface InboundMessageEvent {
agentId: string
- conversationId?: string
+ conversationId: string
content: string
source: MessageSource
timestamp: number
diff --git a/apps/desktop/src/preload/index.ts b/apps/desktop/src/preload/index.ts
index c76ab2b406..d4d06f28b1 100644
--- a/apps/desktop/src/preload/index.ts
+++ b/apps/desktop/src/preload/index.ts
@@ -90,7 +90,7 @@ export type MessageSource =
export interface InboundMessageEvent {
agentId: string
- conversationId?: string
+ conversationId: string
content: string
source: MessageSource
timestamp: number
diff --git a/packages/core/src/agent/tools/exec-approval-types.ts b/packages/core/src/agent/tools/exec-approval-types.ts
index a3275a7b4e..671883b2f2 100644
--- a/packages/core/src/agent/tools/exec-approval-types.ts
+++ b/packages/core/src/agent/tools/exec-approval-types.ts
@@ -24,8 +24,8 @@ export interface ExecApprovalRequest {
approvalId: string;
/** Agent that initiated the command */
agentId: string;
- /** Optional conversation ID. Falls back to agentId in legacy mode. */
- conversationId?: string;
+ /** Conversation ID that initiated the command. */
+ conversationId: string;
/** Shell command to execute */
command: string;
/** Working directory */
diff --git a/packages/core/src/client/actions/exec-approval.ts b/packages/core/src/client/actions/exec-approval.ts
index 3c4d6dd952..0b314d7753 100644
--- a/packages/core/src/client/actions/exec-approval.ts
+++ b/packages/core/src/client/actions/exec-approval.ts
@@ -14,8 +14,8 @@ export interface ExecApprovalRequestPayload {
approvalId: string;
/** Agent that initiated the command */
agentId: string;
- /** Optional conversation ID. Falls back to agentId in legacy mode. */
- conversationId?: string;
+ /** Conversation ID that initiated the approval request. */
+ conversationId: string;
/** Shell command requiring approval */
command: string;
/** Working directory */
diff --git a/packages/core/src/client/actions/stream.ts b/packages/core/src/client/actions/stream.ts
index e40afaece4..777b9734e4 100644
--- a/packages/core/src/client/actions/stream.ts
+++ b/packages/core/src/client/actions/stream.ts
@@ -62,8 +62,8 @@ export type AgentErrorEvent = {
export interface StreamPayload {
streamId: string;
agentId: string;
- /** Optional conversation ID. Falls back to agentId in legacy mode. */
- conversationId?: string;
+ /** Conversation ID of this stream event. */
+ conversationId: string;
event: AgentEvent | CompactionEvent | AgentErrorEvent;
}
diff --git a/packages/core/src/hub/agent-store.ts b/packages/core/src/hub/agent-store.ts
index 2068eeead7..c697ac8517 100644
--- a/packages/core/src/hub/agent-store.ts
+++ b/packages/core/src/hub/agent-store.ts
@@ -23,6 +23,16 @@ export interface HubStoreSnapshot {
const AGENTS_DIR = join(DATA_DIR, "agents");
const AGENTS_FILE = join(AGENTS_DIR, "agents.json");
+const warnedLegacyApis = new Set<string>();
+
+function warnLegacyApi(apiName: string): void {
+ if (warnedLegacyApis.has(apiName)) return;
+ warnedLegacyApis.add(apiName);
+ console.warn(
+ `[agent-store] Deprecated legacy API "${apiName}" was used. ` +
+ "Migrate callers to conversation-first APIs (loadHubStoreSnapshot/upsertConversationRecord).",
+ );
+}
function ensureDir(): void {
if (!existsSync(AGENTS_DIR)) {
@@ -230,10 +240,12 @@ export function removeConversationRecordById(conversationId: string): void {
// Legacy compatibility wrappers
// NOTE: In legacy mode, each agent record is treated as both agent and main conversation.
export function loadAgentRecords(): AgentRecord[] {
+ warnLegacyApi("loadAgentRecords");
return loadHubStoreSnapshot().agents;
}
export function saveAgentRecords(records: AgentRecord[]): void {
+ warnLegacyApi("saveAgentRecords");
const agents = normalizeAgentRecords(records);
const conversations = agents.map((record) => ({
id: record.id,
@@ -249,6 +261,7 @@ export function saveAgentRecords(records: AgentRecord[]): void {
}
export function addAgentRecord(record: AgentRecord): void {
+ warnLegacyApi("addAgentRecord");
upsertAgentRecord(record);
upsertConversationRecord({
id: record.id,
@@ -259,6 +272,7 @@ export function addAgentRecord(record: AgentRecord): void {
}
export function removeAgentRecord(id: string): void {
+ warnLegacyApi("removeAgentRecord");
// Legacy API accepts either agent id or conversation id.
const snapshot = loadHubStoreSnapshot();
const conversation = snapshot.conversations.find((item) => item.id === id);
diff --git a/packages/core/src/hub/exec-approval-manager.test.ts b/packages/core/src/hub/exec-approval-manager.test.ts
index fa38c902b4..1a0ae0e09d 100644
--- a/packages/core/src/hub/exec-approval-manager.test.ts
+++ b/packages/core/src/hub/exec-approval-manager.test.ts
@@ -18,6 +18,7 @@ describe("ExecApprovalManager", () => {
it("sends approval request to client and resolves on decision", async () => {
const promise = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "rm -rf /tmp/test",
cwd: "/workspace",
riskLevel: "dangerous",
@@ -43,6 +44,7 @@ describe("ExecApprovalManager", () => {
it("resolves with deny when decision is deny", async () => {
const promise = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "sudo reboot",
riskLevel: "dangerous",
riskReasons: [],
@@ -59,6 +61,7 @@ describe("ExecApprovalManager", () => {
it("resolves with allow-always", async () => {
const promise = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "git push",
riskLevel: "needs-review",
riskReasons: [],
@@ -75,6 +78,7 @@ describe("ExecApprovalManager", () => {
it("auto-denies on timeout (fail-closed)", async () => {
const promise = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "dangerous-command",
riskLevel: "dangerous",
riskReasons: [],
@@ -91,6 +95,7 @@ describe("ExecApprovalManager", () => {
it("keeps approval pending indefinitely when timeoutMs is -1", async () => {
const promise = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd",
riskLevel: "needs-review",
riskReasons: [],
@@ -112,6 +117,7 @@ describe("ExecApprovalManager", () => {
it("honors askFallback full on timeout", async () => {
const promise = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd",
riskLevel: "needs-review",
riskReasons: [],
@@ -128,6 +134,7 @@ describe("ExecApprovalManager", () => {
it("honors askFallback allowlist on timeout", async () => {
const allowPromise = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd",
riskLevel: "needs-review",
riskReasons: [],
@@ -143,6 +150,7 @@ describe("ExecApprovalManager", () => {
const denyPromise = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd",
riskLevel: "needs-review",
riskReasons: [],
@@ -165,6 +173,7 @@ describe("ExecApprovalManager", () => {
it("returns false when resolving already-resolved approval", async () => {
const promise = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd",
riskLevel: "needs-review",
riskReasons: [],
@@ -183,6 +192,7 @@ describe("ExecApprovalManager", () => {
it("cancels all pending approvals for an agent", async () => {
const promise1 = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd1",
riskLevel: "needs-review",
riskReasons: [],
@@ -190,6 +200,7 @@ describe("ExecApprovalManager", () => {
const promise2 = manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd2",
riskLevel: "needs-review",
riskReasons: [],
@@ -197,6 +208,7 @@ describe("ExecApprovalManager", () => {
const promise3 = manager.requestApproval({
agentId: "agent-2",
+ conversationId: "agent-2",
command: "cmd3",
riskLevel: "needs-review",
riskReasons: [],
@@ -231,6 +243,7 @@ describe("ExecApprovalManager", () => {
const result = await failManager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd",
riskLevel: "needs-review",
riskReasons: [],
@@ -243,6 +256,7 @@ describe("ExecApprovalManager", () => {
it("getSnapshot returns request details", () => {
manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "ls",
riskLevel: "safe",
riskReasons: [],
@@ -265,6 +279,7 @@ describe("ExecApprovalManager", () => {
manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd1",
riskLevel: "needs-review",
riskReasons: [],
@@ -273,6 +288,7 @@ describe("ExecApprovalManager", () => {
manager.requestApproval({
agentId: "agent-1",
+ conversationId: "agent-1",
command: "cmd2",
riskLevel: "needs-review",
riskReasons: [],
diff --git a/packages/core/src/hub/exec-approval-manager.ts b/packages/core/src/hub/exec-approval-manager.ts
index d2208bdb5e..fabbf0054a 100644
--- a/packages/core/src/hub/exec-approval-manager.ts
+++ b/packages/core/src/hub/exec-approval-manager.ts
@@ -42,7 +42,7 @@ export class ExecApprovalManager {
*/
requestApproval(params: {
agentId: string;
- conversationId?: string;
+ conversationId: string;
command: string;
cwd?: string;
riskLevel: "safe" | "needs-review" | "dangerous";
@@ -54,7 +54,7 @@ export class ExecApprovalManager {
const approvalId = uuidv7();
const timeoutMs = params.timeoutMs ?? this.defaultTimeoutMs;
const expiresAtMs = timeoutMs >= 0 ? Date.now() + timeoutMs : -1;
- const conversationId = params.conversationId ?? params.agentId;
+ const conversationId = params.conversationId;
const request: ExecApprovalRequest = {
approvalId,
@@ -124,8 +124,7 @@ export class ExecApprovalManager {
*/
cancelPending(agentId: string): void {
for (const [id, entry] of this.pending) {
- const requestConversationId = entry.request.conversationId ?? entry.request.agentId;
- if (entry.request.agentId === agentId || requestConversationId === agentId) {
+ if (entry.request.agentId === agentId || entry.request.conversationId === agentId) {
if (entry.timer) clearTimeout(entry.timer);
this.pending.delete(id);
entry.resolve({ approved: false, decision: "deny" });
diff --git a/packages/core/src/hub/hub.ts b/packages/core/src/hub/hub.ts
index 0086289703..d872eb7c20 100644
--- a/packages/core/src/hub/hub.ts
+++ b/packages/core/src/hub/hub.ts
@@ -73,14 +73,16 @@ export type MessageSource =
/** Inbound message event broadcast to all listeners */
export interface InboundMessageEvent {
agentId: string;
- /** Optional conversation ID. Falls back to agentId in legacy mode. */
- conversationId?: string;
+ /** Conversation ID for this inbound message. */
+ conversationId: string;
content: string;
source: MessageSource;
timestamp: number;
}
export class Hub {
+ private readonly allowLegacyAgentConversationFallback = process.env.MULTICA_ALLOW_LEGACY_AGENT_FALLBACK === "1";
+ private readonly warnedConversationFallbackAgents = new Set<string>();
// Runtime conversation map (conversationId -> AsyncAgent).
private readonly agents = new Map<string, AsyncAgent>();
// Conversation ownership map (conversationId -> logical agentId).
@@ -138,7 +140,12 @@ export class Hub {
}));
this.rpc.register("generateChannelWelcome", createGenerateChannelWelcomeHandler(this));
this.rpc.register("getAgentMessages", createGetAgentMessagesHandler((agentId, conversationId) => {
- return this.resolveConversationId(agentId, conversationId);
+ const resolvedConversationId = this.resolveConversationId(agentId, conversationId);
+ if (!resolvedConversationId) return null;
+ return {
+ conversationId: resolvedConversationId,
+ storageAgentId: this.getConversationAgentId(resolvedConversationId) ?? this.normalizeId(agentId),
+ };
}));
this.rpc.register("getHubInfo", createGetHubInfoHandler(this));
this.rpc.register("listAgents", createListAgentsHandler(this));
@@ -433,6 +440,14 @@ export class Hub {
console.warn(`[Hub] Invalid payload, missing agentId or content`);
return;
}
+ if (!conversationId) {
+ this.client.send(msg.from, "error", {
+ code: "INVALID_PARAMS",
+ message: "Unable to resolve conversationId. Please provide a valid conversationId.",
+ messageId: msg.id,
+ });
+ return;
+ }
const allowedScope = this.deviceStore.isAllowed(msg.from, conversationId);
if (!allowedScope) {
@@ -668,8 +683,24 @@ export class Hub {
const mainConversationId = this.resolveAgentMainConversationId(normalizedAgentId);
if (mainConversationId) return mainConversationId;
- // Legacy fallback: treat agentId as conversationId when no mapping exists yet.
- return normalizedAgentId;
+ if (this.allowLegacyAgentConversationFallback) {
+ if (!this.warnedConversationFallbackAgents.has(normalizedAgentId)) {
+ this.warnedConversationFallbackAgents.add(normalizedAgentId);
+ console.warn(
+ `[Hub] Legacy fallback enabled: using agentId as conversationId for ${normalizedAgentId}. ` +
+ "Set explicit conversationId in clients to avoid this deprecated path.",
+ );
+ }
+ return normalizedAgentId;
+ }
+
+ if (!this.warnedConversationFallbackAgents.has(normalizedAgentId)) {
+ this.warnedConversationFallbackAgents.add(normalizedAgentId);
+ console.warn(
+ `[Hub] Conversation resolution failed for agent ${normalizedAgentId}: no main conversation found and legacy fallback is disabled.`,
+ );
+ }
+ return "";
}
private beginStream(agentId: string, event: unknown): string {
diff --git a/packages/core/src/hub/rpc/handlers/get-agent-messages.ts b/packages/core/src/hub/rpc/handlers/get-agent-messages.ts
index 75b7ac269b..eb05381571 100644
--- a/packages/core/src/hub/rpc/handlers/get-agent-messages.ts
+++ b/packages/core/src/hub/rpc/handlers/get-agent-messages.ts
@@ -13,7 +13,12 @@ interface GetAgentMessagesParams {
limit?: number;
}
-type ConversationResolver = (agentId: string, conversationId?: string) => string;
+interface ResolvedConversation {
+ conversationId: string;
+ storageAgentId?: string;
+}
+
+type ConversationResolver = (agentId: string, conversationId?: string) => ResolvedConversation | null;
export function createGetAgentMessagesHandler(resolveConversationId?: ConversationResolver): RpcHandler {
return (params: unknown) => {
@@ -26,16 +31,28 @@ export function createGetAgentMessagesHandler(resolveConversationId?: Conversati
throw new RpcError("INVALID_PARAMS", "Missing required param: agentId");
}
const fallbackConversationId = (conversationId ?? "").trim() || agentId;
- const resolvedConversationId = resolveConversationId
+ const resolved = resolveConversationId
? resolveConversationId(agentId, conversationId)
- : fallbackConversationId;
+ : { conversationId: fallbackConversationId };
+
+ const resolvedConversationId = resolved?.conversationId?.trim() ?? "";
+ if (!resolvedConversationId) {
+ throw new RpcError("INVALID_PARAMS", "Unable to resolve conversationId");
+ }
+
+ const storageOptions = resolved?.storageAgentId
+ ? { agentId: resolved.storageAgentId }
+ : undefined;
- const sessionPath = resolveSessionPath(resolvedConversationId);
+ const sessionPath = resolveSessionPath(resolvedConversationId, storageOptions);
if (!existsSync(sessionPath)) {
throw new RpcError("AGENT_NOT_FOUND", `No session found for conversation: ${resolvedConversationId}`);
}
- const session = new SessionManager({ sessionId: resolvedConversationId });
+ const session = new SessionManager({
+ sessionId: resolvedConversationId,
+ ...(storageOptions ?? {}),
+ });
const allMessages = session.loadMessagesForDisplay();
const total = allMessages.length;
const contextWindowTokens = session.getMeta()?.contextWindowTokens ?? session.getContextWindowTokens();
diff --git a/packages/sdk/src/actions/exec-approval.ts b/packages/sdk/src/actions/exec-approval.ts
index 3c4d6dd952..0b314d7753 100644
--- a/packages/sdk/src/actions/exec-approval.ts
+++ b/packages/sdk/src/actions/exec-approval.ts
@@ -14,8 +14,8 @@ export interface ExecApprovalRequestPayload {
approvalId: string;
/** Agent that initiated the command */
agentId: string;
- /** Optional conversation ID. Falls back to agentId in legacy mode. */
- conversationId?: string;
+ /** Conversation ID that initiated the approval request. */
+ conversationId: string;
/** Shell command requiring approval */
command: string;
/** Working directory */
diff --git a/packages/sdk/src/actions/stream.ts b/packages/sdk/src/actions/stream.ts
index e40afaece4..777b9734e4 100644
--- a/packages/sdk/src/actions/stream.ts
+++ b/packages/sdk/src/actions/stream.ts
@@ -62,8 +62,8 @@ export type AgentErrorEvent = {
export interface StreamPayload {
streamId: string;
agentId: string;
- /** Optional conversation ID. Falls back to agentId in legacy mode. */
- conversationId?: string;
+ /** Conversation ID of this stream event. */
+ conversationId: string;
event: AgentEvent | CompactionEvent | AgentErrorEvent;
}