Skip to content

Commit b8733af

Browse files
fix(server): back off failed mention syncs and harden MCP parsing
Treat empty/error scopes by age, reject Jira isError payloads, and stop Codex TOML fields leaking across non-mcp sections. Co-authored-by: Cursor <[email protected]>
1 parent 650dc44 commit b8733af

7 files changed

Lines changed: 18 additions & 19 deletions

‎apps/server/src/mention/MentionIndex.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,12 @@ export const make = Effect.gen(function* () {
315315
markError: Effect.fn("MentionIndex.markError")(function* (scopeKey, detail) {
316316
const previous = yield* loadScope(scopeKey);
317317
const bounded = detail.trim().slice(0, 500) || "Mention index sync failed";
318+
const now = yield* Clock.currentTimeMillis;
318319
yield* setScope(scopeKey, {
319320
rows: previous.rows,
320321
meta: {
321-
syncedAt: previous.meta.syncedAt,
322+
// Stamp failure time so ensureIndexed can honor the freshness window.
323+
syncedAt: now,
322324
status: previous.rows.length > 0 ? "ready" : "error",
323325
detail: bounded,
324326
},

‎apps/server/src/mention/MentionIndexFigmaSyncer.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ const make = Effect.gen(function* () {
113113
const scopeKey = mentionIndexScopeKey("figma", projectId);
114114
const meta = yield* index.scopeMeta(scopeKey);
115115
const now = yield* Clock.currentTimeMillis;
116-
const stale =
117-
meta === null ||
118-
meta.status === "empty" ||
119-
meta.status === "error" ||
120-
now - meta.syncedAt > STALE_AFTER_MS;
116+
const stale = meta === null || now - meta.syncedAt > STALE_AFTER_MS;
121117
if (!stale) return;
122118

123119
const key = String(projectId);

‎apps/server/src/mention/MentionIndexJiraSyncer.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ const make = Effect.gen(function* () {
8080
);
8181
}
8282

83+
if (asRecord(payload)?.isError === true) {
84+
return yield* Effect.fail(new MentionIndexMcpError("Jira MCP tool returned isError"));
85+
}
86+
8387
const now = yield* Clock.currentTimeMillis;
8488
return extractJiraRows(payload, now).slice(0, MAX_ROWS);
8589
}),
@@ -109,7 +113,7 @@ const make = Effect.gen(function* () {
109113
const scopeKey = mentionIndexScopeKey("jira", projectId);
110114
const meta = yield* index.scopeMeta(scopeKey);
111115
const now = yield* Clock.currentTimeMillis;
112-
const stale = meta === null || meta.status === "error" || now - meta.syncedAt > STALE_AFTER_MS;
116+
const stale = meta === null || now - meta.syncedAt > STALE_AFTER_MS;
113117
if (!stale) return;
114118

115119
const key = String(projectId);

‎apps/server/src/mention/MentionIndexMcpClient.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,12 @@ export function parseCodexMcpServers(raw: string): ReadonlyArray<MentionMcpServe
258258
current = null;
259259
};
260260
for (const line of raw.split(/\r?\n/u)) {
261-
const section = line.match(/^\[mcp_servers\.([^\]]+)\]\s*$/u);
261+
const section = line.match(/^\[([^\]]+)\]\s*$/u);
262262
if (section) {
263263
flush();
264-
current = { name: section[1]!.replace(/^"|"$/g, ""), fields: {} };
264+
const mcpSection = /^mcp_servers\.(.+)$/u.exec(section[1]!);
265+
current =
266+
mcpSection === null ? null : { name: mcpSection[1]!.replace(/^"|"$/g, ""), fields: {} };
265267
continue;
266268
}
267269
if (current === null) continue;

‎apps/server/src/mention/MentionIndexMcpSyncers.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ url = "https://mcp.figma.com/mcp"
4343
bearer_token_env_var = "FIGMA_TOKEN"
4444
http_headers = { "X-Region" = "us" }
4545
46+
[profiles.default]
47+
command = "should-not-leak"
48+
4649
[mcp_servers.local-jira]
4750
command = "npx"
4851
args = ["-y", "jira-mcp"]

‎apps/server/src/mention/MentionIndexPrSyncer.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,7 @@ const make = Effect.gen(function* () {
117117
const scopeKey = mentionIndexScopeKey("pull-request", projectId);
118118
const meta = yield* index.scopeMeta(scopeKey);
119119
const now = yield* Clock.currentTimeMillis;
120-
const stale =
121-
meta === null ||
122-
meta.status === "empty" ||
123-
meta.status === "error" ||
124-
now - meta.syncedAt > STALE_AFTER_MS;
120+
const stale = meta === null || now - meta.syncedAt > STALE_AFTER_MS;
125121
if (!stale) return;
126122

127123
const key = String(projectId);

‎apps/server/src/mention/MentionIndexThreadSyncer.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ const make = Effect.gen(function* () {
8383
const scopeKey = mentionIndexScopeKey("thread", projectId);
8484
const meta = yield* index.scopeMeta(scopeKey);
8585
const now = yield* Clock.currentTimeMillis;
86-
const stale =
87-
meta === null ||
88-
meta.status === "empty" ||
89-
meta.status === "error" ||
90-
now - meta.syncedAt > STALE_AFTER_MS;
86+
const stale = meta === null || now - meta.syncedAt > STALE_AFTER_MS;
9187
if (!stale) return;
9288

9389
const key = String(projectId);

0 commit comments

Comments
 (0)