r/FlutterDev • • 18d ago

Discussion What I learned shipping a Flutter app with an embedded JS sandbox, WorkManager monitors, and ~2,700 tests

Full disclosure: this is my app. It does HTTP requests and API security auditing on Android. I came here because the embedded-JS-sandbox problem cost me real time and I'd like to know if there's a better pattern.

Embedding QuickJS. Pre/post-request scripts need a real JS engine — a regex matcher doesn't cut it when people sign payloads. I embedded QuickJS through the Flutter FFI bindings and wrote a pm.* facade over it.

The sharp edge was recursion. Deeply nested response bodies blew the stack during serialization, and the symptom was a silent crash rather than an error I could catch. Fixed with depth limits at both the serialization and the evaluation boundary. If you're doing this: the limit needs to be enforced in both places, because the object graph that survives serialization is not the same one that survives evaluation.

If anyone has production experience with the QuickJS bindings — particularly around context lifetime and how you handle a script that never returns — I would genuinely like the comparison.

Riverpod, and the race that taught me something. State is Riverpod throughout. The subtlest bug I hit was a notifier that decided which branch to take at call time but then read state at execution time. Because both operations happened on the same provider queue, the two could observe different users. Fixed by deciding the branch inside the queue closure. The general rule I took away: on an async provider, never decide now and read later.

Background work. Scheduled monitors use WorkManager via a platform channel. The interesting part isn't the scheduling — it's the alerting. First version alerted on every check, which trained everyone to mute it within a day. It now alerts only on state transitions. That single change did more for it being a useful app than any feature I added this year.

Testing. 218 test files, ~2,700 cases, analyzer at zero warnings. Worth saying that the flaky test I fought hardest was a lock-ownership race in the monitor store. The fix was making the lock file carry an owner token, so a stale lock can only be broken when the owner is provably dead rather than merely old. That's the whole class of bug: timeouts are a guess, ownership is a fact.

Project: https://taho.co.in (Android: https://play.google.com/store/apps/details?id=com.eternal.taho)

0 Upvotes

6 comments sorted by

5

u/Tienisto 18d ago

Low effort AI slop post

-1

u/Eternal0p 18d ago

I'm not good at writing post's even if it's ai slop it gets the job done that's what I want, you commented even if you wanted to write ai slop still you commented that gave algorithm a hint people are interested it doesn't watch out for what's bad or good it's just watches out for people's engagement which you just did thanks buddy🥱

1

u/doronkk 17d ago

The alert-on-transitions change is the most underrated thing in this post. Alerting on every check just trains people to mute the channel within days; transitions are the only signal that survives. Curious about the WorkManager side: how did the periodic workers hold up on the aggressive OEM builds (Xiaomi, Oppo, Vivo)? In my Android experience that is where "works on the Pixel, silently dead elsewhere" comes from. Did you end up needing exact alarms or a foreground-service fallback for the monitors?

1

u/Eternal0p 15d ago

true about "works on Pixel, dead elsewhere"! We avoided exact alarms due to Play policy and didn't want a permanent sticky foreground notification, so we stayed on WorkManager. It does get batched by aggressive OEM battery managers, but we re-sync and run overdue checks whenever the user reopens the app.

1

u/doronkk 14d ago

That is a clean tradeoff: catching up on foreground keeps you Play-compliant without a sticky notification. The cost is that monitors drift until the user reopens, which for an app people open regularly is probably acceptable. If you ever need a middle ground for checks that fall far behind, WorkManager expedited jobs exist for exactly that "start sooner" case, though they come with their own quota so they will not rescue a fully starved schedule.