fix(mcp): guide client and provider timeout recovery (#5608)
Teach client deadline recovery before REA results can be discarded, distinguish producer-owned server budgets, and preserve Evidence/cleanup uncertainty. Include actual Codex CLI recovery probes and CLI/MCP regression coverage. Fixes #5598 Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
1 parent
2a6fc712eb
commit
a35623707e
14 files changed
+179
-37
No files matched your search
@@ -92,7 +92,7 @@ export const ELECTRON_TOOL_CONTRACTS = [
|
||||
name: "analyze_javascript_application",
|
||||
...toolContractMetadata("analyze_javascript_application"),
|
||||
description:
|
||||
"Reconstruct one local ASAR or extracted JavaScript application as an inline application graph without executing it. Returns recovered graph nodes, edges, semantic relations, integrity contradictions, limitations, and coverage. Select source_paths to acquire and analyze only exact inventoried file paths; the complete artifact inventory and identity remain intact, and unselected sources remain explicit unknowns. Dependencies are not implicitly analyzed. Select detail summary to retain the complete analysis Evidence in this session and receive only its summary view, then inspect selected modules or pages with inspect_analysis_view. Summary detail reduces delivery, whereas source_paths bounds source analysis. Integrity mismatches fail by default; record-and-continue retains observed bytes as untrusted and marks graph coverage partial.",
|
||||
"Reconstruct one local ASAR or extracted JavaScript application as an inline application graph without executing it. Returns recovered graph nodes, edges, semantic relations, integrity contradictions, limitations, and coverage. Select source_paths to acquire and analyze only exact inventoried file paths; the complete artifact inventory and identity remain intact, and unselected sources remain explicit unknowns. Dependencies are not implicitly analyzed. Select detail summary to retain the complete analysis Evidence in this session and receive only its summary view, then inspect selected modules or pages with inspect_analysis_view. Summary detail reduces delivery, whereas source_paths bounds source analysis. Integrity mismatches fail by default; record-and-continue retains observed bytes as untrusted and marks graph coverage partial. Timeout recovery: returned provider_timeout uses the per-source analysis_timeout_ms budget. A host-only 'timed out awaiting tools/call' needs a longer client tool deadline, not a larger analysis_timeout_ms. Never repeat the unchanged call to test whether that timeout persists; report the host setting if configuration is not editable (Codex: mcp_servers.<server>.tool_timeout_sec, seconds).",
|
||||
kind: "electron-provider",
|
||||
inputSchema: analyzeJavaScriptApplicationRequestSchema,
|
||||
outputSchema: applicationOutputSchema,
|
||||
|
||||
@@ -387,10 +387,10 @@ const standardErrorMessage = (tag: AnalysisErrorTag): string | undefined => {
|
||||
};
|
||||
|
||||
const timeoutUserMessage = (error: AnalysisTimeoutError): string =>
|
||||
`REA's ${error.operation} operation reached its ${String(error.timeoutMs)}ms server/provider deadline. If the MCP client timed out before this response, increase its tool deadline above ${String(error.timeoutMs)}ms; otherwise retry with a smaller request after checking session/provider state. Do not repeat an unchanged call while work or cleanup may still be active.`;
|
||||
`REA's ${error.operation} operation reached its ${String(error.timeoutMs)}ms server/provider deadline. This is not a client-side timeout; extending only the MCP client's deadline does not change this budget.`;
|
||||
|
||||
const timeoutRemediation = (error: AnalysisTimeoutError): string =>
|
||||
`Inspect session/provider state for ${error.operation} before retrying. If the MCP client ended the call before REA returned this error, raise its tool deadline above ${String(error.timeoutMs)}ms; otherwise retry with a smaller request. Do not repeat an unchanged call while work or cleanup may still be active.`;
|
||||
`Inspect any partial Evidence, provider diagnostics and reported session/provider cleanup state for ${error.operation}. Reduce the request if supported, or resolve the reported provider condition before retrying. Do not repeat the unchanged call or retry while work or cleanup may still be active.`;
|
||||
|
||||
const UNREADABLE_OUTPUT_TAGS: ReadonlySet<AnalysisErrorTag> = new Set([
|
||||
"AnalysisProtocolError",
|
||||
|
||||
@@ -64,9 +64,16 @@ describe("agent recovery metadata", () => {
|
||||
},
|
||||
message: expect.stringContaining("server/provider deadline"),
|
||||
remediation: {
|
||||
action: expect.stringContaining("MCP client"),
|
||||
action: expect.stringContaining("provider diagnostics"),
|
||||
},
|
||||
});
|
||||
expect(projected.message).toContain("not a client-side timeout");
|
||||
expect(projected.remediation.action).not.toContain(
|
||||
"raise its tool deadline",
|
||||
);
|
||||
expect(projected.remediation.action).not.toMatch(
|
||||
/declared timeout controls|larger server\/provider budget/u,
|
||||
);
|
||||
expect(analysisErrorProjectionSchema.parse(projected)).toEqual(projected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,5 +5,5 @@ export const PACKAGE_METADATA = {
|
||||
serverSdkVersion: "2.3.1",
|
||||
clientSdkVersion: "2.3.1",
|
||||
coreSdkVersion: "2.3.1",
|
||||
skillVersion: "43",
|
||||
skillVersion: "44",
|
||||
} as const;
|
||||
@@ -936,6 +936,9 @@ export class JavaScriptAnalysisWorker {
|
||||
return deadline.interruption === "timeout"
|
||||
? new AnalysisTimeoutError(OPERATION, this.limits.timeoutMs, {
|
||||
capturedOutput: this.#captured(),
|
||||
userMessage: `JavaScript source analysis reached its ${String(this.limits.timeoutMs)}ms per-source server/provider deadline (analysis_timeout_ms), not the MCP client deadline.`,
|
||||
remediationAction:
|
||||
"Reuse accessible partial_observation Evidence to avoid recomputation; reading it is not a prerequisite for a corrected retry. Increase analysis_timeout_ms through MCP, or use rea analyze-javascript-application <input_path> --analysis-timeout-ms <milliseconds> on the CLI. Alternatively, reduce semantic limits or select exact inventoried source_paths (CLI: --source-path on that command). Omit source_paths to analyze all sources; an empty array is invalid. detail: summary reduces response size, not analysis work. Allow execution, cleanup and delivery headroom in the MCP client tool deadline; increasing that client deadline alone does not change this server budget. Resolve any reported incomplete cleanup before retrying.",
|
||||
})
|
||||
: new AnalysisCancelledError(OPERATION, {
|
||||
cause: deadline.signal.reason,
|
||||
|
||||
@@ -151,6 +151,11 @@ const TARGET_FREE_INSTRUCTIONS =
|
||||
const ACTIVE_TARGET_INSTRUCTIONS =
|
||||
"REA analyzes the active reverse-engineering target. Use the analysis tool that answers the question directly. Search or list symbols when discovery is needed; analyze_function provides a function dossier, and focused procedure tools return individual facets.";
|
||||
|
||||
// A host deadline can discard the response before error remediation reaches the
|
||||
// agent. Teach that distinction at initialization, not just in returned errors.
|
||||
const RECOVERY_INSTRUCTIONS =
|
||||
"Recovery: For invalid arguments, read the connected tool's input schema (refresh tools/list if stale), fix the reported fields and do not repeat the unchanged call. A returned REA provider_timeout is a server/provider deadline: follow its remediation and reuse accessible partial Evidence. A host error such as 'timed out awaiting tools/call' without a REA result is a client deadline, not proof that work or cleanup stopped. Do not repeat the unchanged analysis. Increase the host's tool deadline with execution/cleanup/delivery headroom; when configuration is not editable, report the required setting (Codex: mcp_servers.<server>.tool_timeout_sec, seconds). Server analysis_timeout_ms, when advertised, is a separate millisecond budget; raising it cannot fix a shorter client deadline. Session state does not establish completion of every target-free operation.";
|
||||
|
||||
export interface CreateServerOptions {
|
||||
readonly environment?: Readonly<NodeJS.ProcessEnv>;
|
||||
readonly delivery?: ToolResultDelivery;
|
||||
@@ -281,7 +286,7 @@ const createMcpServer = (
|
||||
session === undefined
|
||||
? ACTIVE_TARGET_INSTRUCTIONS
|
||||
: TARGET_FREE_INSTRUCTIONS
|
||||
} ${UNTRUSTED_CONTENT_INSTRUCTIONS}`,
|
||||
} ${RECOVERY_INSTRUCTIONS} ${UNTRUSTED_CONTENT_INSTRUCTIONS}`,
|
||||
},
|
||||
session === undefined
|
||||
? undefined
|
||||
|
||||
Reference in new issue
Block a user