@debugg-ai/debugg-ai-mcp 4.4.1 → 6.0.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +61 -1
  2. package/README.md +32 -14
  3. package/dist/handlers/createEnvironmentHandler.js +4 -4
  4. package/dist/handlers/createProjectHandler.js +1 -1
  5. package/dist/handlers/environmentSessionsHandler.js +2 -18
  6. package/dist/handlers/probePageHandler.js +10 -13
  7. package/dist/handlers/runTestSuiteHandler.js +8 -9
  8. package/dist/handlers/searchEnvironmentsHandler.js +3 -6
  9. package/dist/handlers/searchExecutionsHandler.js +3 -11
  10. package/dist/handlers/searchProjectsHandler.js +1 -6
  11. package/dist/handlers/testPageChangesHandler.js +88 -183
  12. package/dist/handlers/triggerCrawlHandler.js +52 -44
  13. package/dist/handlers/updateEnvironmentHandler.js +2 -2
  14. package/dist/index.js +1 -1
  15. package/dist/services/caddy/caddyProxy.js +7 -6
  16. package/dist/services/index.js +18 -21
  17. package/dist/services/tunnel/debuggTransport.js +9 -9
  18. package/dist/services/tunnel/protocol/constants.js +3 -3
  19. package/dist/services/tunnel/transport.js +28 -9
  20. package/dist/services/{ngrok → tunnel}/tunnelFaultInjection.js +9 -15
  21. package/dist/services/{ngrok → tunnel}/tunnelManager.js +65 -131
  22. package/dist/services/{ngrok → tunnel}/tunnelRegistry.js +2 -2
  23. package/dist/services/tunnels.js +64 -46
  24. package/dist/services/verdictAdapter.js +167 -41
  25. package/dist/services/workflows.js +10 -1
  26. package/dist/tools/testPageChanges.js +1 -1
  27. package/dist/utils/authorizedCredentialHosts.js +8 -20
  28. package/dist/utils/confirmDestructive.js +1 -2
  29. package/dist/utils/errors.js +4 -5
  30. package/dist/utils/imageUtils.js +2 -2
  31. package/dist/utils/localReachability.js +62 -341
  32. package/dist/utils/resolveProject.js +1 -1
  33. package/dist/utils/telemetry.js +4 -4
  34. package/dist/utils/tunnelContext.js +11 -9
  35. package/dist/utils/tunnelDisposition.js +51 -69
  36. package/dist/utils/tunnelDomains.js +30 -21
  37. package/dist/utils/urlParser.js +38 -6
  38. package/package.json +2 -3
  39. package/dist/services/ngrok/error.js +0 -3
  40. package/dist/services/ngrok/ngrokAgentInspector.js +0 -210
  41. package/dist/services/ngrok/ngrokAgentSession.js +0 -49
  42. package/dist/services/ngrok/types.js +0 -1
  43. package/dist/services/tunnel/ngrokTransport.js +0 -165
