Skip to content

fix(maestro): bound selector regex matching - #5300

Closed
thymikee wants to merge 17 commits into
fix/daybreak-android-helper-boundariesfrom
fix/daybreak-maestro-selector-regex
Closed

thymikee wants to merge 17 commits into
fix/daybreak-android-helper-boundariesfrom
fix/daybreak-maestro-selector-regex

Conversation

@thymikee

@thymikee thymikee commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Closed as superseded by #5340 on the 0.22 remediation line. Continue review and implementation there. Historical validation below remains attributed to its original commits; closure does not claim the replacements are merge-ready.

Summary

Bound Maestro selector regex work with an AST gate and typed errors. Charge multiline work only at starts that can match the mandatory literal prefix. Carry uncertainty through the applicable tree or position relation and reuse the parent result during ranking. The runtime bundles @eslint-community/regexpp. Stacked on #5245.

Before / after

  • tapOn: {text: 'Sign (in|up).*'} selects Sign in beside dense unrelated lines that share its initial letter.
  • assertNotVisible can confirm absence when the outer ID or another relation eliminates every possible match. A surviving undecidable candidate retains the typed error.
  • scrollUntilVisible can swipe when the current snapshot is undecidable. At the deadline, persistent uncertainty returns maestro_selector_regex_indeterminate.

Validation

395d8a137c passed merge-tree. Hosted checks pending.

At c669bc28082f0f62be6410f9080e65cf068f917c, all 19 focused resolver tests passed. All 34 hosted checks passed at that SHA. Fallow flagged the previous implementation at 7e4b1c3.

At 7e4b1c3, 19 resolver tests passed. The same test file had 7 failures and 12 passes at 4f14c14. Hosted Bundle Size passed at +66,662 bytes unpacked. Android replay did not run because the launcher was pinned to an older version. Maintainer size disposition is pending.

At 4f14c1428d3c1164e8453b7b213f880d7fb27623, all 34 hosted checks passed. Android 16 replay tapped Sign in beside a 45-line label, reached the below-fold target, and returned REPLAY_DIVERGENCE with the typed reason at the clipped-text deadline. Both installed APKs matched local builds. The deadline harness flagged a transport assertion because the full capture used instrumentation. A follow-up capture confirmed clipping and scroll progress.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.78 MB 6.85 MB +66.6 kB
Package (unpacked) 6.78 MB 6.84 MB +66.6 kB
Package (download) 2.07 MB 2.09 MB +17.6 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 18.8 ms 18.8 ms +0.0 ms
CLI --help 43.5 ms 43.2 ms -0.3 ms

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 4f4daf8. The verdict and the full list are in the summary comment.

@blacksmith-sh

This comment has been minimized.

@thymikee
thymikee force-pushed the fix/daybreak-android-helper-boundaries branch from 114df0f to 7214c93 Compare December 1, 2026 08:03
@apex-sentinel-staging

This comment has been minimized.

@thymikee
thymikee force-pushed the fix/daybreak-android-helper-boundaries branch 2 times, most recently from 278fdec to 65f4412 Compare December 1, 2026 08:34
@apex-sentinel-staging

This comment has been minimized.

@thymikee
thymikee force-pushed the fix/daybreak-maestro-selector-regex branch from 42f8ce2 to 0f9f49f Compare December 1, 2026 08:35
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 0f9f49f. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 38f6876. The verdict and the full list are in the summary comment.

@thymikee
thymikee force-pushed the fix/daybreak-android-helper-boundaries branch 2 times, most recently from ac0eadf to b6e9bb3 Compare December 1, 2026 09:10
@thymikee
thymikee force-pushed the fix/daybreak-maestro-selector-regex branch from 38f6876 to c8b433e Compare December 1, 2026 09:13
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on c8b433e. The verdict and the full list are in the summary comment.

