openassistant: escape closing brace in HostSendMsg marker regex (#928)
- Commit
414c3e4d69fad840eba50e567b2deb17a7f7dd8a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 01:45 UTC (17 days ago)
- Parents
b1d3ed7
The HOST_SEND_MSG pattern in InferenceService's companion object was
\[HostSendMsg (\{.*})] โ the opening brace escaped, the closing one
not. Lenient regex engines accept a lone }, but Android's ICU-backed
java.util.regex treats it as a syntax error ("Syntax error in regexp
pattern near index 20", reported from a OnePlus 9 Pro on CrDroid /
Android 16). Because the Regex is a companion-object val, the
PatternSyntaxException surfaced as ExceptionInInitializerError from
InferenceService.<clinit> when the service was first instantiated โ
after the initial model downloads finished โ so the app crashed on
every launch and reinstalling or clearing data could not help.
Escape the closing brace (\{.*\}); the match semantics are
unchanged (matchEntire anchors the marker, the group still captures
the JSON payload). HOST_CONFIRM / HOST_CANCEL use [^\]]+ and were
not affected.
Host JVM tests cannot reproduce this: the JDK regex compiler is
lenient about a lone }, which is why InferenceServiceHostMarkerTest
stayed green while devices crashed. Those tests still lock the
marker-matching behaviour.
Verified: :openassistant:testDevUnitTest and ./check openassistant
(detekt + lint) pass.Diff
openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.ktindex f1b7a7372b..ab605a61ee 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt@@ -99,7 +99,7 @@ class InferenceService : Service() { private const val AUDIT_OUTCOME_CHARS = 200 private val HOST_CONFIRM = Regex("""\[HostConfirm ([^\]]+)]""") private val HOST_CANCEL = Regex("""\[HostCancel ([^\]]+)]""")- private val HOST_SEND_MSG = Regex("""\[HostSendMsg (\{.*})]""")+ private val HOST_SEND_MSG = Regex("""\[HostSendMsg (\{.*\})]""") /** The system prompt used when the user has not set a custom one. */ val DEFAULT_SYSTEM_PROMPT = """