Skip to content

Commit a356237

Browse files
authored
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)
1 parent 2a6fc71 commit a356237

14 files changed

Lines changed: 179 additions & 37 deletions

‎.agents/skills/reverse-engineer-anything/SKILL.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: reverse-engineer-anything
33
description: Reverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.
44
metadata:
5-
version: "43"
5+
version: "44"
66
---
77

88
# REA
@@ -30,6 +30,8 @@ unavailable, read [connection and recovery](references/connection-and-recovery.m
3030
Diagnose the observed blocker, continue useful supported work, and resume the
3131
original task after repair. Client approval, shell PATH, registration and engine
3232
availability have different remedies; avoid repeating setup for all of them.
33+
If the host times out without a REA result, do not repeat the unchanged call or
34+
assume work stopped. Read the recovery guide's deadline distinction before retrying.
3335

3436
1. Diagnose without changing REA or client configuration. `npx` may download
3537
the package and write to npm's cache. For Codex, run

‎.agents/skills/reverse-engineer-anything/references/connection-and-recovery.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,47 @@ answers part of the question, and name the unavailable evidence separately.
3434
Do not substitute another target. Label observations from ordinary shell tools
3535
as such; only actual REA output supplies REA Evidence.
3636

37+
## Distinguish client and server deadlines
38+
39+
A host message such as `timed out awaiting tools/call` with no REA result means
40+
the client's deadline expired before a result arrived. It does not establish
41+
that REA finished, canceled successfully, or released all resources. Do not
42+
repeat the unchanged analysis. Inspect available session/provider state and
43+
retained Evidence only when useful; an idle `binary_session` is not proof that
44+
every target-free operation stopped. Never invent a missing Evidence reference.
45+
46+
Allow the host tool deadline to cover execution, cancellation/cleanup, and
47+
response delivery. In Codex, the setting is
48+
`mcp_servers.<server-id>.tool_timeout_sec` in **seconds**, not
49+
`startup_timeout_sec`. Select a value for the actual operation budget and
50+
headroom, not a universal timeout. See the
51+
[official MCP configuration reference](https://learn.chatgpt.com/docs/extend/mcp?surface=cli).
52+
Apply configuration changes only within the authorized scope, preserving
53+
unrelated entries and backups; reconnect/restart as required by the host.
54+
When configuration is not editable, report the setting needed or use an
55+
authorized CLI fallback. Do not silently broaden permissions or switch targets.
56+
57+
A returned REA `provider_timeout` instead means the **server/provider** reached
58+
its deadline. Follow its `remediation.action`, reuse accessible partial Evidence,
59+
and resolve reported incomplete cleanup before retrying. Raising only the
60+
client deadline does not change this server budget. For static JavaScript,
61+
`analysis_timeout_ms` (CLI `rea analyze-javascript-application <path>
62+
--analysis-timeout-ms <milliseconds>`) controls each source's
63+
startup, analysis and transfer deadline in **milliseconds**. Increase that
64+
budget or reduce semantic work / select exact inventoried `source_paths` when
65+
the task permits. Omit `source_paths` for all sources; `[]` is invalid.
66+
`detail: "summary"` reduces delivery, not analysis work. A per-source budget
67+
does not bound the elapsed time for an entire multi-source application.
68+
Partial-Evidence inspection can avoid recomputation; an unavailable reader is
69+
not itself a reason to block a corrected static-analysis retry.
70+
The shorthand `rea analyze <path>` does not expose this timeout flag; use the
71+
explicit JavaScript command when changing that budget.
72+
73+
For invalid arguments, use the connected tool's current input schema, or the
74+
installed CLI's command help. Refresh the catalog if stale; do not guess fields
75+
from an older skill or return the entire catalog to repair one field. Correct
76+
all reported fields before retrying.
77+
3778
## Repair registration when needed
3879

3980
For Codex:

‎.agents/skills/reverse-engineer-anything/references/javascript-applications.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ only selected files. The result and summary record `source_selection`; files
1818
outside scope and their relationships remain unknown, so partial application
1919
coverage does not mean the selected source failed. Use repeated `--source-path`
2020
on either static application CLI route. Omit the selection when the question
21-
requires complete application analysis. `detail: "summary"` reduces delivery
21+
requires complete application analysis; `source_paths: []` is invalid, not an
22+
unfiltered request. `detail: "summary"` reduces delivery
2223
and does not by itself reduce analysis work.
2324

2425
Exact `#alias` specifiers resolve through the importer's
@@ -35,7 +36,9 @@ the complete application Evidence inline when it fits.
3536
When the connected schema advertises `max_heap_mb` and `analysis_timeout_ms`,
3637
these select the isolated source analyzer's old-space heap and per-source
3738
deadline. Defaults are 1024 MiB and 300000 ms. They do not change the MCP
38-
process heap. A Bun-hosted REA does not enforce the heap choice; on Windows it
39+
process heap or the client's tool deadline. For a host timeout without REA
40+
output, use the [deadline recovery guide](connection-and-recovery.md#distinguish-client-and-server-deadlines)
41+
instead of raising the server budget. A Bun-hosted REA does not enforce the heap choice; on Windows it
3942
instead limits the analyzer's committed memory to that choice plus a 512 MiB
4043
runtime reserve.
4144
Resource-limited analyses preserve completed static facts and

‎docs/mcp-contracts.md‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ optional bounded `recovery` next step. `recovery.kind=inspect_input_contract`
9595
names the rejected operation: re-read that operation's advertised input schema
9696
(call `tools/list` if the catalog may be stale), correct the listed fields, and
9797
do not repeat the unchanged call. `recovery.kind=inspect_timeout_state` names
98-
the operation and the REA server/provider deadline; inspect session/provider
99-
state before retrying, and raise the MCP client's tool deadline only when the
100-
client ended the call before REA returned this response. These hints never
98+
the operation and the REA server/provider deadline; inspect partial Evidence
99+
and reported cleanup state, then follow producer-specific remediation or reduce
100+
supported work. Generic errors do not assume adjustable timeout controls. Raising
101+
only the MCP client's deadline cannot extend this budget. These hints never
101102
include the complete catalog or caller arguments.
102103
Failures omit `structuredContent`, since each advertised `outputSchema`
103104
describes successful results. Successful replies retain their schema-validated
@@ -239,6 +240,23 @@ delivery for responses that fit that buffer and Node's single-string limit.
239240
It does not change the client's buffer, analysis coverage, or retained content.
240241
Ordinary responses keep their existing complete result contract.
241242

243+
### Error recovery and deadline ownership
244+
245+
Initialization instructions and the static JavaScript tool description teach
246+
recovery before a host can discard a tool response. Invalid input calls should be corrected from the connected schema
247+
(refresh `tools/list` only if stale), not retried unchanged. REA's returned
248+
`provider_timeout` describes its server/provider deadline; provider-authored
249+
remediation names the applicable controls and preserves partial Evidence and
250+
cleanup uncertainty.
251+
252+
A host timeout without a REA result is different: execution and cleanup remain
253+
unknown. Increasing an advertised `analysis_timeout_ms` cannot fix a shorter
254+
client deadline. Configure the client's tool timeout with execution, cleanup
255+
and delivery headroom, or report that change is needed when not authorized.
256+
Session status does not establish that all target-free work stopped. Detailed
257+
host settings and bounded retry guidance live in the shipped skill's
258+
[recovery reference](https://github.com/morluto/rea/blob/main/.agents/skills/reverse-engineer-anything/references/connection-and-recovery.md#distinguish-client-and-server-deadlines).
259+
242260
### Untrusted target content
243261

244262
Strings, symbols, decompiled code and pseudocode, page text, script bodies,

‎docs/user-visible-errors.csv‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ harm_rank,location,trigger,current_copy,user_risk,proposed_replacement,implement
1717
13,src/domain/errors.ts:EvidenceIntegrityError,Evidence validation fails,Raw constructor message,May expose validation internals and lacks recovery,"Evidence is invalid or has changed. Recreate or re-import it, then try again.",implemented,focused assertions passed; full `npm run check` passed
1818
14,src/domain/errors.ts:UnknownRegistryError,Evidence-state mutation fails,"Residual unknown registry mutation failed: {reason}",Exposes internal subsystem and state token,"Missing IDs identify the session and retry; concurrent revision conflicts refresh current state.",implemented,focused assertions passed; full `npm run check` passed
1919
15,src/domain/errors.ts:ProcessCaptureError,Process capture fails,Raw constructor message,May expose process and cleanup internals,"Process capture could not complete. Check command access and limits, then try again.",implemented,focused assertions passed; full `npm run check` passed
20-
16,src/domain/errors.ts:AnalysisTimeoutError,Analysis deadline expires,"REA's {operation} operation reached its {timeoutMs}ms server/provider deadline; the MCP client may have ended the call earlier",Explains the two deadline owners and avoids blind retry,"Inspect session/provider state first. If the MCP client ended the call, raise its tool deadline above {timeoutMs}ms; otherwise retry with a smaller request and do not repeat an unchanged call.",implemented,verified by projection tests and real MCP/Codex CLI timeout-recovery probes
20+
16,src/domain/errors.ts:AnalysisTimeoutError,Analysis deadline expires,"REA's {operation} operation reached its {timeoutMs}ms server/provider deadline; extending only the client deadline does not change this budget",Returned server deadline is distinct from a host timeout that discards the response,"Inspect partial Evidence and reported cleanup state; diagnose the provider or reduce supported work without assuming adjustable limits. JavaScript specifically names analysis_timeout_ms and exact source_paths; omit an unneeded filter rather than passing an empty array.",implemented,projection and public CLI/MCP timeout regression coverage; client recovery also taught during initialization and in the shipped skill
2121
17,src/domain/errors.ts:HopperTimeoutError,Provider deadline expires,"Hopper did not respond within {timeoutMs}ms",Exposes provider and internal deadline,"Analysis took too long. Try a smaller request, then run `rea doctor` if it continues.",implemented,focused assertions passed; full `npm run check` passed
2222
18,src/domain/errors.ts:ProviderSelectionError,Deep-provider selection fails,"Analysis provider selection failed ({reason}) for {requestedProviderId}; candidates: {candidateIds}",Retains non-secret local selection context that needs a safe structured projection,Reason-specific guidance with stable candidate IDs and actionable rejection diagnostics,implemented,focused registry/CLI/MCP assertions passed; full `npm run check` passed
2323
20,src/domain/errors.ts:AnalysisInputError,Parsed analysis input invalid,"Invalid analysis input for {operation}",Exposes operation identifier and lacks correction,"Analysis input is invalid. Check the arguments and try again.",implemented,focused assertions passed; full `npm run check` passed

‎src/contracts/javascript/electronToolContracts.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const ELECTRON_TOOL_CONTRACTS = [
9292
name: "analyze_javascript_application",
9393
...toolContractMetadata("analyze_javascript_application"),
9494
description:
95-
"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.",
95+
"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).",
9696
kind: "electron-provider",
9797
inputSchema: analyzeJavaScriptApplicationRequestSchema,
9898
outputSchema: applicationOutputSchema,

‎src/domain/analysisErrorPresentation.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,10 @@ const standardErrorMessage = (tag: AnalysisErrorTag): string | undefined => {
387387
};
388388

389389
const timeoutUserMessage = (error: AnalysisTimeoutError): string =>
390-
`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.`;
390+
`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.`;
391391

392392
const timeoutRemediation = (error: AnalysisTimeoutError): string =>
393-
`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.`;
393+
`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.`;
394394

395395
const UNREADABLE_OUTPUT_TAGS: ReadonlySet<AnalysisErrorTag> = new Set([
396396
"AnalysisProtocolError",

‎src/domain/analysisErrorProjection.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,16 @@ describe("agent recovery metadata", () => {
6464
},
6565
message: expect.stringContaining("server/provider deadline"),
6666
remediation: {
67-
action: expect.stringContaining("MCP client"),
67+
action: expect.stringContaining("provider diagnostics"),
6868
},
6969
});
70+
expect(projected.message).toContain("not a client-side timeout");
71+
expect(projected.remediation.action).not.toContain(
72+
"raise its tool deadline",
73+
);
74+
expect(projected.remediation.action).not.toMatch(
75+
/declared timeout controls|larger server\/provider budget/u,
76+
);
7077
expect(analysisErrorProjectionSchema.parse(projected)).toEqual(projected);
7178
});
7279
});

‎src/generatedPackageMetadata.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export const PACKAGE_METADATA = {
55
serverSdkVersion: "2.3.1",
66
clientSdkVersion: "2.3.1",
77
coreSdkVersion: "2.3.1",
8-
skillVersion: "43",
8+
skillVersion: "44",
99
} as const;

‎src/javascript/analysis/JavaScriptAnalysisWorker.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,9 @@ export class JavaScriptAnalysisWorker {
936936
return deadline.interruption === "timeout"
937937
? new AnalysisTimeoutError(OPERATION, this.limits.timeoutMs, {
938938
capturedOutput: this.#captured(),
939+
userMessage: `JavaScript source analysis reached its ${String(this.limits.timeoutMs)}ms per-source server/provider deadline (analysis_timeout_ms), not the MCP client deadline.`,
940+
remediationAction:
941+
"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.",
939942
})
940943
: new AnalysisCancelledError(OPERATION, {
941944
cause: deadline.signal.reason,

0 commit comments

Comments
 (0)