@thymikee
thymikee force-pushed the fix/daybreak-android-helper-boundaries branch from b6e9bb3 to ee8075e Compare December 1, 2026 09:40
@thymikee
thymikee force-pushed the fix/daybreak-maestro-selector-regex branch from c8b433e to ca8364b Compare December 1, 2026 09:42
@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

At ca8364b, one problem in the multiline matching budget needs a fix: an unrelated long text on screen can make a valid selector step fail.

The multiline budget limits line count times text length to 131,072, whatever the pattern costs. A non-matching text of about 3 KB with more than 43 lines, such as a terms block, goes over it. For patterns with ., such as Welcome.* or Sign (in|up).*, the matcher then throws maestro_selector_regex_indeterminate. This was reproduced with a 2,959-character, 45-line text at this commit, with a stubbed error class. By code reading, a tap or swipe then fails for the whole selector with UNSUPPORTED_OPERATION, even when another node such as "Welcome back" definitely matches. The base branch taps that node. The same cause can stop an observe wait on the first snapshot with no definite match. The rule: for a pattern that passes the AST gate, "indeterminate" must happen only when the text is too large to scan in bounded time, not because an ordinary screen text has many lines. The smallest fix is to run the multiline regex whenever the text length is within MAX_MULTILINE_VALUE_LENGTH, or to raise MAX_MULTILINE_WORK to about 1,000,000 to 4,000,000. Please add a resolver-level regression test where a tap with one definite match and one non-matching 3 KB, 45-line node resolves.

Not blocking, so take or leave these: a follow-up issue could relax the overlapping quantifier check, which refuses linear selectors such as [A-Z][a-z]+ [A-Z][a-z]+, \w+\s?\w+, .*\d+.* and .*\d+ items, by allowing a disjoint mandatory atom between two overlapping quantifiers and a single variable quantifier between a leading and trailing .*; both hard-coded reason strings (resolver, target policy) could use MAESTRO_SELECTOR_REGEX_REASONS.indeterminate.reason; the error docs row and the thrown message could say the matcher could not decide the value within its work budget, since single-line values can hit this too; after the fix above, "indeterminate" could throw straight from the matcher, which would remove confirmedUnindexedExistence, resolutionDepth and the uncertain fields (if observe mode still needs an exception, a match/no-match/unknown result decided once in resolveMaestroTargetFromSnapshot would do); and an externalized root runtime dependency on @eslint-community/regexpp could replace the bundled dependency proof tooling.

Could this be much smaller while keeping the regexpp AST gate? A length or time budget alone does not bound synchronous backtracking: (a+)+ on 33 characters took 111 s in a test run. Moving matching off the event loop would make the synchronous resolver async, and the V8 linear engine rejects the i flag. Could the multiline path become cheap enough that "indeterminate" is practically unreachable, so it can fail loudly from the matcher without the extra uncertainty plumbing? Could regexpp be a root runtime dependency, so the bundling tooling can go? That second step needs a maintainer decision first.

These open threads still apply: observe wait aborts and definite match still fails. These do not apply and can be resolved: this one is fixed at this commit, because both typed refusals are documented and production callers handle them; this one was withdrawn, because rethrowing the typed error for a hidden definite match with uncertainty is the intended behavior.

Not verified here: the resolver-level failure was not run as a resolver test; the packed package (bundled regexpp, license notice, no runtime import) was not built, and the package check in CI covers it; the commit range-diff for the restack was not checked; and it is not proven that every pattern accepted by the AST gate has polynomial cost, although spot checks of nested, overlapping, alternation and group-after-quantifier forms were refused or ran linearly.

CI is still pending: 34 checks pass, and one queued check is not a test job. Before merge, the multiline work budget must be fixed and covered by the resolver-level regression test.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 finding moved to a new line on ca8364b. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@thymikee
thymikee marked this pull request as ready for review December 1, 2026 10:52

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 27 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread website/docs/docs/run-maestro-flows.md Resolved
Comment thread website/docs/docs/error-reasons.md Resolved
Comment thread scripts/check-package.ts Resolved
@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

