mobile-debug-mcp 0.26.5 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,321 @@
1
+
2
+
3
+ # RFC 011 — Recovery and Replanning for Failed or Ambiguous Interaction Flows
4
+
5
+ ## 1. Summary
6
+
7
+ This RFC defines a structured recovery and replanning model for UI interaction failures, enabling the system to respond to execution uncertainty with bounded, deterministic recovery strategies.
8
+
9
+ It extends the interaction stack defined in RFCs 005–009 by introducing explicit failure classification, recovery policy selection, and bounded replanning of interaction sequences.
10
+
11
+ ---
12
+
13
+ ## 2. Problem Statement
14
+
15
+ Even with reliable execution primitives (RFC 005–009), UI interactions can fail due to:
16
+
17
+ - incorrect or stale target resolution
18
+ - state drift between observation and execution
19
+ - ambiguous or partial UI snapshots
20
+ - control convergence failures (RFC 008)
21
+ - semantic mismatches in custom/Compose controls (RFC 009)
22
+
23
+ Currently, failure handling is implicit and ad hoc, often resulting in:
24
+
25
+ - repeated identical retries
26
+ - stalled flows with no recovery path
27
+ - loss of interaction context
28
+ - inability to switch strategy after failure
29
+
30
+ This leads to brittle automation behavior even when core primitives are correct.
31
+
32
+ ---
33
+
34
+ ## 3. Goals
35
+
36
+ This RFC introduces a structured recovery system that MUST:
37
+
38
+ - classify failures into distinct categories
39
+ - select appropriate recovery strategies based on failure type
40
+ - enable bounded replanning of interaction flows
41
+ - prevent infinite retry loops
42
+ - preserve interaction context across recovery attempts
43
+ - improve robustness under UI drift or ambiguity
44
+
45
+ ---
46
+
47
+ ## 4. Non-Goals
48
+
49
+ This RFC does NOT define:
50
+
51
+ - new UI interaction primitives (covered in RFC 006–008)
52
+ - new target resolution mechanisms (RFC 007)
53
+ - new control semantics (RFC 008–009)
54
+ - general autonomous planning system
55
+ - ML-based decision making or probabilistic policy learning
56
+
57
+ Recovery is deterministic and rule-based in this version.
58
+
59
+ ---
60
+
61
+ ## 5. Runtime Ownership and Integration
62
+
63
+ Recovery is a cross-layer concern with explicit ownership:
64
+
65
+ ### 5.1 Server Layer (src/server)
66
+ - Detects failure conditions from action execution results
67
+ - Emits normalized failure objects
68
+ - Applies initial failure classification mapping
69
+
70
+ ### 5.2 Interact Layer (src/interact)
71
+ - Executes recovery strategies
72
+ - Performs re-resolution, retry, and step-back operations where supported
73
+ - Maintains bounded retry loops
74
+
75
+ ### 5.3 Shared Contract Layer
76
+ - Defines failure schema
77
+ - Defines recovery state machine transitions
78
+
79
+ Recovery is NOT owned by a single layer; it is a coordinated contract between server and interact.
80
+
81
+ ---
82
+
83
+ ## 5. Failure Classification Model
84
+
85
+ All interaction failures MUST be classified into one of the following categories:
86
+
87
+ ### 5.1 Target Resolution Failure
88
+ - element not found
89
+ - ambiguous or multiple matches
90
+ - stale UI tree snapshot
91
+
92
+ ### 5.2 Execution Failure
93
+ - action could not be dispatched
94
+ - runtime rejection of interaction
95
+ - invalid gesture or control interaction
96
+
97
+ ### 5.3 Verification Failure
98
+ - action executed but expected state not observed
99
+ - expect_state mismatch (RFC 005)
100
+
101
+ ### 5.4 Control Convergence Failure
102
+ - adjustable control failed to reach target state (RFC 008)
103
+
104
+ ### 5.5 Semantic Mismatch Failure
105
+ - control semantics inferred incorrectly (RFC 009)
106
+
107
+ ---
108
+
109
+ ## 6. Runtime Failure Code Mapping
110
+
111
+ Existing runtime failure signals MUST map into RFC 011 failure categories.
112
+
113
+ | Runtime Code | RFC 011 Category |
114
+ |--------------|------------------|
115
+ | ELEMENT_NOT_FOUND | Target Resolution Failure |
116
+ | STALE_REFERENCE | Target Resolution Failure |
117
+ | AMBIGUOUS_TARGET | Target Resolution Failure |
118
+ | TIMEOUT | Execution Failure |
119
+ | ACTION_REJECTED | Execution Failure |
120
+ | VERIFICATION_FAILED | Verification Failure |
121
+ | EXPECT_STATE_MISMATCH | Verification Failure |
122
+ | CONTROL_CONVERGENCE_FAILED | Control Convergence Failure |
123
+ | UNKNOWN | Execution Failure (default fallback) |
124
+
125
+ This mapping MUST be deterministic and versioned with the runtime.
126
+
127
+ ---
128
+
129
+ ## 6. Recovery Strategy Model
130
+
131
+ Each failure type MUST map to a bounded set of recovery strategies:
132
+
133
+ ### 6.1 Re-resolve Strategy
134
+ Re-run target resolution (RFC 007) with updated context.
135
+
136
+ Used for:
137
+ - stale snapshot
138
+ - ambiguous target
139
+
140
+ ---
141
+
142
+ ### 6.2 Alternate Candidate Strategy
143
+ Select next-best candidate from resolved targets.
144
+
145
+ Used for:
146
+ - multiple matches
147
+ - incorrect initial resolution
148
+
149
+ ---
150
+
151
+ ### 6.3 State Refresh Strategy
152
+ Re-observe UI state before retrying action.
153
+
154
+ Used for:
155
+ - drift between observation and execution
156
+
157
+ ---
158
+
159
+ ### 6.4 Retry with Constraint Adjustment
160
+ Retry action with adjusted parameters:
161
+ - increased tolerance (RFC 008)
162
+ - alternative interaction mode
163
+
164
+ Used for:
165
+ - convergence failures
166
+ - flaky execution paths
167
+
168
+ ---
169
+
170
+ ### 6.5 Step-back Strategy
171
+ Rollback interaction context one step and re-enter flow.
172
+
173
+ Used for:
174
+ - persistent verification failure
175
+ - inconsistent UI state transitions
176
+
177
+ ---
178
+
179
+ ## 7. Replanning Model
180
+
181
+ Replanning is the process of constructing a new bounded interaction sequence after failure.
182
+
183
+ A replanned sequence MUST:
184
+
185
+ - preserve original intent
186
+ - incorporate failure classification context
187
+ - apply a recovery strategy
188
+ - remain bounded in retry depth
189
+
190
+ Replanning is NOT full autonomous task planning.
191
+
192
+ ---
193
+
194
+ ## 7.1 Scope of Replanning
195
+
196
+ Replanning in this RFC is strictly scoped to:
197
+
198
+ - Single-action recovery sequences
199
+ - Local retry chains
200
+ - Bounded corrective adjustments
201
+
202
+ It does NOT include:
203
+
204
+ - multi-step autonomous task planning
205
+ - global goal decomposition
206
+ - long-horizon planning
207
+
208
+ Replanning is therefore a bounded extension of execution, not a planning system.
209
+
210
+ ---
211
+
212
+ ## 8. Recovery State and Budget Contract
213
+
214
+ The system MUST represent recovery state explicitly per action.
215
+
216
+ ### 8.1 Recovery State Schema (conceptual)
217
+
218
+ {
219
+ "failure_class": "TargetResolutionFailure | ExecutionFailure | VerificationFailure | ControlConvergenceFailure | SemanticMismatchFailure",
220
+ "recovery_strategy": "re_resolve | alternate_candidate | state_refresh | retry_adjustment | step_back",
221
+ "recovery_attempts": 0,
222
+ "max_recovery_attempts": 3,
223
+ "retry_depth": 0,
224
+ "max_retry_depth": 3
225
+ }
226
+
227
+ ### 8.2 Budget Rules
228
+
229
+ - Each action MUST track recovery_attempts
230
+ - Recovery MUST NOT exceed max_recovery_attempts
231
+ - retry_depth MUST be bounded per interaction step
232
+ - Exhaustion MUST produce a terminal failure state
233
+
234
+ ### 8.3 Enforcement Point
235
+
236
+ Budget enforcement is the responsibility of the Interact layer (src/interact), with server providing initial values.
237
+
238
+ ---
239
+
240
+ ## 9. Execution Context Model
241
+
242
+ Full rollback is NOT required or assumed.
243
+
244
+ The system MUST preserve:
245
+
246
+ - last resolved target set (RFC 007)
247
+ - last executed action descriptor (RFC 006)
248
+ - last verification result (RFC 005)
249
+ - recovery_attempts counter
250
+
251
+ The system MAY optionally retain:
252
+
253
+ - prior candidate selections
254
+ - intermediate resolution outputs
255
+
256
+ Step-back is implemented as a re-resolution + re-execution, NOT a full state rollback system.
257
+
258
+ ---
259
+
260
+ ## 10. Relationship to Existing RFCs
261
+
262
+ ### RFC 005 — Correctness Model
263
+ Defines verification failures that trigger recovery.
264
+
265
+ ### RFC 006 — Runtime Binding
266
+ Defines execution surface where failures occur.
267
+
268
+ ### RFC 007 — Target Resolution
269
+ Provides alternate candidates for recovery strategies.
270
+
271
+ ### RFC 008 — Control-State Convergence
272
+ Defines recovery paths for control adjustment failures.
273
+
274
+ ### RFC 009 — Semantic Control Model
275
+ Defines classification of semantic mismatch failures.
276
+
277
+ ---
278
+
279
+ ## 11. Expected System Behaviour
280
+
281
+ On failure:
282
+
283
+ 1. classify runtime failure using deterministic mapping (Section 6)
284
+ 2. select recovery strategy
285
+ 3. optionally re-resolve target
286
+ 4. re-execute bounded action
287
+ 5. verify outcome using RFC 005 or mark recovery attempt failure
288
+ 6. escalate if budget exceeded
289
+
290
+ ---
291
+
292
+ ## 12. Structured Failure Output Contract
293
+
294
+ When recovery is exhausted or fails, the system MUST emit a structured failure object:
295
+
296
+ {
297
+ "failure_class": "...",
298
+ "runtime_code": "...",
299
+ "resolved_target": "...",
300
+ "attempted_recovery_strategies": ["..."],
301
+ "recovery_attempts": 3,
302
+ "final_state": "failed"
303
+ }
304
+
305
+ This ensures consistent observability across server and interact layers.
306
+
307
+ ---
308
+
309
+ ## 12. Success Metrics
310
+
311
+ - reduction in stuck interaction flows
312
+ - reduced repeated identical retries
313
+ - improved recovery success rate after first failure
314
+ - improved robustness under UI drift
315
+ - clearer structured failure outputs
316
+
317
+ ---
318
+
319
+ ## 13. Summary
320
+
321
+ This RFC introduces deterministic recovery and replanning for UI interaction failures, enabling the system to remain robust under ambiguity, drift, and execution uncertainty while preserving bounded and explainable behavior.
@@ -0,0 +1,253 @@
1
+ # RFC 011.1 — Recovery Contract Types & Runtime Wiring Spec
2
+
3
+ ## 1. Purpose
4
+
5
+ This document defines the typed runtime contract required to implement RFC 011 safely and consistently across:
6
+
7
+ - src/server
8
+ - src/interact
9
+ - shared action/result boundaries
10
+
11
+ It removes ambiguity from RFC 011 by formalising:
12
+ - enums
13
+ - state schemas
14
+ - execution payloads
15
+ - failure propagation format
16
+
17
+ ---
18
+
19
+ ## 2. Design Principle
20
+
21
+ Recovery is not a behaviour description.
22
+
23
+ It is a typed state machine over execution results.
24
+
25
+ All recovery decisions MUST be derivable from structured runtime data.
26
+
27
+ ---
28
+
29
+ ## 3. Core Runtime Types
30
+
31
+ ### 3.1 Failure Class
32
+
33
+ ```ts
34
+ type FailureClass =
35
+ | "TargetResolutionFailure"
36
+ | "ExecutionFailure"
37
+ | "VerificationFailure"
38
+ | "ControlConvergenceFailure"
39
+ | "SemanticMismatchFailure";
40
+ ```
41
+
42
+ ---
43
+
44
+ ### 3.2 Recovery Strategy
45
+
46
+ ```ts
47
+ type RecoveryStrategy =
48
+ | "re_resolve"
49
+ | "alternate_candidate"
50
+ | "state_refresh"
51
+ | "retry_adjustment"
52
+ | "step_back";
53
+ ```
54
+
55
+ ---
56
+
57
+ ### 3.3 Runtime Failure Code
58
+
59
+ ```ts
60
+ type RuntimeFailureCode =
61
+ | "ELEMENT_NOT_FOUND"
62
+ | "STALE_REFERENCE"
63
+ | "AMBIGUOUS_TARGET"
64
+ | "TIMEOUT"
65
+ | "ACTION_REJECTED"
66
+ | "VERIFICATION_FAILED"
67
+ | "EXPECT_STATE_MISMATCH"
68
+ | "CONTROL_CONVERGENCE_FAILED"
69
+ | "SEMANTIC_MISMATCH"
70
+ | "UNKNOWN";
71
+ ```
72
+
73
+ ---
74
+
75
+ ### 3.4 Recovery State
76
+
77
+ ```ts
78
+ interface RecoveryState {
79
+ failure_class: FailureClass;
80
+ runtime_code: RuntimeFailureCode;
81
+
82
+ recovery_strategy?: RecoveryStrategy;
83
+
84
+ recovery_attempts: number;
85
+ max_recovery_attempts: number;
86
+
87
+ retry_depth: number;
88
+ max_retry_depth: number;
89
+
90
+ is_terminal: boolean;
91
+
92
+ // derived from runtime retryable signal
93
+ retry_allowed?: boolean;
94
+ }
95
+ ```
96
+
97
+ ---
98
+
99
+ ## 4. Execution Result Integration (ActionExecutionResult)
100
+
101
+ This RFC does NOT introduce a new execution result type. Instead, it extends the existing runtime ActionExecutionResult / tool response envelope.
102
+
103
+ The recovery contract MUST be attached as an extension field.
104
+
105
+ ```ts
106
+ type ActionExecutionResult = {
107
+ success: boolean;
108
+
109
+ action_type: string;
110
+ target_id?: string;
111
+
112
+ // existing runtime error representation (already present in system)
113
+ failure_code?: RuntimeFailureCode;
114
+
115
+ // existing runtime retry signal
116
+ retryable?: boolean;
117
+
118
+ // RFC 011.1 extension
119
+ recovery?: RecoveryState;
120
+ };
121
+ ```
122
+
123
+ The recovery extension MUST NOT replace or duplicate existing failure_code semantics. Instead, failure_code remains the source input for deriving FailureClass and RecoveryState. RecoveryState is a structured interpretation layer built on top of existing execution results.
124
+
125
+ Existing retryable semantics remain authoritative for whether an action may be directly retried.
126
+
127
+ - retryable answers whether an execution may be retried.
128
+ - RecoveryState defines how recovery proceeds when failure occurs.
129
+
130
+ RecoveryState augments retryability; it does not replace it.
131
+
132
+ ---
133
+
134
+ ## 5. Server → Interact Contract
135
+
136
+ ### 5.1 Server responsibilities
137
+ - map raw runtime errors → RuntimeFailureCode
138
+ - attach initial FailureClass
139
+ - initialise recovery state defaults
140
+
141
+ ### 5.2 Interact responsibilities
142
+ - consume RecoveryState
143
+ - mutate recovery_attempts and retry_depth
144
+ - select RecoveryStrategy
145
+ - enforce bounds
146
+
147
+ Interact is the only layer allowed to mutate recovery state.
148
+
149
+ ---
150
+
151
+ ## 6. Deterministic Mapping Function
152
+
153
+ ```ts
154
+ function mapRuntimeCodeToFailureClass(code: RuntimeFailureCode): FailureClass {
155
+ switch (code) {
156
+ case "ELEMENT_NOT_FOUND":
157
+ case "STALE_REFERENCE":
158
+ case "AMBIGUOUS_TARGET":
159
+ return "TargetResolutionFailure";
160
+
161
+ case "TIMEOUT":
162
+ case "ACTION_REJECTED":
163
+ case "UNKNOWN":
164
+ return "ExecutionFailure";
165
+
166
+ case "VERIFICATION_FAILED":
167
+ case "EXPECT_STATE_MISMATCH":
168
+ return "VerificationFailure";
169
+
170
+ case "CONTROL_CONVERGENCE_FAILED":
171
+ return "ControlConvergenceFailure";
172
+
173
+ case "SEMANTIC_MISMATCH":
174
+ return "SemanticMismatchFailure";
175
+ }
176
+ }
177
+ ```
178
+
179
+ ---
180
+
181
+ ## 7. Step-back Semantics
182
+
183
+ Step-back MUST be implemented as re-entry into resolution + execution pipeline, NOT state rollback.
184
+
185
+ ---
186
+
187
+ ## 8. Budget Enforcement Rules
188
+
189
+ ```ts
190
+ const RECOVERY_LIMITS = {
191
+ max_recovery_attempts: 3,
192
+ max_retry_depth: 3
193
+ };
194
+ ```
195
+
196
+ - MUST increment recovery_attempts per recovery cycle
197
+ - MUST increment retry_depth per re-resolution loop
198
+ - MUST terminate when limits exceeded
199
+
200
+ ### Retryability Gating Rules
201
+
202
+ Recovery strategies MUST honor existing retryable semantics.
203
+
204
+ If retryable=false:
205
+ - direct identical-action retry MUST NOT be selected
206
+ - retry_adjustment MUST NOT be selected
207
+ - re_resolve or alternate_candidate SHOULD be preferred
208
+
209
+ If retryable=true:
210
+ - retry_adjustment MAY be selected subject to recovery budgets
211
+
212
+ This prevents contradiction between runtime execution constraints and recovery policy.
213
+
214
+ ---
215
+
216
+ ## 9. Failure Output Contract
217
+
218
+ ```ts
219
+ interface TerminalFailure {
220
+ failure_class: FailureClass;
221
+ runtime_code: RuntimeFailureCode;
222
+
223
+ resolved_target?: string;
224
+
225
+ recovery_attempts: number;
226
+
227
+ attempted_recovery_strategies: RecoveryStrategy[];
228
+
229
+ final_state: "failed";
230
+ }
231
+ ```
232
+
233
+ ---
234
+
235
+ ## 10. Integration Summary
236
+
237
+ This spec defines the typed contract required for implementing RFC 011 across server and interact layers.
238
+
239
+ ### 10.1 Runtime Wiring Constraint
240
+
241
+ This specification MUST be implemented by extending existing ActionExecutionResult objects in both src/server and src/interact.
242
+
243
+ No new parallel execution envelope is permitted.
244
+
245
+ RecoveryState is an additive field only.
246
+
247
+ Failure interpretation MUST continue to use existing failure_code fields as the source of truth.
248
+
249
+ ---
250
+
251
+ ## 11. Summary
252
+
253
+ This document formalises recovery as a deterministic, typed execution subsystem.