Repository navigation
feat: mm logs on mobile (Hermes console errors and uncaught exceptions) - #142
Open
cryptotavares wants to merge 9 commits into
Open
cryptotavares wants to merge 9 commits into
cryptotavares wants to merge 9 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the mm CLI v2 effort: ticket
P2-29(Phase 2).Problem
On mobile,
mm logs,mm eventsandmm networkreturnMM_TOOL_NOT_SUPPORTED_ON_PLATFORM. Agents fall back to ad-hocconsolewrappers viamm cdp, which miss errors before install or after a JS reload and do not match the Extension output shape.Hermes also never emits
Runtime.exceptionThrown. Uncaught exceptions arrive only as theconsole.errorReact Native logs, indistinguishable from a caughtconsole.error(err).Solution
HermesConsoleSourcesubscribes to the session's persistentHermesClientand writes into the sharedEventBuffer.SessionEventstakes a connection factory instead of aBrowserContext.getActiveSessionEventsselects the browserCdpManageror the mobile driver'sHermesClient.ConsoleSourceand the browser path stay unchanged.mm launchstarts session events on mobile too and can wait up toSESSION_EVENTS_START_WAIT_MSfor the inspector.Runtime.consoleAPICalledgoes throughtoConsoleRecord, level filtering and redaction. Pre-enable replays and#InstanceAgentsynthetic messages are dropped. While a session is open, the app serializes everyconsole.*call with previews, like an open DevTools.ErrorUtilswrapper (globalThis.__mmLogsHookV1) reports{ fatal, text }to a per-session binding, then invokes the previous handler with the samethisand arguments and returns its result. The source joins the report and console echo into one record (newest-first, full text when matching an earlier console error, first line within 5 s for a trailing echo). The wrapper stays in the app aftermm cleanupuntil the next JS reload, reporting to a binding nobody listens to (harmless).Runtime.disable.startkeeps its listeners even if Metro is not ready and enables oncontextCreated(connect/reconnect). A failedRuntime.enableis retried every 500 ms for up to 60 s and reports one capture error at the deadline. A new execution context reinstalls the wrapper.mm cdp Runtime.disableis refused withMM_CDP_BLOCKEDon the session client;Runtime.enableand other methods pass through.flowchart TD L["mm launch / mm logs / mm events"] --> G{"getActiveSessionEvents:<br/>mobile driver?"} G -->|browser| B["SessionEvents on CdpManager<br/>(ConsoleSource, NetworkSource)"] G -->|ios / android| H["SessionEvents on session HermesClient<br/>(HermesConsoleSource)"] H --> E["Runtime.addBinding + Runtime.enable<br/>(on start or contextCreated)"] E --> R["Pre-enable replay or #InstanceAgent"] R --> X["Dropped. Not recorded."] E --> K["Install ErrorUtils wrapper<br/>(__mmLogsHookV1)"] K --> C["consoleAPICalled -> console record<br/>target.kind: hermes"] K --> U["bindingCalled -> mark newest match<br/>uncaught, fatal"] C --> BUF[("Shared EventBuffer:<br/>seq, cursor, gap, summary")] U --> BUF B --> BUF RL["JS reload: executionContextCreated"] --> K RC["Socket lost: contextCreated reconnect"] --> E classDef new fill:#fff3cd,stroke:#d39e00 classDef stop fill:#f8d7da,stroke:#c82333 class G,H,E,K,C,U,RL,RC new class R,X stopYellow boxes are new. Red boxes stop a message.
What the agent sees
Live iOS run (
console.error+ uncaught throw with the same first line), thenmm logs --cursor 45:mm logs/mm eventson mobiletarget.kind: "hermes"records.mm networkon mobileMM_TOOL_NOT_SUPPORTED_ON_PLATFORM(P2-30).console.erroruncaught: true(fatal: truewhen React Native passedisFatal). App error handling runs unchanged.mm logs configure --levels.DevSettings.reload())[CONNECTION_LOST])captureErrors + 1; re-enables oncontextCreated(reconnect).mm cdp Runtime.disableon session clientMM_CDP_BLOCKED.Runtime.enableand other methods pass through.Not captured: native crashes and native logs (use
mm device-logs), pre-connect Hermes replays, messages sent while disconnected, and release builds without Metro.Decisions for reviewers
device-mcpchange (trackContexts: false)contextCreated(connect/reconnect) and sends its ownRuntime.enableandRuntime.addBinding, avoiding a duplicate enable fromtrackContexts.Runtime.enablepass-through; block onlyRuntime.disableRuntimeDomainAgent::enable()returns early when already enabled on the same socket, so a second enable does not replay console messages (verified live on iOS). Blocking onlyRuntime.disableavoids masking a failed start.fatal?: trueonConsoleRecordP2-29. Reflects React Native'sisFatalflag; the app's own handler may still swallow the error (MetaMask does this for Ledger and Keystone errors).ErrorUtilswrapper (__mmLogsHookV1)ErrorUtilsexists in every React Native build (unlike LogBox). Versioned global lets future cores install a new wrapper cleanly. Wrapper stays aftermm cleanupuntil reload, calling an inert binding name.ConsoleRecorderextraction; retry inside the sourceConsoleSourcestays untouched onmain.HermesConsoleSourcekeeps its listeners on a failed connect, retries a failedRuntime.enableevery 500 ms for up to 60 s, and enables again oncontextCreated.ConsoleObjectGroupevery 200 console eventsReview guide
Read the files in this order:
src/events/hermes-console-source.tshookScript(__mmLogsHookV1, observe-only),#enablingreplay drop,contextCreatedconnect/reconnect guard,#takeRecentjoinsrc/events/session-events.tsgetActiveSessionEventssrc/platform/mobile-platform-driver.ts,types.tsgetHermesEventClient,Runtime.disableblocksrc/tools/{logs,events,launch,registry}.ts,types/events.ts,cli/mm.tsevents/logs, mobile launch start,fatalfield*.test.tsSKILL.md,README.mdmm logson mobile" section andlogstable rowTesting
yarn build,yarn lint,attwandCI=1 yarn testpass (77 files, 3010 tests). Coverage: 98.12% statements, 95.40% branches, 97.36% functions, 98.21% lines (floors: 97 / 94 / 96 / 97).hermes-console-source.test.ts(28 tests): VM sandbox tests forhookScript(not-ready, idempotent install, forwardsthis/args/return value, multi-binding dedupe, re-wraps app handler, survives throwing binding); source tests for redaction, levels, replay/#InstanceAgentdrop, both join orders, same-head caught + uncaught errors and two console errors, reload reinstall + retry + timeout, failed enable retry and deadline, connect-after-failed-start, reconnect + failed re-enable, start failure, unsubscribe and object-group release.session-events.test.ts,mobile-platform-driver.hermes.test.ts,logs.test.ts,launch.test.ts,platform-gating.test.ts,registry.test.ts: mobile routing,Runtime.disableblock +Runtime.enablepass-through, platform gating.iPhone 17 Pro, read-only login screen, no unlock, Metro 8085,device-mcp0.10.0):__mmLogsHookV1installed aftermm launchconsole.error('mm-p2-29 before')->mm logsseq: 44)mm cdp Runtime.enablesent live ->mm logs --cursor 44result: {}, 0 replayed duplicates)mm cdp Runtime.callFunctionOnafter secondRuntime.enablevalue: 42)mm cdp Runtime.disableon session clientMM_CDP_BLOCKED)Error('mm-p2-29 uncaught')uncaught: true,fatal: true)mm-p2-29 dup)uncaught: true, fatal: true)DevSettings.reload()-> wrapper reinstalled (+10 s), newconsole.error+ uncaught capturedcaptureErrors: 0)Docs changed
SKILL.md: un-gated Session events, added concise "mm logson mobile" section covering uncaught/fatalaccuracy, reloads/reconnects, DevTools serialization overhead,Runtime.disableguard and "Not captured".README.md: updatedeventsandlogsrows to reference mobile Hermes runtime (andSKILL.md).src/cli/mm.ts: updatedmm --helpsession events heading andlogsdescription.Follow-ups
P2-30(mm networkon mobile) adds a network source on the sameSessionEvents<HermesEventClient>and removesnetworkfromBROWSER_ONLY_TOOLS.