At 7c7546d, observe mode now retries an indeterminate snapshot, which fixes the nested childOf case. Two problems remain from the code side, so this is not ready to merge. The line-budget failure from the earlier review is unchanged.

The multiline work budget still charges lines times length. A non-matching text of about 3 KB with more than 43 lines exceeds it. With a line-spanning pattern such as Welcome.* or Sign (in|up).*, action mode then throws maestro_selector_regex_indeterminate, even when another node definitely matches (resolved thread, still applies). So tapOn: Welcome.* fails next to a terms block, while the base branch taps "Welcome back". For a pattern that passes the AST gate, only a value longer than MAX_MULTILINE_VALUE_LENGTH should be indeterminate, never the line count. Please run the multiline regex for every value within that length, or raise the budget enough to cover it (about 2-4M or more). Please also add a createMaestroSnapshotResolver test in action mode, without confirmedUnindexedExistence, with one "Welcome back" node and one non-matching 45-line, 3 KB node. Welcome.* must resolve to "Welcome back", and the test should fail on the current code.

Can scrollUntilTypedMaestroTarget still reach a target below the fold when the current screen is indeterminate? It sleeps and recaptures without calling scroll, so the same text stays on screen until the deadline and the error is rethrown. The new test expects zero scrolls. The base branch scrolls and finds the target. This also affects values over 16,384 characters after the budget fix. An indeterminate snapshot should scroll like a non-match, and the error should be rethrown only if the last snapshot before the deadline is still indeterminate. Please change the test to expect a scroll and then a definite match.

Two open high-priority threads still apply: loop-bound RegExp alias and globalThis.RegExp guard bypass. Three lower-priority threads also still apply. The long-selector thread does not apply and can be resolved: a long pattern never runs as a regex, and after an exact match it is used as a literal, so no valid target is missed.

All 44 checks pass at this commit. Not verified here: no test was run. The budget failure was traced in the code, which is identical to ca8364b, where it was reproduced with a 2,959-character, 45-line value. The scroll problem comes from reading the code only, not from a device run or the real scroll callback.

Before merge, line count alone must no longer make a line-spanning pattern indeterminate, the 3 KB tap test must be added, and scrollUntilVisible must scroll past an indeterminate snapshot.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

At 806f13b, the earlier review's geometry fallback and nested polling issues are fixed, but two correctness findings remain. The exact-head packet reports 34 green checks; the earlier Repo Guards complexity result was for 9021a0c. There are no conflicts. Before merge, preserve definite misses across combined relations and valid bounded multiline spans, then record exact-head native replay evidence.

An assertNotVisible with childOf selecting an existing empty container can still resolve containsChild against the whole snapshot. An unrelated long label can cause an indeterminate error before the empty-scope return, turning a definite absence into a typed replay failure. Can relation composition short-circuit when the intersection is provably empty, including between conjuncts in containsDescendants, while preserving uncertainty only when it can affect a surviving candidate? https://github.com/callstack/agent-device/blob/806f13b/packages/maestro/src/internal/runtime-selector-resolution.ts#L193

The dense multiline regression expects an indeterminate result for a roughly 6 KB label ending in Order and ready on separate lines, although Order.*ready definitely matches that tail on the base regex. Charging impossible line starts against the limit can make a text-only tap or visibility assertion fail on a complete, under-length snapshot. Can the matcher retain its work limit while pruning starts that cannot match the required literal prefix, and preserve the definite tail match in the existing regression? https://github.com/callstack/agent-device/blob/806f13b/packages/maestro/src/internal/selector-regex.ts#L61

The device run in the packet was at 9021a0c; the production source change to this head is a behavior-preserving extraction, but an exact-head live receipt and the earlier detailed commands and outputs were not provided. Before merge, record a built-CLI native Android daemon replay at 806f13b with the SHA, device, persistent android-helper backend and matching version, commands and outcomes. Show the sign-in tap beside the 45-line label, a swipe from an initially indeterminate snapshot reaching the below-fold target, and a separate run ending with REPLAY_DIVERGENCE and maestro_selector_regex_indeterminate. https://github.com/callstack/agent-device/blob/806f13b/packages/maestro/src/daemon-port/daemon-runtime-port.ts#L296