@@ -16,8 +16,8 @@ import { resolveTargetUrl, buildContext, findExistingTunnel, ensureTunnel, acqui
16
16
  import { randomUUID } from 'node:crypto';
17
17
  import { detectRepoName } from '../utils/gitContext.js';
18
18
  import { disposeUnhealthyTunnel } from '../utils/tunnelDisposition.js';
19
- import { probeLocalPort, probeTunnelHealth, extractNgrokErrorCode } from '../utils/localReachability.js';
20
- import { extractLocalhostPort } from '../utils/urlParser.js';
19
+ import { probeLocalPort, probeTunnelHealth, extractTunnelErrorCode } from '../utils/localReachability.js';
20
+ import { extractLocalhostPort, rewriteLocalhostInText } from '../utils/urlParser.js';
21
21
  import { getCachedTemplateUuid, getCachedProjectUuid, invalidateTemplateCache, invalidateProjectCache, } from '../utils/handlerCaches.js';
22
22
  import { isTransientWorkflowError, transientReasonTag } from '../utils/transientErrors.js';
23
23
  import { Telemetry, TelemetryEvents } from '../utils/telemetry.js';
@@ -35,12 +35,12 @@ function getMaxTransientRetries() {
35
35
  return 1;
36
36
  return Math.min(n, 3);
37
37
  }
38
- // Bug z15n: scan run evidence for ngrok's interstitial marker. The marker is a
38
+ // Bug z15n: scan run evidence for the tunnel server's interstitial marker. It is a
39
39
  // stable, recognizable string the REMOTE BROWSER saw — positive evidence that it
40
40
  // hit our tunnel's error page rather than the user's app. Non-string parts are
41
41
  // serialized (the action trace is the usual carrier); a part we can't serialize
42
42
  // is simply skipped — it is not evidence either way.
43
- function findNgrokErrorMarker(parts) {
43
+ function findTunnelErrorMarker(parts) {
44
44
  for (const part of parts) {
45
45
  if (part === undefined || part === null || part === '')
46
46
  continue;
@@ -51,7 +51,7 @@ function findNgrokErrorMarker(parts) {
51
51
  catch {
52
52
  continue;
53
53
  }
54
- const code = extractNgrokErrorCode(text);
54
+ const code = extractTunnelErrorCode(text);
55
55
  if (code)
56
56
  return code;
57
57
  }
@@ -202,7 +202,7 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
202
202
  // --- Tunnel: reuse existing or provision a fresh one ---
203
203
  if (ctx.isLocalhost) {
204
204
  // Bead 1om: pre-flight local port probe BEFORE committing to backend
205
- // provision + ngrok session. If the user's dev server isn't listening,
205
+ // provision + tunnel session. If the user's dev server isn't listening,
206
206
  // fail in ~1.5s with a structured error instead of burning 5 minutes
207
207
  // on a browser agent trying to reach a dead tunnel.
208
208
  const localPort = extractLocalhostPort(ctx.originalUrl);
@@ -211,7 +211,7 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
211
211
  if (!probe.reachable) {
212
212
  const payload = {
213
213
  error: 'LocalServerUnreachable',
214
- message: `No server listening on 127.0.0.1:${localPort}. Start your dev server on that port before running check_app_in_browser. Probe result: ${probe.code} (${probe.detail ?? 'no detail'}).`,
214
+ message: `No server listening on 127.0.0.1:${localPort}.`,
215
215
  detail: {
216
216
  port: localPort,
217
217
  probeCode: probe.code,
@@ -244,27 +244,21 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
244
244
  catch (provisionError) {
245
245
  const msg = provisionError instanceof Error ? provisionError.message : String(provisionError);
246
246
  const diag = provisionError instanceof TunnelProvisionError ? ` ${provisionError.diagnosticSuffix()}` : '';
247
- throw new Error(`Failed to provision tunnel for ${ctx.originalUrl}. ` +
248
- `The remote browser needs a secure tunnel to reach your local dev server. ` +
249
- `Make sure your dev server is running on the specified port and try again. ` +
250
- `(Detail: ${msg})${diag}`);
247
+ throw new Error(`Failed to provision tunnel for ${ctx.originalUrl}: ${msg}${diag}`);
251
248
  }
252
249
  provision = tunnel;
253
250
  try {
254
251
  ctx = await ensureTunnel(ctx, tunnel.tunnelKey, tunnel.tunnelId, tunnel.keyId, () => client.tunnels.revoke(tunnel),
255
252
  // The provision IS the transport selection. Omitting it here is
256
- // not a no-op: ensureTunnel falls back to ngrok, so the flagship
257
- // tool would keep using ngrok however the backend answered, and
258
- // would revoke through the ngrok endpoint. The other three
253
+ // not a no-op: without it ensureTunnel gets no relayUrl or
254
+ // tunnelDomain at all, so the flagship tool cannot connect a
255
+ // tunnel the backend just issued. The other three
259
256
  // handlers pass it; this one was missed.
260
257
  tunnel);
261
258
  }
262
259
  catch (tunnelError) {
263
260
  const msg = tunnelError instanceof Error ? tunnelError.message : String(tunnelError);
264
- throw new Error(`Tunnel creation failed for ${ctx.originalUrl}. ` +
265
- `Could not establish a secure connection between the remote browser and your local port. ` +
266
- `Verify your dev server is running and the port is accessible. ` +
267
- `(Detail: ${msg})`);
261
+ throw new Error(`Tunnel creation failed for ${ctx.originalUrl}: ${msg}`);
268
262
  }
269
263
  logger.info(`Tunnel ready: ${ctx.targetUrl} (id: ${ctx.tunnelId})`);
270
264
  }
@@ -287,7 +281,7 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
287
281
  : undefined,
288
282
  });
289
283
  // Bead 1om: verify traffic actually flows through the tunnel. The
290
- // tunnel can be established (ngrok.connect returns OK) yet refuse
284
+ // tunnel can be established (connect returns OK) yet refuse
291
285
  // to forward traffic — e.g., IPv4/IPv6 bind mismatch, or the dev
292
286
  // server died between the pre-flight probe and here. Catch it now,
293
287
  // in ~1s, not via a 5-minute browser-agent false-pass.
@@ -296,15 +290,15 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
296
290
  if (!health.healthy) {
297
291
  const payload = {
298
292
  error: 'TunnelTrafficBlocked',
299
- message: `Tunnel was established but traffic isn't reaching the dev server. ${health.detail ?? ''} Common causes: dev server binds to 0.0.0.0 or ::1 but not 127.0.0.1; dev server crashed; firewall.`,
293
+ message: `Tunnel established; a request through it to 127.0.0.1:${extractLocalhostPort(ctx.originalUrl)} failed: ${health.detail ?? health.code}.`,
300
294
  detail: {
301
295
  code: health.code,
302
296
  status: health.status,
303
- ngrokErrorCode: health.ngrokErrorCode,
297
+ tunnelErrorCode: health.tunnelErrorCode,
304
298
  elapsedMs: health.elapsedMs,
305
299
  },
306
300
  };
307
- logger.warn(`Tunnel health probe failed for ${ctx.targetUrl}: ${health.code} ${health.ngrokErrorCode ?? ''} in ${health.elapsedMs}ms`);
301
+ logger.warn(`Tunnel health probe failed for ${ctx.targetUrl}: ${health.code} ${health.tunnelErrorCode ?? ''} in ${health.elapsedMs}ms`);
308
302
  // Evict ONLY on a code proving the endpoint is gone; every other
309
303
  // failure keeps the tunnel we are already paying for, because a
310
304
  // teardown+re-provision costs two billed hours and this probe cannot
@@ -346,22 +340,18 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
346
340
  : Promise.resolve(undefined),
347
341
  ]);
348
342
  if (!templateUuid) {
349
- throw new Error('App Evaluation Workflow Template not found. ' +
350
- 'Ensure the template is seeded in the backend (GET /api/v1/workflows/?is_template=true).');
343
+ throw new Error(`App Evaluation workflow template not found (slug "${getEvalTemplateSlug()}").`);
351
344
  }
352
345
  // Fail fast + actionable when project_id can't be resolved (pinned backend
353
346
  // semantics: project_id is required). Surfacing "link this repo to a
354
347
  // project" now — before executeWorkflow — beats letting a backend workflow
355
348
  // node fail mid-run several minutes into the evaluation.
356
349
  if (!projectUuid) {
357
- const detail = repoName
358
- ? `Repo "${repoName}" isn't linked to a DebuggAI project.`
359
- : 'No git repository was detected to resolve a project from.';
360
350
  const payload = {
361
351
  error: 'ProjectRequired',
362
- message: `project_id is required but could not be resolved. ${detail} ` +
363
- 'Link this repo to a project at https://debugg.ai (Projects → connect your repository), then retry. ' +
364
- 'To evaluate a different repo than the current one, pass repoName.',
352
+ message: repoName
353
+ ? `No DebuggAI project found for repo "${repoName}".`
354
+ : 'No git repository detected and no repoName passed.',
365
355
  };
366
356
  logger.warn(`check_app_in_browser: ${payload.message}`);
367
357
  return { content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }], isError: true };
@@ -369,7 +359,12 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
369
359
  // --- Build context data (camelCase here — axiosTransport auto-converts to snake_case) ---
370
360
  const contextData = {
371
361
  targetUrl: ctx.targetUrl ?? originalUrl,
372
- question: input.description,
362
+ // The goal is read by a browser in OUR cloud. A goal that still says
363
+ // "go to http://localhost:3017" sends it to its own loopback, where it
364
+ // gets connection refused and the run is recorded as the app failing —
365
+ // with the tunnel working the whole time. Rewrite it onto the same
366
+ // tunnel the targetUrl above uses.
367
+ question: rewriteLocalhostInText(input.description, ctx.targetUrl),
373
368
  };
374
369
  if (projectUuid) {
375
370
  contextData.projectId = projectUuid;
@@ -386,7 +381,8 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
386
381
  if (input.auth.precondition)
387
382
  auth.precondition = input.auth.precondition;
388
383
  // Bead go1m: entryUrl/deepUrl are URLs the run NAVIGATES, so they need the
389
- // same localhost→tunnel rewrite `url` gets (contextData.targetUrl above).
384
+ // same localhost→tunnel rewrite `url` and the goal text get
385
+ // (contextData.targetUrl and contextData.question above).
390
386
  // Forwarded verbatim they reached the remote browser as literal localhost
391
387
  // and it dialled its own loopback: offscope_host + ERR_CONNECTION_REFUSED.
392
388
  for (const field of ['entryUrl', 'deepUrl']) {
@@ -397,11 +393,8 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
397
393
  if (!rewrite.ok) {
398
394
  const payload = {
399
395
  error: 'AuthUrlPortMismatch',
400
- message: `auth.${field} points at localhost:${rewrite.port} but url points at ` +
401
- `localhost:${rewrite.primaryPort}. A single call tunnels exactly one local ` +
402
- `port, so the remote browser cannot reach both. Put the login page and the ` +
403
- `target page on the same port, or drop auth.${field} and pass username/password ` +
404
- `at the top level so the agent signs in on the page it already reached.`,
396
+ message: `auth.${field} points at localhost:${rewrite.port}; url points at ` +
397
+ `localhost:${rewrite.primaryPort}. One call tunnels one local port.`,
405
398
  detail: { field, authPort: rewrite.port, urlPort: rewrite.primaryPort, url: originalUrl },
406
399
  };
407
400
  logger.warn(`check_app_in_browser: ${payload.message}`);
@@ -546,11 +539,12 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
546
539
  // next line (line 183 in services/workflows.ts), so there's no
547
540
  // post-pollExecution progress emission that could race the response.
548
541
  if (TERMINAL_STATUSES.has(exec.status)) {
549
- const terminalOutcome = exec.state?.outcome ?? exec.status;
542
+ // Status only: state.outcome is an internal value and can be one the
543
+ // user-facing verdict retired ('inconclusive', 'unverified').
550
544
  await progressCallback({
551
545
  progress: TOTAL_STEPS,
552
546
  total: TOTAL_STEPS,
553
- message: `Complete: ${terminalOutcome}`,
547
+ message: `Complete: ${exec.status}`,
554
548
  });
555
549
  return;
556
550
  }
@@ -622,93 +616,36 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
622
616
  const duration = Date.now() - startTime;
623
617
  // --- Format result ---
624
618
  const nodes = finalExecution.nodeExecutions ?? [];
625
- // subworkflow.run is the current graph shape — carries outcome, actionHistory, screenshot
619
+ // subworkflow.run carries an inline base64 screenshot on some graph shapes;
620
+ // only used for the image block below.
626
621
  const subworkflowNode = nodes.find(n => n.nodeType === 'subworkflow.run');
627
- // surfer.execute_task and brain.step/brain.evaluate are older graph shapes
628
- const surferNode = nodes.find(n => n.nodeType === 'surfer.execute_task');
629
- // Action trace: brain.step nodes (old) → subworkflow.run actionHistory (new)
630
- const brainSteps = nodes
631
- .filter(n => n.nodeType === 'brain.step' && n.outputData)
632
- .sort((a, b) => a.executionOrder - b.executionOrder);
633
- const actionTrace = brainSteps.map((n, i) => {
634
- const d = n.outputData.decision ?? n.outputData;
635
- return {
636
- step: i + 1,
637
- action: d.actionType ?? d.action_type,
638
- intent: d.intent,
639
- target: d.target,
640
- value: d.value ?? undefined,
641
- success: n.outputData.success ?? n.status === 'success',
642
- durationMs: n.executionTimeMs,
643
- };
644
- });
645
- const subworkflowHistory = subworkflowNode?.outputData?.actionHistory;
646
- if (actionTrace.length === 0 && Array.isArray(subworkflowHistory) && subworkflowHistory.length > 0) {
647
- subworkflowHistory.forEach((step, i) => {
648
- actionTrace.push({
649
- step: i + 1,
650
- action: step.actionType ?? step.action_type ?? step.action,
651
- intent: step.intent,
652
- target: step.target,
653
- value: step.value ?? undefined,
654
- success: step.success ?? true,
655
- durationMs: step.durationMs ?? step.duration_ms ?? undefined,
656
- });
657
- });
658
- }
659
- // Evaluation: RELAY the backend's block; derive one only for older backends.
660
- //
661
- // The backend computes `evaluation` from the SAME verdict as the headline
662
- // outcome (sentinal-sk5sl.1) precisely so one payload cannot say
663
- // outcome='inconclusive' at the top and evaluation.outcome='unknown'
664
- // underneath. Rebuilding it here from raw subworkflow node output
665
- // reintroduced that contradiction client-side, and worse: the node's
666
- // `success` is a bare boolean, so "could not determine" arrived as
667
- // passed:false. The backend deliberately sends passed:null for
668
- // inconclusive — an undetermined run is not a failed one.
669
- //
670
- // Deriving from nodes stays ONLY as the pre-contract fallback.
671
- const evalNode = nodes.find(n => n.nodeType === 'brain.evaluate');
672
- let evaluation;
673
- if (finalExecution.evaluation && typeof finalExecution.evaluation === 'object') {
674
- evaluation = finalExecution.evaluation;
675
- }
676
- else if (evalNode?.outputData) {
677
- evaluation = {
678
- passed: evalNode.outputData.passed,
679
- outcome: evalNode.outputData.outcome,
680
- reason: evalNode.outputData.reason,
681
- verifications: evalNode.outputData.verifications,
682
- };
683
- }
684
- else if (subworkflowNode?.outputData) {
685
- const sw = subworkflowNode.outputData;
686
- evaluation = {
687
- passed: sw.success,
688
- outcome: sw.outcome,
689
- reason: sw.error || undefined,
690
- };
691
- }
692
622
  // --- Relay the backend's explicit verdict (bead 56kd.2) ---
693
623
  // ONE adapter owns the backend-field → MCP mapping (services/verdictAdapter).
694
- // We consume the verdict/budget/evidence VERBATIM — no fabricated outcome,
695
- // no success default-false, no synthesized 'assertion-mismatch'. A
696
- // missing/unknown verdict surfaces as 'inconclusive', never as a failure.
697
624
  // On a poll-deadline timeout (bead 56kd.3) pollExecution returns the last
698
625
  // observed execution flagged `timedOut`; force outcome 'timeout' since there
699
- // is no terminal backend verdict, and shape its partial evidence below.
626
+ // is no terminal backend verdict.
700
627
  const timedOut = finalExecution.timedOut === true;
701
628
  const verdict = adaptVerdict(finalExecution, {
702
- fallbackBudget: MAX_EXEC_STEPS,
703
629
  outcomeOverride: timedOut ? 'timeout' : undefined,
630
+ // real numbers from the deadline path, so the reason is a record of what
631
+ // we observed rather than a fixed sentence
632
+ pollTimeout: timedOut ? finalExecution.pollTimeout : undefined,
704
633
  });
705
- // Evidence: prefer the backend's contract evidence.actionTrace; fall back to
706
- // the legacy node-extracted trace while the backend contract deploys.
707
- const relayActionTrace = verdict.actionTrace ?? actionTrace;
634
+ const relayActionTrace = verdict.actionTrace;
635
+ // Evaluation: the backend derives it from the SAME verdict as the headline
636
+ // (sentinal-sk5sl.1), so its passed/outcome/reason are that verdict a second
637
+ // time — and passed is just outcome === 'pass'. Relay only what the verdict
638
+ // does not already carry (e.g. verifications); omit it when that is nothing.
639
+ let evaluation;
640
+ if (finalExecution.evaluation && typeof finalExecution.evaluation === 'object') {
641
+ const { passed: _p, outcome: _o, reason: _r, ...rest } = finalExecution.evaluation;
642
+ if (Object.keys(rest).length > 0)
643
+ evaluation = rest;
644
+ }
708
645
  // --- Post-hoc tunnel reclassification (bugs z15n, 4bui) ---
709
646
  // The pre-flight probe above proves the tunnel was alive when we handed it to
710
647
  // the remote browser — it can still die mid-run. When it does, the browser
711
- // lands on ngrok's ERR_NGROK_* interstitial and the backend, which only sees
648
+ // lands on the tunnel server's DEBUGG_TUNNEL_* interstitial and the backend, which only sees
712
649
  // "the page didn't contain what I was asked about", returns a normal 'fail'
713
650
  // whose reason blames the USER'S page for OUR dead tunnel (execution
714
651
  // a8f07747: 217s, 7 steps, failureCategory 'fail').
@@ -716,7 +653,7 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
716
653
  // THE MARKER IS REQUIRED (bug 4bui). Reclassifying overrides the backend's
717
654
  // verdict, so it demands positive evidence of the claim we are actually
718
655
  // making: that the remote browser hit OUR error page DURING THE RUN. Only
719
- // the ERR_NGROK_* marker recorded BY the run is evidence of that.
656
+ // the DEBUGG_TUNNEL_* marker recorded BY the run is evidence of that.
720
657
  //
721
658
  // The re-probe is NOT such evidence and can no longer trigger this on its
722
659
  // own. It answers a different question — "is the tunnel healthy NOW?" —
@@ -728,12 +665,12 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
728
665
  // independently returned a FALSE NETWORK_ERROR on healthy servers ~1 in 5
729
666
  // runs (bug k6yq), so the false positive was reachable with nothing
730
667
  // whatsoever wrong. (k6yq is now fixed: the cause was not the suspected DNS
731
- // race but an HTTP/2 GOAWAY from the ngrok edge on a freshly created
668
+ // race but a connection-level flake against a freshly created
732
669
  // tunnel, which probeTunnelHealth now retries. The marker requirement
733
670
  // stands on its own regardless — the probe never decides this.)
734
671
  //
735
672
  // Requiring the marker loses no coverage: a real mid-run death fires BOTH
736
- // arms (live-confirmed — re-probe NETWORK_ERROR *and* marker ERR_NGROK_3200),
673
+ // arms (live-confirmed — re-probe NETWORK_ERROR *and* an endpoint-gone marker),
737
674
  // so the marker alone still catches it. The probe is kept purely as
738
675
  // CORROBORATION in `detail` — it tells the caller whether the tunnel is
739
676
  // still down now or has since recovered. Per epic 56kd ("relay honestly,
@@ -741,7 +678,7 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
741
678
  // during the run is the relay inventing a cause.
742
679
  let tunnelFault;
743
680
  if (verdict.outcome === 'fail' && ctx.isLocalhost && ctx.tunnelId && ctx.targetUrl) {
744
- const marker = findNgrokErrorMarker([
681
+ const marker = findTunnelErrorMarker([
745
682
  verdict.reason,
746
683
  finalExecution.state?.error,
747
684
  finalExecution.errorMessage,
@@ -752,45 +689,34 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
752
689
  // never decides whether we reclassify, only what we report alongside it.
753
690
  const probe = await probeTunnelHealth(ctx.targetUrl).catch(() => undefined);
754
691
  if (marker) {
755
- tunnelFault = { probe, ngrokErrorCode: marker };
692
+ tunnelFault = { probe, tunnelErrorCode: marker };
756
693
  logger.warn(`Reclassifying backend 'fail' as an infrastructure fault for ${executionUuid}: ` +
757
694
  `the run recorded ${marker} (re-probe now: ` +
758
695
  `${probe ? (probe.healthy ? 'healthy — tunnel has since recovered' : probe.code) : 'unavailable'})`);
759
696
  }
760
697
  else if (probe && !probe.healthy) {
761
698
  // Deliberately NOT reclassifying. The tunnel looks unhealthy now, but
762
- // the run recorded no ngrok interstitial, so we have no evidence the
699
+ // the run recorded no tunnel interstitial, so we have no evidence the
763
700
  // browser ever saw one — the tunnel most likely died after the run (or
764
701
  // the probe flaked). Relay the backend's verdict and log the tension.
765
702
  logger.info(`Post-run tunnel re-probe for ${executionUuid} was unhealthy (${probe.code}) but the run ` +
766
- 'recorded no ERR_NGROK_* marker, so the browser reached the app during the run. Relaying ' +
703
+ 'recorded no DEBUGG_TUNNEL_* marker, so the browser reached the app during the run. Relaying ' +
767
704
  "the backend's verdict verbatim rather than blaming the tunnel.");
768
705
  }
769
706
  }
770
707
  const responsePayload = {
771
708
  outcome: verdict.outcome,
772
- success: verdict.success,
709
+ ...(verdict.reason ? { reason: verdict.reason } : {}),
710
+ // platform-98fv.16: never attempted a test — no verdict, the backend's reason verbatim
711
+ ...(verdict.skipped ? { skipped: true } : {}),
712
+ ...(verdict.skipReason ? { skipReason: verdict.skipReason } : {}),
773
713
  status: finalExecution.status,
774
- stepsTaken: verdict.stepsTaken,
775
- stepsBudget: verdict.stepsBudget, // from the response (bead 56kd.2)
776
- stepsRemaining: verdict.stepsRemaining,
777
- targetUrl: originalUrl,
778
714
  executionId: executionUuid,
715
+ targetUrl: originalUrl,
779
716
  durationMs: finalExecution.durationMs ?? duration,
780
717
  };
781
- // failureCategory = the outcome verbatim (fail | inconclusive | error |
782
- // timeout); OMITTED on success. No inference, no 'assertion-mismatch'.
783
- if (verdict.failureCategory)
784
- responsePayload.failureCategory = verdict.failureCategory;
785
- if (verdict.reason)
786
- responsePayload.reason = verdict.reason;
787
- // --- Which identity did the run actually sign in as? ---
788
- // A login as the wrong account and an app rejecting the right one produce
789
- // the SAME symptom ("login failed") and used to be indistinguishable from
790
- // the result, so an environment-default substitution read as an application
791
- // bug. Relay the logins verbatim, and when the caller named an account but
792
- // an environment default was used anyway, say so explicitly rather than
793
- // leaving the caller to infer it from a failed check.
718
+ if (verdict.budget)
719
+ responsePayload.budget = verdict.budget;
794
720
  // For "navigate and describe what you see", the answer IS the deliverable —
795
721
  // and it reached callers only incidentally, buried in actionTrace[0].intent,
796
722
  // which the verify-gate rewrites when it disagrees with the page. Surface it.
@@ -800,10 +726,12 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
800
726
  responsePayload.logins = verdict.logins;
801
727
  if (verdict.loginError)
802
728
  responsePayload.loginError = verdict.loginError;
803
- // Bead b5x6: only a SUBMITTED env-default login under a DIFFERENT account
804
- // counts. A refused/skipped login (offscope_host, no form) typed nothing,
805
- // and the env's stored credential may be the very account that was named —
806
- // warning on either states something that did not happen.
729
+ // Bead b5x6: the caller named an account and the run SUBMITTED an
730
+ // environment default for a different one. Stated as the two facts — what
731
+ // was asked for, what was used — and nothing about what to conclude.
732
+ // Only a SUBMITTED env-default login under a DIFFERENT account counts: a
733
+ // refused/skipped login typed nothing, and the env's stored credential may
734
+ // be the very account that was named.
807
735
  const requestedIdentity = input.username
808
736
  ?? input.auth?.username
809
737
  ?? input.loginCredentials?.[0]?.username;
@@ -816,45 +744,28 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
816
744
  responsePayload.credentialWarning = {
817
745
  requested: requestedIdentity,
818
746
  used: [...new Set(substituted.map(l => l.username))],
819
- message: `This run signed in with an environment default credential even though ` +
820
- `'${requestedIdentity}' was specified. Treat a login failure here as a ` +
821
- `credential-resolution problem, not an application failure.`,
822
747
  };
823
748
  logger.warn(`check_app_in_browser: requested identity '${requestedIdentity}' but the run used ` +
824
749
  `environment-default credential(s): ${responsePayload.credentialWarning.used.join(', ')}`);
825
750
  }
826
- // Bug z15n: OUR tunnel died mid-run, so this 'fail' describes our error page,
827
- // not the user's app. Relay it as a distinct, retryable infrastructure class
828
- // so an automated caller doesn't record a UI regression that never happened.
829
- // The backend's original verdict is preserved verbatim, never swallowed.
830
- //
831
- // Bug 4bui: the stated cause leads with the MARKER, because the marker is the
832
- // evidence that justified getting here — the run itself recorded ngrok's
833
- // interstitial. The probe only corroborates (and may legitimately say the
834
- // tunnel has recovered by now), so it rides in `detail`, never as the cause.
751
+ // Bug z15n: the run itself recorded our tunnel's DEBUGG_TUNNEL_* interstitial,
752
+ // so its 'fail' describes our error page, not the user's app. That is an
753
+ // MCP-observed fact, so the MCP may state it: outcome 'error', a reason
754
+ // built from the marker and the probe result, the backend's own verdict kept
755
+ // verbatim under `backendVerdict`. No commentary on top.
835
756
  if (tunnelFault) {
836
- const { probe, ngrokErrorCode } = tunnelFault;
757
+ const { probe, tunnelErrorCode } = tunnelFault;
837
758
  responsePayload.backendVerdict = { outcome: verdict.outcome, reason: verdict.reason };
838
759
  responsePayload.outcome = 'error';
839
- responsePayload.success = false;
840
- responsePayload.failureCategory = 'infrastructure';
841
760
  responsePayload.error = 'TunnelOfflineDuringRun';
842
- responsePayload.message =
843
- 'During this run the remote browser landed on our tunnel\'s ngrok error page instead of your ' +
844
- 'app, so the check evaluated our error page rather than your UI. This is an infrastructure ' +
845
- 'fault on our side, not a failed check — retry it. The backend\'s original verdict is ' +
846
- 'preserved under `backendVerdict`.';
847
- responsePayload.reason =
848
- `The run recorded ngrok's ${ngrokErrorCode} interstitial, so the remote browser reached ` +
849
- 'our tunnel error page instead of your app.' +
850
- (probe
851
- ? probe.healthy
852
- ? ' (Our re-probe after the run found the tunnel reachable again, so it has since recovered.)'
853
- : ` (Our re-probe after the run also failed: ${probe.code}` +
854
- `${probe.status ? ` (HTTP ${probe.status})` : ''}.)`
855
- : '');
761
+ const probeFact = probe
762
+ ? probe.healthy
763
+ ? 'post-run tunnel probe: reachable'
764
+ : `post-run tunnel probe: ${probe.code}${probe.status ? ` (HTTP ${probe.status})` : ''}`
765
+ : 'post-run tunnel probe: not run';
766
+ responsePayload.reason = `The run recorded the tunnel error page ${tunnelErrorCode}; ${probeFact}.`;
856
767
  responsePayload.detail = {
857
- ngrokErrorCode,
768
+ tunnelErrorCode,
858
769
  probeCode: probe?.code,
859
770
  probeStatus: probe?.status,
860
771
  probeHealthy: probe?.healthy,
@@ -869,19 +780,14 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
869
780
  responsePayload.agentError = finalExecution.state.error;
870
781
  if (finalExecution.errorMessage)
871
782
  responsePayload.errorMessage = finalExecution.errorMessage;
872
- if (finalExecution.errorInfo?.failedNodeId)
873
- responsePayload.failedNode = finalExecution.errorInfo.failedNodeId;
783
+ if (finalExecution.errorInfo)
784
+ responsePayload.errorInfo = finalExecution.errorInfo;
874
785
  if (executeResponse.resolvedEnvironmentId)
875
786
  responsePayload.resolvedEnvironmentId = executeResponse.resolvedEnvironmentId;
876
787
  if (executeResponse.resolvedCredentialId)
877
788
  responsePayload.resolvedCredentialId = executeResponse.resolvedCredentialId;
878
- if (surferNode?.outputData) {
879
- responsePayload.surferOutput = sanitizeResponseUrls(surferNode.outputData, ctx);
880
- }
881
- // Backend release 2026-04-25: browser_session block on execution detail
882
- // carries presigned S3 URLs for HAR + console log + recording. Pass through
883
- // verbatim — sanitizeResponseUrls below only strips ngrok hosts so S3 URLs
884
- // are preserved. Resolves client-feedback items #1 (network) + #7 (console).
789
+ // browser_session block: presigned S3 URLs for HAR + console log + recording,
790
+ // passed through verbatim.
885
791
  if (finalExecution.browserSession) {
886
792
  responsePayload.browserSession = finalExecution.browserSession;
887
793
  }
@@ -962,7 +868,6 @@ async function testPageChangesHandlerInner(input, context, rawProgressCallback)
962
868
  ? [resourceLinkBlock(gifUrl, 'run-recording.gif', {
963
869
  mimeType: 'image/gif',
964
870
  title: 'Run recording',
965
- description: 'Animated recording of the run (presigned URL — open or fetch on demand).',
966
871
  })]
967
872
  : []),
968
873
  ...artifactResourceLinks(sanitizedPayload.browserSession),