The unsafe propagation thread does not apply because unsafe errors are rethrown before fallback: #5300 (comment). The uncertainty thread is benign because uncertainty is preserved when no definite visible target exists: #5300 (comment). The indexed miss, reason documentation, nested polling, loop initializer, globalThis, same-node intersection, matching documentation, error documentation, and bundled dependency threads are fixed at head: #5300 (comment) #5300 (comment) #5300 (comment) #5300 (comment) #5300 (comment) #5300 (comment) #5300 (comment) #5300 (comment) #5300 (comment). No lower-priority threads still apply.

Not verified here: Tests, a build, device execution, and individual CLI, Node, or MCP surface invocations were not performed. Static source review and packet inspection trace the shared daemon replay backend to the native operation dispatcher; no measured daemon event-loop latency, raw focused-run receipts, current packed artifact, or exact-head native execution receipt were provided.

@thymikee

thymikee commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Size follow-up at 806f13b97f: CI Size reports about +65.1 kB unpacked and +17.1 kB download versus the stack base. The earlier file-level audit put the unpacked delta at +65,099 B, mostly in the bundled Maestro replay chunk, with +2 B from the last refactor. I measured pinned regexpp 4.12.2 in isolation with tsdown's locked Rolldown 1.2.5 and minification. Exporting the parser and visitor produced 56,868 B (14,331 B gzip). Exporting the parser alone produced 51,482 B (13,527 B gzip). The 5,386 B difference is before adding replacement traversal and is a module measurement, not a package measurement. A custom walk would take ownership of traversal through groups, assertions, and quantified elements, including the checks for nested quantifiers and repetition and alternation limits. I found no visitor-only change with a verified net package saving and preserved behavior. The maintainer decision is whether to accept the current package delta or re-scope the parser approach.

@thymikee

thymikee commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Fixed both findings from the review at 806f13b in fc18329a76. Relation resolution stops when the scope is empty and defers typed uncertainty until the remaining relations have narrowed it. The multiline budget now skips impossible line starts for a pattern with a known leading literal. It still limits viable starts. Both regression cases failed at 806f13b, and all 46 tests in the two owning files passed at fc18329a76. The Android replay receipt remains at 9021a0c6 and the size decision remains open.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

thymikee commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

At 4f14c14, the earlier Log-line regression is fixed, but combined selector misses and another multiline prefix case still need fixes before merge.

Ranking resolves an uncertain childOf again after containsChild has proved absence. The second resolution throws, so daemon replay can poll until it reports maestro_selector_regex_indeterminate instead of returning absence. Carry parent-match information from composition into ranking, and cover the uncertain-childOf-first order through production target resolution or observation.

Relation composition retains a terminal candidate when an unrelated clipped node makes nested text uncertain. An assertNotVisible can therefore fail even though that candidate has no eligible child or descendant. Keep possible nested matches tied to their source nodes and project them through containsChild and containsDescendants before intersecting, including terminal candidates.

Deferred uncertainty is raised before the outer leaf predicates can prove that every candidate has the wrong ID. Daemon replay can report maestro_selector_regex_indeterminate for a selector that is definitely absent. Intersect outer leaf matches before raising relation uncertainty, and retain the typed refusal when a leaf-compatible candidate still depends on that relation.

The budget prefilter checks only the first character, so 1,500 Other lines followed by Order and ready on separate lines can exhaust the work budget despite a valid multiline match. This can make a text observation or action fail as indeterminate. Use the full mandatory run of leading Character atoms for the sticky, case-insensitive prefilter, while charging viable starts and retaining the length and work limits.

Before merge, attach a remotely accessible native replay receipt for 4f14c14 with the built-CLI commands, Android device, interactive android-helper snapshot backend and helperVersion 0.21.46-dev. Show the 45-line sign-in tap, actual scroll progress to the below-fold target, and deadline REPLAY_DIVERGENCE with its typed reason. Identify the supplemental instrumentation capture and its transport assertion separately from the interactive route and clipping evidence.

The thread on visibility uncertainty does not apply because the uncertain candidate could satisfy visibility; the thread on stale observation errors does not apply because each poll replaces the prior error; the thread on geometry fallback does not apply because unsafe input is rethrown and the oversized-value fallback is intended. No other lower-priority threads still apply.

The initial Body rules run was cancelled. The latest GitHub check snapshot for 4f14c14 reports 34 passed, with no pending or failed checks. No conflicts are known.

Not verified here: local gates, tests, builds, device runs, and individual CLI, Node, or MCP execution were not performed. The review used static source and the evidence packet; no raw focused-run results, exact-head package size or artifact, Body rules failure excerpt, or verifiable native receipt was available. Before merge, preserve definite relation and leaf misses through production ranking, prune impossible full-prefix starts within the existing budget, and provide the native receipt. The maintainer’s package-size decision remains open.

@thymikee

thymikee commented Dec 2, 2026

Copy link
Copy Markdown
Member Author

Follow-up at 7e4b1c33762841d06632f82de3007d310b86458c. Multiline work now charges only starts that match the full mandatory literal prefix. A tap regression beside 800 ordinary “Shipping info” lines proves that sharing the first character with Sign (in|up).* no longer blocks Sign in. The resolver now keeps undecidable candidates scoped to the node that produced them, intersects that scope with the outer ID and other relations, and passes the computed parent result to ranking. A surviving undecidable candidate still returns maestro_selector_regex_indeterminate.

pnpm exec vitest run --project unit-core packages/maestro/src/internal/__tests__/runtime-selector-resolution.test.ts passed all 19 tests. The same file in a disposable checkout at 4f14c1428d3c1164e8453b7b213f880d7fb27623 had 7 failures and 12 passes. The PR is mergeable against #5245.

The earlier Android 16 replay receipt belongs to 4f14c14. Its harness invoked the branch-built CLI with replay <tap|scroll|deadline>.yaml --maestro --platform android --serial emulator-5558 --session maestro5300-final --state-dir <isolated-state> --json. Its retained output showed {"case":"tap","lines":45,"signedIn":true,"steps":3} and {"case":"scroll","targetVisible":true,"steps":2}. The deadline reply matched REPLAY_DIVERGENCE and maestro_selector_regex_indeterminate before the full snapshot failed an extra transport assertion. The follow-up capture showed one clipped node and scroll progress. The disposable fixture directory was removed after that run. Replay at the new head and the package-size decision remain open.

@apex-sentinel-staging

This comment has been minimized.

@thymikee
thymikee force-pushed the fix/daybreak-maestro-selector-regex branch from c669bc2 to 395d8a1 Compare December 2, 2026 16:57
@thymikee
thymikee force-pushed the fix/daybreak-android-helper-boundaries branch from 88af7a6 to 7e9c0c4 Compare December 2, 2026 16:57
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 395d8a1

Warning

The isolation lease for this review ended before the review finished (an artifact of the staging environment). There is a chance that some of its findings are unverified, or that something was missed. Comment @apex-sentinel-staging review to run it again.

Since the review of c669bc2: 2 new · 0 still open · 0 no longer raised

2 finding(s): 2 minor.

🟡 Minor (2)

Where Finding
packages/maestro/src/daemon-port/daemon-runtime-port-observation.ts:226 🆕 scrollUntilTypedMaestroTarget can scroll after its deadline expires
packages/maestro/src/daemon-port/daemon-runtime-port-observation.ts:141 🆕 Unobserved regex work exhaustion becomes a permanent timeout, not the typed reason
Not in the reviewers' scope (1 file)
  • pnpm-lock.yaml: generated or a lockfile, so its lines were left out

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (7c6ef4a2ed46).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on 395d8a1. The verdict and the full list are in the summary comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant