<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ashwar Sadh</title>
    <description>The latest articles on DEV Community by Ashwar Sadh (@ashwar_sadh_f7abe6f82c8e9).</description>
    <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4167453%2F4c6bcbac-018d-4813-b21d-380952caddd8.jpg</url>
      <title>DEV Community: Ashwar Sadh</title>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashwar_sadh_f7abe6f82c8e9"/>
    <language>en</language>
    <item>
      <title>Which permission is missing, and what does it switch off? A pure function that keeps an Android app from ever feeling dead</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Fri, 27 Nov 2026 06:14:13 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/which-permission-is-missing-and-what-does-it-switch-off-a-pure-function-that-keeps-an-android-app-3kbg</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/which-permission-is-missing-and-what-does-it-switch-off-a-pure-function-that-keeps-an-android-app-3kbg</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of the app described here, and this post is published from my account. It was drafted and published by an AI agent working from the project's source code. QuickDial is not affiliated with WhatsApp LLC or Meta.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.ashwar.quickdialbridge&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-permission-plan" rel="noopener noreferrer"&gt;QuickDial&lt;/a&gt; adds shortcuts around chat and phone calls on Android: open a chat from a typed number, a call button inside a chat, a chat button while a call is on. Those shortcuts need up to six things from the user, spread across system dialogs and Settings pages. The early complaint was blunt: users did not know they had to allow anything.&lt;/p&gt;

&lt;p&gt;The fix was not more screens. It was one pure Kotlin object that answers three questions, and a rule that the app is never "dead".&lt;/p&gt;

&lt;h2&gt;
  
  
  A snapshot in, a plan out
&lt;/h2&gt;

&lt;p&gt;No Android classes go in. A &lt;code&gt;Snapshot&lt;/code&gt; is six booleans read by the permission checker elsewhere:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Snapshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;canPostNotifications&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;hasOverlay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;accessibilityEnabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;notificationAccessEnabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;hasContacts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;backgroundRestricted&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because it is plain data, the order, the reduced mode and the reminder rule are all unit-testable on the JVM with no emulator.&lt;/p&gt;

&lt;h2&gt;
  
  
  The order is a design decision, so it lives in code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Snapshot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buildList&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Kind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ALERTS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;canPostNotifications&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;essential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Kind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CONTACTS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hasContacts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;essential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Kind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ACCESSIBILITY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;accessibilityEnabled&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;essential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Kind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;OVERLAY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hasOverlay&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;essential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Kind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CALL_ACCESS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notificationAccessEnabled&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;essential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backgroundRestricted&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Kind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BACKGROUND&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;granted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;essential&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each choice has a reason that would otherwise be lost:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Notifications first.&lt;/strong&gt; It is a single system dialog, and it is what lets the app tell the user later that something else is still off. Without it, a missing permission is silent for ever.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The two in-app dialogs next, then the accessibility service before the two Settings pages.&lt;/strong&gt; Once the service is running it can bring the app back to the foreground after the user visits those Settings pages, so the guided flow does not strand them there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The battery item is conditional.&lt;/strong&gt; It is only listed when the system has actually restricted the app in the background. Testing showed that the Play install ran fine without an exemption; asking for one anyway adds a scary dialog for no benefit. The list is built from evidence of a real problem, not from a general worry.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Nothing is a gate
&lt;/h2&gt;

&lt;p&gt;The most important function is the shortest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;workingFeatures&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Snapshot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Feature&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buildList&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Feature&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;OPEN_CHAT_FROM_NUMBER&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hasOverlay&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;accessibilityEnabled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Feature&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CALL_BUTTON_IN_CHATS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hasOverlay&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notificationAccessEnabled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Feature&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CHAT_BUTTON_DURING_CALLS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With nothing granted, the list still has one entry: opening a chat from a typed number needs none of the six. That gives the UI an honest sentence for every state. Instead of "permissions required", the card can say which shortcut is on and which is off, and what to tap to turn the next one on. Each missing item switches off one shortcut, never the whole app.&lt;/p&gt;

&lt;p&gt;Two features each need the overlay permission plus one other thing, which is why the conditions are combined rather than one flag per feature. If the user grants the overlay but not accessibility, the call button in chats stays off and the chat button during a call does not depend on it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reminders only for things that matter
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;needsReminder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Snapshot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;missing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;essential&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notifications and contacts are marked &lt;code&gt;essential = false&lt;/code&gt;. A user who declines contacts is not nagged: they lose name matching, not a shortcut. A reminder goes out only while something that actually switches a shortcut off is missing, and it stops by itself the moment the last essential item is granted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tests worth writing
&lt;/h2&gt;

&lt;p&gt;Because the object is pure, the useful tests are small tables:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;All six granted: &lt;code&gt;missing&lt;/code&gt; is empty, &lt;code&gt;needsReminder&lt;/code&gt; is false.&lt;/li&gt;
&lt;li&gt;Nothing granted: &lt;code&gt;workingFeatures&lt;/code&gt; is exactly one item, never empty.&lt;/li&gt;
&lt;li&gt;Overlay granted but accessibility off: the call button in chats is absent.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;backgroundRestricted&lt;/code&gt; false: the list has five items; true: six.&lt;/li&gt;
&lt;li&gt;Order is stable: alerts first, accessibility before overlay.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The pattern is portable to any app with a permission ladder: a snapshot of booleans, a pure ordered plan, a "what still works" function that can never return empty, and a reminder rule that looks only at essential items.&lt;/p&gt;

&lt;p&gt;QuickDial is not affiliated with WhatsApp LLC or Meta.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>testing</category>
      <category>ux</category>
    </item>
    <item>
      <title>One tap from the notification shade: a Quick Settings tile that opens a photo picker, and the Android 14 API change it hides</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Fri, 27 Nov 2026 06:13:34 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/one-tap-from-the-notification-shade-a-quick-settings-tile-that-opens-a-photo-picker-and-the-2pkh</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/one-tap-from-the-notification-shade-a-quick-settings-tile-that-opens-a-photo-picker-and-the-2pkh</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of the app described here, and this post is published from my account. It was drafted and published by an AI agent working from the project's source code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.ashwar.autoupiqr&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-qs-tile" rel="noopener noreferrer"&gt;Auto UPI QR&lt;/a&gt; reads a UPI QR from a picture and hands the link to the UPI app you already use. The usual way in is to open the app and press "Choose QR image". That is two steps too many for something you do while standing at a counter, so the app also ships a Quick Settings tile: pull down the shade, tap, and the photo picker is already open.&lt;/p&gt;

&lt;p&gt;The tile is about thirty lines. Two things in it are worth writing down.&lt;/p&gt;

&lt;h2&gt;
  
  
  The service does almost nothing
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;TileService&lt;/code&gt; is a service Android binds to when your tile is visible. It is the wrong place for real work, so the tile only forwards a tap to the Activity that already knows how to scan:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PickTileService&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;TileService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;intent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;MainActivity&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MainActivity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ACTION_PICK_QR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addFlags&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;FLAG_ACTIVITY_NEW_TASK&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nc"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;FLAG_ACTIVITY_CLEAR_TOP&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;// start the Activity and close the shade (see below)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The manifest entry needs the &lt;code&gt;BIND_QUICK_SETTINGS_TILE&lt;/code&gt; permission, an icon, a label and the &lt;code&gt;QS_TILE&lt;/code&gt; intent filter. The user adds the tile themselves from the edit screen of Quick Settings; the app cannot place it for them.&lt;/p&gt;

&lt;p&gt;The action string, &lt;code&gt;ACTION_PICK_QR&lt;/code&gt;, is not special to the tile. The launcher long-press shortcut "Choose QR image" uses the same action. One entry point, three doors.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Android 14 change: &lt;code&gt;startActivityAndCollapse(Intent)&lt;/code&gt; is deprecated
&lt;/h2&gt;

&lt;p&gt;A tile that starts an Activity also has to close the notification shade, or the Activity opens behind it. &lt;code&gt;TileService.startActivityAndCollapse&lt;/code&gt; does both. On Android 14 (API 34) the &lt;code&gt;Intent&lt;/code&gt; overload is deprecated and a &lt;code&gt;PendingIntent&lt;/code&gt; overload takes its place, so the call has to branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;VERSION&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SDK_INT&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;startActivityAndCollapse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nc"&gt;PendingIntent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getActivity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;PendingIntent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;FLAG_IMMUTABLE&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="nc"&gt;PendingIntent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;FLAG_UPDATE_CURRENT&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Suppress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"DEPRECATION"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;startActivityAndCollapse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;FLAG_IMMUTABLE&lt;/code&gt; is required for a &lt;code&gt;PendingIntent&lt;/code&gt; you hand to the system on current Android versions, and it is the right choice here because nobody needs to fill in extras later. The deprecated branch keeps older phones working; it is the only place in the app where the suppression lives.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Activity side: cold start and warm start are different paths
&lt;/h2&gt;

&lt;p&gt;The same tap reaches &lt;code&gt;MainActivity&lt;/code&gt; in two ways. If the app is not running, the intent arrives in &lt;code&gt;onCreate&lt;/code&gt;. If it is already open, &lt;code&gt;CLEAR_TOP&lt;/code&gt; brings the existing instance forward and delivers the intent to &lt;code&gt;onNewIntent&lt;/code&gt;. Both must open the picker:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// onCreate&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;ACTION_PICK_QR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;launchPicker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;firstLaunch&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;showOnboarding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onNewIntent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onNewIntent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;ACTION_PICK_QR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;launchPicker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;savedInstanceState == null&lt;/code&gt; check matters. When Android recreates the Activity after a rotation or after the process was killed, it replays the original intent. Without the check, the picker would pop open again every time the screen turned, for a user who had already chosen a picture.&lt;/p&gt;

&lt;p&gt;Note also that the first-launch onboarding is an &lt;code&gt;else if&lt;/code&gt;: someone who reaches the app through the tile on day one goes straight to the picker rather than past a tutorial they did not ask for.&lt;/p&gt;

&lt;h2&gt;
  
  
  The picker needs no permission
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;launchPicker()&lt;/code&gt; uses the system photo picker (&lt;code&gt;PickVisualMedia&lt;/code&gt;, images only). The app never asks for access to the whole gallery; it receives the one picture the user selects. The tile only opens a chooser, nothing more, and what happens next is the ordinary scan and hand-off.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would tell myself before building it
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Keep the &lt;code&gt;TileService&lt;/code&gt; a dumb forwarder; put the behaviour in an Activity action you can reach from other doors.&lt;/li&gt;
&lt;li&gt;Branch on API 34 for &lt;code&gt;startActivityAndCollapse&lt;/code&gt; and keep the deprecated call in one suppressed spot.&lt;/li&gt;
&lt;li&gt;Handle both &lt;code&gt;onCreate&lt;/code&gt; and &lt;code&gt;onNewIntent&lt;/code&gt;, and guard the cold-start path with &lt;code&gt;savedInstanceState == null&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Auto UPI QR is not a payment app: it finds the link in the picture and passes it to your UPI app. Always check the payee name before entering your UPI PIN.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>mobile</category>
      <category>ux</category>
    </item>
    <item>
      <title>Which production errors deserve a human? Grouping failures by signature, filing only the new or growing ones</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Thu, 26 Nov 2026 06:14:51 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/which-production-errors-deserve-a-human-grouping-failures-by-signature-filing-only-the-new-or-27fk</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/which-production-errors-deserve-a-human-grouping-failures-by-signature-filing-only-the-new-or-27fk</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of ScooterLog, and this post is published from my account. It was drafted and published by an AI agent working on my behalf. ScooterLog is an independent app, not affiliated with, endorsed by or sponsored by Ola Electric.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.kkfe.scooterlog" rel="noopener noreferrer"&gt;ScooterLog&lt;/a&gt; is a small web app that signs a user in to their scooter's own cloud account and logs their battery readings. Its two riskiest steps, sign-in and polling, depend on someone else's API that can change without notice. I wanted failures to reach whoever fixes them &lt;strong&gt;without a user having to complain first&lt;/strong&gt;, and without a daily wall of noise. This is how the digest decides what is worth filing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: a signature that carries no user data
&lt;/h2&gt;

&lt;p&gt;Every failure is stored as one row keyed by a &lt;strong&gt;signature&lt;/strong&gt;: the step that failed, the HTTP status, and the upstream's own reason words. Free text, digits and anything typed by the user are dropped before it is a key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test_signature_drops_free_text_and_digits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defect_sig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'verify'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'otp HTTP 401 status=FAILURE code=NOT_FOUND reason=INVALID_PARAMETERS text=x'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; \
        &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'verify | 401 | code=NOT_FOUND | reason=INVALID_PARAMETERS'&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="s1"&gt;'9811'&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defect_sig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'client/login'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'network failed 9811100632'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things follow. Identical failures collapse into one row with a hit count and a count of &lt;strong&gt;distinct users&lt;/strong&gt;. And nothing that identifies a person can end up in the digest, because it was never stored in the key.&lt;/p&gt;

&lt;p&gt;A row has a state (&lt;code&gt;open&lt;/code&gt;, &lt;code&gt;fixed&lt;/code&gt;, &lt;code&gt;wontfix&lt;/code&gt;). A new hit on a &lt;code&gt;fixed&lt;/code&gt; row flips it to &lt;code&gt;regressed&lt;/code&gt;, so a fix that did not hold comes back by itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: what is not a defect
&lt;/h2&gt;

&lt;p&gt;The upstream answers a mistyped code with a perfectly valid error. Counting those as defects would bury the real ones, so a list of the upstream's &lt;em&gt;user-error&lt;/em&gt; reasons (wrong code, expired code, attempt limit) is counted and shown but never filed on its own. A signature that matches is skipped, and so is anything marked &lt;code&gt;wontfix&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: new, growing or regressed, and more than one person
&lt;/h2&gt;

&lt;p&gt;The daily run files a signature only if it passes both tests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;it is new&lt;/strong&gt; (first seen in the last 48 hours), &lt;strong&gt;or growing&lt;/strong&gt; (today's hits are more than twice its weekly average: &lt;code&gt;hits * 7 &amp;gt; 2 * week_hits&lt;/code&gt;), &lt;strong&gt;or regressed&lt;/strong&gt;; and&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;at least two distinct users hit it&lt;/strong&gt;, unless it belongs to the sign-in class, where one user is already enough.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A single user's one-off JavaScript error never makes the digest. The test from the repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;rep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'day'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sig&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'verify | 401 | reason=INVALID_PARAMETERS'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'verify'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hits&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sig&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'verify | 400 | reason=INCORRECT_VERIFICATION_CODE'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'verify'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hits&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sig&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'client/home | js: x'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'client/home'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hits&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;# the first is filed; the wrong-code one (a typo) and the single-user blip are not&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the second row has &lt;em&gt;more&lt;/em&gt; hits and &lt;em&gt;more&lt;/em&gt; users than the first and is still not filed. Volume is not the signal; whether the system is at fault is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: a second, faster path for the failures that lock people out
&lt;/h2&gt;

&lt;p&gt;A daily digest is too slow for "nobody can sign in". A 15-minute run looks only at the sign-in class (and the login-rate page), with a lower bar of three users. And so one outage does not file itself 96 times a day, a filed signature is held back for &lt;strong&gt;20 hours&lt;/strong&gt; in the daily run and &lt;strong&gt;6 hours&lt;/strong&gt; in the urgent one, unless it has regressed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: a model labels it, it does not decide whether to file
&lt;/h2&gt;

&lt;p&gt;Only after the rules above pick candidates does a language model see them, through a central gateway, with a JSON schema that forces one of four classes: &lt;code&gt;ola_changed&lt;/code&gt; (the upstream broke or changed something), &lt;code&gt;our_bug&lt;/code&gt;, &lt;code&gt;user_error&lt;/code&gt;, &lt;code&gt;network&lt;/code&gt;, plus a three-line diagnosis (what failed, likely cause, first thing to check). If the gateway is down, the item is filed as &lt;code&gt;unclassified&lt;/code&gt; with the gateway error rather than dropped. In the daily digest, &lt;code&gt;user_error&lt;/code&gt; and &lt;code&gt;network&lt;/code&gt; items are filtered out unless at least ten users hit them. The model never sees a user identity, only the signature, the counts and a sanitised sample.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: file one incident, mark it filed
&lt;/h2&gt;

&lt;p&gt;The result is &lt;strong&gt;one numbered incident&lt;/strong&gt; per run, written into a repair queue, listing each signature with hits, users, total, state and class, plus the logins-per-hour figure (for example "ok/tries"). The signatures are then marked filed so the next run holds them back. There is also a &lt;code&gt;--dry-run&lt;/code&gt; that prints what would be filed and writes nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Key failures by &lt;strong&gt;what failed&lt;/strong&gt;, not by who or when; drop digits and free text before they become a key.&lt;/li&gt;
&lt;li&gt;Separate the upstream's &lt;em&gt;user-error&lt;/em&gt; answers from real defects up front.&lt;/li&gt;
&lt;li&gt;Use "new or growing, and more than one person" as the filing rule, not raw volume.&lt;/li&gt;
&lt;li&gt;Give the failures that block sign-in their own faster, lower-threshold path and a hold-back so one outage is one ticket.&lt;/li&gt;
&lt;li&gt;Let a model label and explain; keep &lt;strong&gt;whether to file&lt;/strong&gt; in plain, testable code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;ScooterLog is an independent app, not affiliated with, endorsed by or sponsored by Ola Electric.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>monitoring</category>
      <category>sqlite</category>
      <category>webdev</category>
    </item>
    <item>
      <title>My Node.js app froze for 44 seconds and nothing could say why: a worker thread that profiles the blocked main thread</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Thu, 26 Nov 2026 06:13:41 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/my-nodejs-app-froze-for-44-seconds-and-nothing-could-say-why-a-worker-thread-that-profiles-the-363j</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/my-nodejs-app-froze-for-44-seconds-and-nothing-could-say-why-a-worker-thread-that-profiles-the-363j</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of Relaymote, and this post is published from my account. It was drafted and published by an AI agent working on my behalf. Relaymote is unofficial; not affiliated with or endorsed by Anthropic.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ashwarsadh/relaymote" rel="noopener noreferrer"&gt;Relaymote&lt;/a&gt; is a small local Node.js daemon that puts Claude Desktop's Code-tab sessions on your phone. In early November, requests from the phone started taking up to 44 seconds. Nothing in the logs could say why.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the existing timing could not tell
&lt;/h2&gt;

&lt;p&gt;I already logged a "poll: TOTAL" time. But that number includes every &lt;code&gt;await&lt;/code&gt; in the poll, so a poll that is slow because it is &lt;em&gt;waiting&lt;/em&gt; looks identical to one that is slow because the &lt;strong&gt;event loop is blocked&lt;/strong&gt;. Those need opposite fixes: wait less, or stop running synchronous work on the main thread. The log could not separate them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea: watch from outside the thing that is stuck
&lt;/h2&gt;

&lt;p&gt;A blocked main thread cannot report on itself. So the main thread does one trivial thing, and a worker thread does the watching:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The main thread writes &lt;code&gt;Date.now()&lt;/code&gt; into a &lt;code&gt;SharedArrayBuffer&lt;/code&gt; every 100 ms. That is the heartbeat.&lt;/li&gt;
&lt;li&gt;A worker thread checks that value every 200 ms. If it is older than &lt;code&gt;STALL_MS&lt;/code&gt; (2 s by default), a stall is open.&lt;/li&gt;
&lt;li&gt;The worker keeps a rolling CPU profile of the main thread, in 30 s windows, using Node's &lt;code&gt;inspector&lt;/code&gt; module: &lt;code&gt;session.connectToMainThread()&lt;/code&gt; lets a worker attach to the main thread's inspector &lt;strong&gt;without opening a port&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;When a stall closes, the worker reads the window's profile for just the stall's time range and logs what was running.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;inspector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connectToMainThread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Profiler.enable'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Profiler.setSamplingInterval'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;interval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 10 ms&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;wall0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Profiler.start'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;WINDOW_MS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;open&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// a stall still open ends in the next window&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;profile&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Profiler.stop'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;stalls&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;attribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;wall0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;t0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One detail that matters: a stall that is still open when the window ends is not cut off. The worker waits for it to close and reads it from the same profile, otherwise the longest stalls, which are the ones you care about, would be the ones you lose.&lt;/p&gt;

&lt;h2&gt;
  
  
  "readFileSync" is not an answer
&lt;/h2&gt;

&lt;p&gt;A CPU profile's leaf frame is usually something like &lt;code&gt;readFileSync&lt;/code&gt; or &lt;code&gt;statSync&lt;/code&gt;. That tells you the call, not who made it. So the attribution does two extra things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it walks up from each sample to the &lt;strong&gt;nearest frame that belongs to our own code&lt;/strong&gt; (a path check against the project root) and charges the time to that;&lt;/li&gt;
&lt;li&gt;it also keeps the chain of our own callers above that frame, up to three, as &lt;code&gt;frame &amp;lt; caller &amp;lt; caller&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The second part came from a real failure: a log line that said only a &lt;code&gt;mtime&lt;/code&gt; helper in &lt;code&gt;core.js&lt;/code&gt; was hot could not say &lt;em&gt;which&lt;/em&gt; caller was stat-ing. With the caller chain, each stall line now names the call path that asked.&lt;/p&gt;

&lt;p&gt;The log line for one stall looks like this (the shape is real, the values here are made up):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;loop stall 6.2 s from 2026-11-07T10:14:03Z (5900 ms sampled)
  ours: poll core.js:210 4100ms, ...
  | leaf: statSync 3900ms, ...
  | via: mtime core.js:67 &amp;lt; readCached core.js:90 &amp;lt; poll core.js:210 3800ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  A second job: "blocked" is not "dead"
&lt;/h2&gt;

&lt;p&gt;On 16 November a PC-wide stall lasted 186 seconds. The tray's watchdog saw two missed health probes (about 40 s) and ended the daemon, which cost two restarts and a 72 s boot stall. The daemon had not crashed; it was blocked.&lt;/p&gt;

&lt;p&gt;The same worker keeps running while the main thread is blocked, so it can say so. After &lt;code&gt;NOTE_AFTER_MS&lt;/code&gt; (5 s) of stall it writes a small JSON file every 5 s:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"pid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"stalledSince"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1763000000000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1763000012000&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The watchdog now treats a fresh note as "blocked, not dead" and waits up to a configured grace period before ending the process. A hang where the worker is &lt;strong&gt;also&lt;/strong&gt; silent is still ended at once. The file is written to a temp name and renamed, and a write that is still in flight is not started twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs and how to turn it off
&lt;/h2&gt;

&lt;p&gt;The worker is &lt;code&gt;unref&lt;/code&gt;'d so it never keeps the process alive, the sampling interval is 10 ms, and &lt;code&gt;RELAYMOTE_LOOP_WATCH=0&lt;/code&gt; turns the whole thing off. The thresholds are environment variables too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Measure a blocked event loop from &lt;strong&gt;another thread&lt;/strong&gt;; a timer on the blocked thread cannot fire to tell you it is blocked.&lt;/li&gt;
&lt;li&gt;Total request time that includes &lt;code&gt;await&lt;/code&gt;s cannot separate waiting from blocking. A heartbeat can.&lt;/li&gt;
&lt;li&gt;Attribute profile samples to &lt;strong&gt;your&lt;/strong&gt; frames and keep a short caller chain, because the leaf is almost always a library call.&lt;/li&gt;
&lt;li&gt;Give your watchdog a way to tell "blocked" from "dead", or it will kill a process that was about to recover.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Source is MIT-licensed in the repo (&lt;code&gt;lib/loop-watch.js&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Unofficial; not affiliated with or endorsed by Anthropic.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>performance</category>
      <category>debugging</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Remember which chats are groups without storing their names: a hashed, versioned set that can also forget</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Wed, 25 Nov 2026 06:15:20 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/remember-which-chats-are-groups-without-storing-their-names-a-hashed-versioned-set-that-can-also-38kj</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/remember-which-chats-are-groups-without-storing-their-names-a-hashed-versioned-set-that-can-also-38kj</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of QuickDial, and this post is published from my account. It was drafted and published by an AI agent working on my behalf from the app's source code. QuickDial is not affiliated with WhatsApp LLC or Meta.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.ashwar.quickdialbridge&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-groupstore" rel="noopener noreferrer"&gt;QuickDial&lt;/a&gt; shows a small call button over a one-to-one chat in a chat app, and it must never show it over a group or community. The screen alone does not always say which one you are on: a header can repaint before its member list has arrived. This post is about the 54-line object that remembers what has been proven, and three decisions in it that I would repeat.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem: one reading is not proof
&lt;/h2&gt;

&lt;p&gt;The first version decided from a single look at the screen. On a community group the header briefly looked like a person's chat, and the button appeared where it should not. The fix has two halves. Detection is now evidence-based: a title counts as a group once any of three signals shows it (the header, a sender label on messages, or a group-info page reached by a tap). And once proven, the answer is &lt;strong&gt;remembered&lt;/strong&gt;, so the next paint cannot flip it back.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;remember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;normalizedTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;normalizedTitle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isBlank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;normalizedTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;memory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;                       &lt;span class="c1"&gt;// already known: no disk write&lt;/span&gt;
    &lt;span class="nf"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;putBoolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A small in-memory set sits in front of the preferences file, so the check that runs on every screen update never touches disk after the first time. &lt;code&gt;remember&lt;/code&gt; returns early when the key is already in memory, which also stops repeated writes during a burst of identical events.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 1: store a hash, not the chat name
&lt;/h2&gt;

&lt;p&gt;A list of group names is a list of who someone talks to. The set does not need the names, only a yes/no on "have I proven this title is a group". So the key is a SHA-256 of the app's package name and the title:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;internal&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;normalizedTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;digest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MessageDigest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SHA-256"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"$packageName\u0000$normalizedTitle"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toByteArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Charsets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTF_8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;joinToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kt"&gt;byte&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"%02x"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details. A &lt;code&gt;\u0000&lt;/code&gt; separator keeps ("ab", "c") and ("a", "bc") from hashing to the same thing. And the package name is part of the key, so a chat with the same title in a second chat app is a separate entry. Lookups work because the title is hashed the same way each time; nothing readable is kept on the phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 2: the set must be able to forget
&lt;/h2&gt;

&lt;p&gt;A one-way "this is a group" flag has an obvious failure: a wrong entry is permanent. So there is a second proof in the other direction. If a title's contact-info page opens (a person's page, not a group's), it is proven &lt;em&gt;not&lt;/em&gt; a group and must stop being hidden:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;forget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;normalizedTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;normalizedTitle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isBlank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;normalizedTitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;memory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Evidence in both directions, with the stronger proof winning, is what keeps a remembered answer from turning into a stuck one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 3: version the store's file name
&lt;/h2&gt;

&lt;p&gt;This is the one that cost me something. An older build had marked some titles as groups wrongly, and a real one-to-one chat with a business contact was hidden for good, because nothing could tell the stored flag was bad. Fixing the detection did not fix the data already on phones. The fix was to change the preferences file name from &lt;code&gt;known_group_chats&lt;/code&gt; to &lt;code&gt;known_group_chats_v2&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// v2: the first store held titles wrongly marked as groups by older builds, and a 1:1 contact&lt;/span&gt;
&lt;span class="c1"&gt;// was hidden for good. A fresh store drops them.&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;PREFS_NAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"known_group_chats_v2"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A new name means an empty store, and the entries rebuild from fresh evidence. The cost is that real groups are re-learned once. The alternative, trusting every existing flag, would have kept the bug alive on every updated phone. When a bug is in persisted data, a schema or file-name version is the cheap, honest reset.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell myself earlier
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;A cache of a &lt;em&gt;conclusion&lt;/em&gt; needs a way to be wrong and recover. Build &lt;code&gt;forget&lt;/code&gt; at the same time as &lt;code&gt;remember&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If the answer is yes/no, keep a digest, not the thing you looked up.&lt;/li&gt;
&lt;li&gt;Put a version in the name of anything persisted from a heuristic. You will want to throw it away.&lt;/li&gt;
&lt;li&gt;Check the in-memory set first; the lookup runs on every accessibility event.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The code is plain Kotlin and &lt;code&gt;SharedPreferences&lt;/code&gt;; nothing in it depends on the chat app.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;QuickDial is an independent app, not affiliated with WhatsApp LLC or Meta.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>androiddev</category>
      <category>kotlin</category>
      <category>a11y</category>
    </item>
    <item>
      <title>The upload failed on a flaky link but the audio was fine: resending a voice note patiently, with a timeout that grows</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Wed, 25 Nov 2026 06:13:51 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/the-upload-failed-on-a-flaky-link-but-the-audio-was-fine-resending-a-voice-note-patiently-with-a-49a5</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/the-upload-failed-on-a-flaky-link-but-the-audio-was-fine-resending-a-voice-note-patiently-with-a-49a5</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of Bolo, and this post is published from my account. It was drafted and published by an AI agent working on my behalf from the app's source code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.ashwar.bolo&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-resend" rel="noopener noreferrer"&gt;Bolo&lt;/a&gt; is an Android voice-typing app: you speak, the take is transcribed, and the text lands in whatever field you were typing in. This post is about one failure that looked like three different bugs, and the small &lt;code&gt;TranscriptionResend&lt;/code&gt; object that fixed it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually happened
&lt;/h2&gt;

&lt;p&gt;The report was short: on a home connection, "it times out, then I pressed retry and it cancelled". Looking at the server-side log for that morning, the picture was this (one 24-second note, about 104 KB):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first upload was reset after 15.5 s and never reached the server.&lt;/li&gt;
&lt;li&gt;The single automatic retry died 5 s in.&lt;/li&gt;
&lt;li&gt;The third send, by hand, reached the server and was transcribed in 1.5 s.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the audio was fine, the server was fine, and the link was bad. The missing piece was not a smarter transcription path, it was &lt;strong&gt;resending patiently&lt;/strong&gt;. The "retry cancelled" part is a trap worth knowing about too: OkHttp reports a deliberate cancel as an ordinary network error, so a retry loop has to tell the two apart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 1: only resend failures of the link, never of the request
&lt;/h2&gt;

&lt;p&gt;A resend is only worth doing when the same bytes might succeed next time. A rejected request will be rejected again. The classification is a few lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;isTransient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Throwable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;VoxException&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;                       &lt;span class="c1"&gt;// our own, deliberate failure&lt;/span&gt;
    &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UnknownHostException&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IOException&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;isCallCancelled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;retrofit2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HttpException&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;code&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;TRANSIENT_HTTP&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// 500-504 from the server or nginx; 520-524 are Cloudflare's "origin did not answer in time".&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;TRANSIENT_HTTP&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;502&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;504&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;520&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;521&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;522&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;523&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;524&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The easy mistake is the &lt;code&gt;IOException&lt;/code&gt; branch. OkHttp reports its own cancel (a tap that stopped the job) as &lt;code&gt;IOException("Canceled")&lt;/code&gt;. Treat that as transient and a user's deliberate stop starts another upload. So that one message is carved out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;isCallCancelled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IOException&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Canceled"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ignoreCase&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rule 2: a bounded loop, with a clock, that never swallows cancellation
&lt;/h2&gt;

&lt;p&gt;Four attempts in total, pauses of 2, 5 and 10 seconds, and a 90-second window after which no new attempt starts. The loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/* attempts, backoff, window, clock, sleep injected */&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;startedAt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;nowMs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;block&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;currentCoroutineContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ensureActive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;      &lt;span class="c1"&gt;// coroutine cancelled? stop, do not resend&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;pause&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;backoffMs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getOrElse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;backoffMs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lastOrNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;0L&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;outOfTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;nowMs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;startedAt&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;pause&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;windowMs&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;isTransient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;maxAttempts&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;outOfTime&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
            &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
            &lt;span class="nf"&gt;onResend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pause&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter. &lt;code&gt;ensureActive()&lt;/code&gt; runs first in the catch block, so a cancelled coroutine rethrows its cancellation instead of being retried. And the window check includes the &lt;em&gt;next pause&lt;/em&gt;, so the loop does not start an attempt it already knows it cannot finish inside the window. The clock and the sleep are parameters, which is what makes the loop testable without waiting 17 real seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 3: resending must be safe
&lt;/h2&gt;

&lt;p&gt;Resending an upload that already landed would be a double charge and a double transcription. The server keys work on the device and a hash of the audio bytes, and it keeps a completed transcript for ten minutes. A resend of a take that did arrive gets the cached text back: no second speech-to-text call, no second quota use. I had written the idempotency key for a different reason, and it is what makes an aggressive client-side resend a safe design instead of a gamble.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 4: the read timeout should depend on the note
&lt;/h2&gt;

&lt;p&gt;A fixed 30-second read timeout cut off a slow but healthy answer, because the server's fallbacks take longer on a longer note. The upload already carries its duration in a header, so an OkHttp interceptor sets the timeout per request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;readTimeoutMsFor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audioDurationMs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Long&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Long&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;BASE_READ_TIMEOUT_MS&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;audioDurationMs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;coerceAtLeast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0L&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;coerceIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;BASE_READ_TIMEOUT_MS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;MAX_READ_TIMEOUT_MS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// 30 s up to 120 s&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thirty seconds plus half the note's length, never below 30 s, never above two minutes. Requests without the header keep the client defaults, so the rest of the app's networking is untouched.&lt;/p&gt;

&lt;h2&gt;
  
  
  And when every attempt fails
&lt;/h2&gt;

&lt;p&gt;The last failure is rethrown, and the take is kept on the phone rather than discarded. A notification then says the voice note was not sent; tapping it opens the app on the screen where the saved take sits with a Retry button, and the notification clears itself once that take is sent or discarded. A failed upload is an inconvenience. Losing what someone said is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell myself earlier
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Work out &lt;em&gt;where&lt;/em&gt; in the chain the failure is before touching the transcription code. Here, a 15-second reset before the server saw anything.&lt;/li&gt;
&lt;li&gt;Make the retry classifier an explicit allow-list, and write the cancel case down as its own line.&lt;/li&gt;
&lt;li&gt;Put the clock and sleep in the function signature. The tests then cover the window and backoff in milliseconds.&lt;/li&gt;
&lt;li&gt;Idempotency on the server is what lets the client be persistent.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The code is plain Kotlin and OkHttp, nothing specific to speech. If you upload anything over a bad link from Android, the same four rules apply.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Bolo is a voice-typing keyboard-bubble app for Android; this write-up is about its networking code, not a claim about transcription accuracy.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>networking</category>
      <category>mobile</category>
    </item>
    <item>
      <title>When to stop polling a user who stopped opening your app: a dormancy ladder, and the uninstall signal Android lacks</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Tue, 24 Nov 2026 06:15:39 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/when-to-stop-polling-a-user-who-stopped-opening-your-app-a-dormancy-ladder-and-the-uninstall-51pi</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/when-to-stop-polling-a-user-who-stopped-opening-your-app-a-dormancy-ladder-and-the-uninstall-51pi</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of the app described here, and this post is published from my account. It was drafted and published by an AI agent working from the project's source code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.kkfe.scooterlog&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-dormancy" rel="noopener noreferrer"&gt;ScooterLog&lt;/a&gt; keeps a log of an electric scooter's battery, charges and rides by polling the vehicle's data on the user's behalf from a small server. ScooterLog is an independent app, not affiliated with, endorsed by or sponsored by Ola Electric.&lt;/p&gt;

&lt;p&gt;That design has a cost that grows silently: every person who installs the app and then forgets it keeps being polled, forever. This post is about the small "dormancy ladder" that handles it, and about the one signal it needed that Android does not provide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two bad answers
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Poll everyone forever.&lt;/strong&gt; Simple, and wasteful: the load grows with every abandoned install, and it is a steady stream of requests to someone else's API for nobody.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stop polling when the app hasn't been opened for N days.&lt;/strong&gt; Also simple, and wrong for this app. Someone can leave ScooterLog installed, never open it, and still want the history and the alarms (charge complete, low battery) it records in the background. Pausing them loses data they would have wanted. The rule I was given was the opposite: keep tracking people who still have the app, nudge the long-dormant, and stop only for people who no longer have it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The missing signal
&lt;/h2&gt;

&lt;p&gt;"Opened the app" is easy: the app calls the server's state endpoint. "Still installed" is the hard part. Android sends no uninstall broadcast to the server, or to anyone.&lt;/p&gt;

&lt;p&gt;The app already had a background worker that runs about every 15 minutes and calls the server's alarm endpoint, even when the app is closed. So the worker's call became a heartbeat. The server records two timestamps per sign-in: &lt;code&gt;last_open_ms&lt;/code&gt; (a person opened the app) and &lt;code&gt;last_beat_ms&lt;/code&gt; (the worker called). An uninstalled app stops both, and &lt;strong&gt;a heartbeat that stops is the uninstall signal.&lt;/strong&gt; A third signal is a web-push subscription that comes back "gone" (HTTP 404 or 410), which the server drops.&lt;/p&gt;

&lt;h2&gt;
  
  
  Slow down before you stop
&lt;/h2&gt;

&lt;p&gt;The first rung doesn't stop anything. It only slows the polling of a &lt;em&gt;parked&lt;/em&gt; scooter, by days since the last open:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;dormancy_floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last_open_ms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;now_ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;days&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now_ms&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last_open_ms&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;now_ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;DAY&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;900&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;days&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is a minimum gap in seconds: none under 30 days, 15 minutes from 30, an hour from 90, six hours from 180. The docstring carries the important rule: riding and charging cadence is never slowed, so a ride that is found is still followed minute by minute. Only the parked, quiet case gets cheaper.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nudge, then pause only if the app is gone
&lt;/h2&gt;

&lt;p&gt;A daily pass walks the sign-in holders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;NUDGE_AT_DAYS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dormant_owners&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;open_days&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now_ms&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'last_open_ms'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;DAY&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'nudges'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;NUDGE_AT_DAYS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;open_days&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;NUDGE_AT_DAYS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'nudges'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# web push, plus a marker file the Android worker turns into a notification&lt;/span&gt;
        &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mark_nudged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;
    &lt;span class="n"&gt;gone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;now_ms&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'last_beat_ms'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;DAY&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all_push_subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;open_days&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'nudges'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;now_ms&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'nudged_ms'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;DAY&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;gone&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pause_tracking&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading it as a ladder: unopened for 60 days, send the first nudge ("Open the app once to keep your history and alerts going"); at 180, the second. A pause needs &lt;strong&gt;all&lt;/strong&gt; of these at once: unopened 60+ days, already nudged, the last nudge at least 14 days old, no heartbeat for 30 days, and no live push subscription. Any single sign that the app is still there keeps tracking going.&lt;/p&gt;

&lt;p&gt;Pausing is gentle. History, tokens and alerts stay, and any app open flips the status back to active and resets the nudge count:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"UPDATE users SET status='ACTIVE', nudges=0 WHERE user_id=? AND status='PAUSED'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Two details that bit
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A linked member has no app of its own.&lt;/strong&gt; When one person's sign-in covers a second login, the member inherits the owner's opens and heartbeats, via a join in the query. Without it, a family member's login would look dormant while its owner used the app daily. The ladder also skips members and acts on owners.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Throttle the writes.&lt;/strong&gt; A heartbeat every 15 minutes per user would be a database write each time. &lt;code&gt;touch&lt;/code&gt; updates a timestamp only if the stored one is more than 10 minutes old.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The test that pins it
&lt;/h2&gt;

&lt;p&gt;The tests build users with chosen open and heartbeat ages and assert the ladder: an install unopened for 70 days with a live heartbeat is nudged and later &lt;em&gt;not&lt;/em&gt; paused; one with no heartbeat for 40 days is nudged, then paused 15 days later; a fresh one is untouched; and an app open resumes a paused user at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;"Last opened" is not "uninstalled". If you need the second, build a heartbeat; Android won't tell your server.&lt;/li&gt;
&lt;li&gt;Slow the cheap, quiet case first; never slow the case where something is happening.&lt;/li&gt;
&lt;li&gt;Require several independent signs before stopping anyone, and make stopping reversible by the simplest user action.&lt;/li&gt;
&lt;li&gt;Resolve who "the user" is before you read their activity: linked accounts should share it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ScooterLog is on Google Play: &lt;a href="https://play.google.com/store/apps/details?id=com.kkfe.scooterlog&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-dormancy" rel="noopener noreferrer"&gt;https://play.google.com/store/apps/details?id=com.kkfe.scooterlog&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-dormancy&lt;/a&gt;. It logs battery, charging and ride history for a compatible Ola Electric scooter. ScooterLog is an independent app, not affiliated with, endorsed by or sponsored by Ola Electric. The code here is from the current server source, and I don't claim which release runs it.&lt;/p&gt;

</description>
      <category>android</category>
      <category>python</category>
      <category>backend</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Not a UPI QR, or couldn't read it? A scan result with three outcomes, and a debug log that never ships</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Tue, 24 Nov 2026 06:12:34 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/not-a-upi-qr-or-couldnt-read-it-a-scan-result-with-three-outcomes-and-a-debug-log-that-never-18kg</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/not-a-upi-qr-or-couldnt-read-it-a-scan-result-with-three-outcomes-and-a-debug-log-that-never-18kg</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of the app described here, and this post is published from my account. It was drafted and published by an AI agent working from the project's source code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.ashwar.autoupiqr&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-three-outcomes" rel="noopener noreferrer"&gt;Auto UPI QR&lt;/a&gt; reads a UPI QR from a picture and hands the link to the UPI app you already use. This post is about the smallest piece of it: what the scanner returns when it is done, and why that return type has three cases instead of two.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two-case version
&lt;/h2&gt;

&lt;p&gt;The obvious signature is &lt;code&gt;suspend fun scan(uri): UpiQr?&lt;/code&gt;. A link, or null. It is also the version that gives the user a bad message, because null covers three different situations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The picture has a QR, and it is a UPI payment link. Go on.&lt;/li&gt;
&lt;li&gt;The picture has no QR, or a QR that is not a payment (a website, a Wi-Fi login, a shop's loyalty page). Tell the user this picture has no UPI QR in it.&lt;/li&gt;
&lt;li&gt;Something broke while reading: the file could not be opened, the decoder threw. Tell the user the picture could not be read, which is a different thing to try again.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If both 2 and 3 collapse to "no QR found", a user whose file simply failed to open is told their QR is bad, and goes to ask the shopkeeper for a new one.&lt;/p&gt;

&lt;h2&gt;
  
  
  The sealed result
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Found&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UpiQr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;NoUpiQr&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;imageUri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Uri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;mlKit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;InputImage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromFilePath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;imageUri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="nf"&gt;withContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Dispatchers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Default&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;imageUri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Found&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NoUpiQr&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The inner passes return &lt;code&gt;UpiQr?&lt;/code&gt;, where null means "this pass saw nothing". Only the outer function turns "every pass saw nothing" into &lt;code&gt;NoUpiQr&lt;/code&gt;, and only the &lt;code&gt;catch&lt;/code&gt; produces &lt;code&gt;Error&lt;/code&gt;. The caller then has to handle each case, because &lt;code&gt;when&lt;/code&gt; over a sealed class is exhaustive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ImageScanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;Found&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;paySheet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;NoUpiQr&lt;/span&gt;  &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;toast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;toast_no_upi_qr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;Error&lt;/span&gt;    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;toast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;toast_scan_error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a fourth case later and the compiler points at every place that must decide what to say.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Is it a UPI QR" is decided by the parser, not the decoder
&lt;/h2&gt;

&lt;p&gt;An image can hold several QR codes: a poster with a website code beside the payment code, say. ML Kit returns all of them, and the scanner picks the first one that parses as a payment link:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstNotNullOfOrNull&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;UpiQr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rawValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;UpiQr.parse&lt;/code&gt; returns null unless the text starts with &lt;code&gt;upi://pay&lt;/code&gt; and carries a non-blank payee address. So a decoded Wi-Fi code is not an error and not a found payment: it is simply "not a UPI QR", and the loop moves on. Decoding and deciding are two steps, and keeping the second one in the parser means the three outcomes stay honest.&lt;/p&gt;

&lt;h2&gt;
  
  
  A log line that only exists in debug builds
&lt;/h2&gt;

&lt;p&gt;While tuning the scanner on worn, printed stickers I wanted to know which pass read each one, and the exact text, to check the hand-off byte for byte. That text includes the payee's address. So the log call is guarded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;qr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UpiQr&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BuildConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;DEBUG&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;i&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"AUQ"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"scan pass=$pass raw=${qr?.raw}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;BuildConfig.DEBUG&lt;/code&gt; is a compile-time constant, so a release build has no branch to take and writes nothing. The app also has no internet permission, so nothing could leave the phone anyway; the guard is about not leaving payee details in the system log of someone's phone, where other tools can read it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Model "nothing found" and "could not look" as different results; they need different words and different next steps.&lt;/li&gt;
&lt;li&gt;A sealed class makes every caller choose a message for every outcome.&lt;/li&gt;
&lt;li&gt;Let the parser decide what counts as a payment QR, so non-payment codes fall into "no UPI QR" without special cases.&lt;/li&gt;
&lt;li&gt;Anything diagnostic that prints user data belongs behind &lt;code&gt;BuildConfig.DEBUG&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Auto UPI QR is on Google Play: &lt;a href="https://play.google.com/store/apps/details?id=com.ashwar.autoupiqr&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-three-outcomes" rel="noopener noreferrer"&gt;https://play.google.com/store/apps/details?id=com.ashwar.autoupiqr&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w48-three-outcomes&lt;/a&gt;. It reads UPI QR codes from images and hands the link to your own UPI app. It is not a bank and never sees your PIN. The code here is from the current source, and I don't claim which Play build contains it. Always check the payee name before entering your UPI PIN.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>mobile</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Audio before the socket is ready: queueing WebSocket messages until the session says so, and a final transcript with a deadline</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Mon, 23 Nov 2026 06:15:25 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/audio-before-the-socket-is-ready-queueing-websocket-messages-until-the-session-says-so-and-a-2h4j</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/audio-before-the-socket-is-ready-queueing-websocket-messages-until-the-session-says-so-and-a-2h4j</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of Bolo, and this post is published from my account. It was drafted and published by an AI agent working on my behalf from the app's source code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.ashwar.bolo" rel="noopener noreferrer"&gt;Bolo&lt;/a&gt; (search "Bolo AI" on Google Play) can stream a voice take to a transcription service over a WebSocket while you are still speaking. The client class is under 300 lines, and three small decisions in it are worth writing down, because each one fixes a bug that looks like "it works on my network".&lt;/p&gt;

&lt;h2&gt;
  
  
  1. "Socket open" is not "session ready"
&lt;/h2&gt;

&lt;p&gt;OkHttp calls &lt;code&gt;onOpen&lt;/code&gt; as soon as the WebSocket handshake completes. The server, though, still has to set up the transcription session, and it announces that with its own message (&lt;code&gt;session.ready&lt;/code&gt;, or &lt;code&gt;session.created&lt;/code&gt; / &lt;code&gt;session.updated&lt;/code&gt; on the other protocol the class speaks). Audio sent in between can be dropped.&lt;/p&gt;

&lt;p&gt;So every message that needs a ready session goes through one function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;sendRaw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;requiresReady&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Unit&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;requiresReady&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;sessionReady&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;pendingMessages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addLast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Unit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;sent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;webSocket&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Unit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/* interrupted */&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The session-init message itself passes &lt;code&gt;requiresReady = false&lt;/code&gt;; audio chunks and the commit pass &lt;code&gt;true&lt;/code&gt;. When the ready message arrives, the queue is flushed in order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;flushPendingMessages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pendingMessages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNotEmpty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;sent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;webSocket&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pendingMessages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeFirst&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;failFinalTranscript&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The caller never has to know whether the session was ready yet. The first words you speak are in the queue, in order, ahead of everything that follows. If a send fails during the flush, the pending wait is failed straight away instead of leaving it to time out.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. One deferred for the final answer, with a deadline
&lt;/h2&gt;

&lt;p&gt;The result the caller wants is a single string, the final transcript. A &lt;code&gt;CompletableDeferred&amp;lt;String&amp;gt;&lt;/code&gt; holds it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;awaitFinalTranscript&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;withTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;finalTranscriptDeferred&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Throwable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;failure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;VoxException&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nc"&gt;VoxException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cm"&gt;/* timed out */&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things complete that deferred: a transcript message, an error message, or a socket failure. Each failure path goes through one helper that completes it exceptionally only if it is not already completed, because a socket failure and an error message can arrive for the same take and the second completion must not throw.&lt;/p&gt;

&lt;p&gt;The 12-second limit is what stops a dropped connection from leaving the keyboard-side UI waiting forever. A typed failure reason (connect failed, timed out, stream interrupted, unavailable) travels with the exception, so the app can say which of them happened rather than "something went wrong".&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Reset between takes, not just close
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;resetFinalTranscriptWait()&lt;/code&gt; makes a fresh deferred, clears the queue and sets &lt;code&gt;sessionReady = false&lt;/code&gt;. It matters when one connection is reused for the next take: a stale completed deferred would hand back the previous take's text instantly, and a stale queue would replay old audio.&lt;/p&gt;

&lt;h2&gt;
  
  
  A small extra: matching the sample rate the other protocol wants
&lt;/h2&gt;

&lt;p&gt;Capture on the phone is 16 kHz PCM. One of the two protocols expects 24 kHz, so audio is linearly interpolated up before it is sent: for each output sample, find its fractional source position, and blend the two neighbouring input samples by the fraction. It is deliberately simple; with speech, the point is to match the rate the service declares, not to master audio.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would test
&lt;/h2&gt;

&lt;p&gt;The queue is the part that is easy to break. The cases worth a unit test: audio sent before ready is delivered in order after ready; a send that fails mid-flush fails the wait; a second failure after the first does not throw; reset between takes does not return the old transcript.&lt;/p&gt;

&lt;p&gt;Bolo is available on Google Play; search "Bolo AI".&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>websockets</category>
      <category>coroutines</category>
    </item>
    <item>
      <title>Work and personal Claude accounts, one sidebar: keeping Claude Desktop's groups and archive the same across accounts</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Mon, 23 Nov 2026 06:13:18 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/work-and-personal-claude-accounts-one-sidebar-keeping-claude-desktops-groups-and-archive-the-1lhj</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/work-and-personal-claude-accounts-one-sidebar-keeping-claude-desktops-groups-and-archive-the-1lhj</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of Relaymote, and this post is published from my account. It was drafted and published by an AI agent working on my behalf from the project's documentation. Relaymote is unofficial; not affiliated with or endorsed by Anthropic.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Plenty of people use Claude with more than one account: a work organisation and a personal plan, or two organisations for two clients. On the command line there are good tools for this; most give each account its own config folder.&lt;/p&gt;

&lt;p&gt;Claude Desktop is different. Each account keeps &lt;strong&gt;its own sidebar&lt;/strong&gt;: sessions, archive, groups and routines. Switch accounts and the app looks like someone else's. The groups you carefully arranged are not there; sessions you archived are back.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ashwarsadh/relaymote" rel="noopener noreferrer"&gt;Relaymote&lt;/a&gt; has an &lt;strong&gt;Accounts&lt;/strong&gt; module that keeps those sidebars in step, so switching accounts shows you the same app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preview first, always
&lt;/h2&gt;

&lt;p&gt;Turn on &lt;strong&gt;Settings › Modules › Accounts&lt;/strong&gt;, then open &lt;strong&gt;Accounts&lt;/strong&gt; (or run &lt;code&gt;relaymote accounts&lt;/code&gt;):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You see every Claude account and organisation signed in on this computer, and &lt;strong&gt;how far their sidebars have drifted apart&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Preview sync&lt;/strong&gt; shows exactly what would change in each account. Nothing is written.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sync now&lt;/strong&gt; writes it, after &lt;strong&gt;backing up every file it touches&lt;/strong&gt;. There is an &lt;code&gt;undo&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What syncs: session records, archive state, session details and routines. Sidebar groups that Claude loses are repaired; folding groups &lt;em&gt;across&lt;/em&gt; accounts is opt-in.&lt;/p&gt;

&lt;h2&gt;
  
  
  The awkward part: only one account is "live"
&lt;/h2&gt;

&lt;p&gt;Claude Desktop keeps only the account that is &lt;strong&gt;currently open&lt;/strong&gt; in memory. Writing that account's files while Desktop is running would be overwritten on its next save. So Relaymote updates the &lt;strong&gt;other&lt;/strong&gt; accounts straight away and applies changes for the open account when Claude Desktop is closed. It is slower, and it is the only order that does not lose your edits.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this is, and what it is not
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is for &lt;strong&gt;your own&lt;/strong&gt; accounts: work and personal, or separate organisations you belong to. Each account is its own subscription, under its own terms.&lt;/li&gt;
&lt;li&gt;It is &lt;strong&gt;not&lt;/strong&gt; a way to pool usage limits, and it does not move sessions between accounts' quotas. A session runs on the account it belongs to.&lt;/li&gt;
&lt;li&gt;It reads and writes Claude Desktop's local files on your PC. Nothing is uploaded.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why bother
&lt;/h2&gt;

&lt;p&gt;Because the sidebar &lt;em&gt;is&lt;/em&gt; the project map once you run many sessions. Relaymote's Organizer files every new session into its project's group automatically; Accounts makes that map the same whichever account you open. Together they mean the place you look for "the API work" does not depend on which login is active.&lt;/p&gt;

&lt;p&gt;The commands are under "Accounts" in the &lt;a href="https://github.com/ashwarsadh/relaymote" rel="noopener noreferrer"&gt;README&lt;/a&gt;: &lt;code&gt;relaymote accounts sync [--apply] [--fold]&lt;/code&gt;, &lt;code&gt;undo&lt;/code&gt;, &lt;code&gt;hold&lt;/code&gt;, &lt;code&gt;freeze&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Relaymote is unofficial; not affiliated with or endorsed by Anthropic.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>devtools</category>
      <category>opensource</category>
      <category>ai</category>
    </item>
    <item>
      <title>Counting what is selected in a list that recycles its rows: two sightings, whole rows only, and a cap from the app's own count</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Fri, 20 Nov 2026 06:19:19 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/counting-what-is-selected-in-a-list-that-recycles-its-rows-two-sightings-whole-rows-only-and-a-1813</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/counting-what-is-selected-in-a-list-that-recycles-its-rows-two-sightings-whole-rows-only-and-a-1813</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of QuickDial, and this post is published from my account. It was drafted and published by an AI agent working on my behalf from the app's source code. QuickDial is not affiliated with WhatsApp LLC or Meta.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.ashwar.quickdialbridge&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w47-selection" rel="noopener noreferrer"&gt;QuickDial&lt;/a&gt; has a "Share all" button for a chat app's multi-select mode: you tick several photos, and one tap sends them on together, in chat order. Behind that button sits a small, awkward problem that has nothing to do with sharing. &lt;strong&gt;How do you reliably learn which rows of a scrolling, recycling list are selected, when you only ever see the rows currently on screen?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An Android accessibility service sees the window's node tree. A &lt;code&gt;RecyclerView&lt;/code&gt;-style list only has the visible rows in it, and rows are reused as you scroll. This post is about the three rules that turned that stream of noisy snapshots into a stable selection, each added after a real wrong result.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;While the chat app is in selection mode, the collector gets a callback on every window change. For each visible row it reads a small description (its clock time, how many photos it shows, sent or received, the date line above it) and whether the row is marked selected. Rows are kept in chat order in memory, for the current selection only, and the whole thing is cleared when selection mode ends. Only counts and shapes of rows are used to decide; the Play build reads photo and video rows and never message text.&lt;/p&gt;

&lt;p&gt;The first version was the obvious one: if a row is selected on this screen, add it; if it is shown unselected, drop it. Three bugs later it is not that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 1: a row counts only after two sightings
&lt;/h2&gt;

&lt;p&gt;The first wrong result: four photos were ticked, and the share screen came back with three extra photos from an earlier date. While the list is scrolled quickly, a recycled row can report "selected" for a moment from the binding it had before. A single snapshot is not evidence.&lt;/p&gt;

&lt;p&gt;So each row keeps a counter, and a row only enters the selection after it has been seen selected in two separate screen updates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sightings&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;sightings&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sightings&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;MIN_SIGHTINGS&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;   &lt;span class="c1"&gt;// MIN_SIGHTINGS = 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The cost is honest and small: a row you scrolled past very fast may not have been seen twice. The app then says that only N of M were on screen, and you scroll a little. A visible "scroll up a bit" is a better failure than sending the wrong photos.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 2: count only whole rows
&lt;/h2&gt;

&lt;p&gt;The second wrong result: a row cut off by the edge of the list reads short. It has no clock time, fewer tiles, no tick. Each short reading produced a new row key, so the same photo turned up as several entries, none of which was ever seen unselected again to remove it.&lt;/p&gt;

&lt;p&gt;The fix is to measure the row against the list's bounds and skip any row that is not wholly inside:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;wholeRows&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;isWhole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rowRect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;listRect&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rowWhole&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getOrNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A half-visible row is simply not a witness yet. It becomes one when scrolling brings it fully into view.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 3: a plain row seen unselected must not erase its twin
&lt;/h2&gt;

&lt;p&gt;The third wrong result came from a live run: a minute with seven photos, no captions, the sixth and seventh ticked. Plain photos read exactly alike, and a row key only tells them apart while they share a screen. Scrolling up, the collector saw some unticked photo from the same minute, took it for the ticked one, and removed the entry. One of three photos reached the share screen.&lt;/p&gt;

&lt;p&gt;The rule now: a &lt;em&gt;plain&lt;/em&gt; row seen unselected no longer deletes anything. It only marks the entry as the first candidate to go, by giving it the oldest possible "last seen":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;isSelected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;isSelected&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;plain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;picked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;lastSeen&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;MIN_VALUE&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rows with something distinctive (a caption, an album shape) are still removed as before, because their keys are reliable.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ceiling: the app's own count
&lt;/h2&gt;

&lt;p&gt;Rules 1 to 3 make wrong rows rarer, not impossible. So there is a final, independent check. The chat app shows its own count of selected items ("5 selected"), and it counts a message once and each photo of an album once. The collector must never hold more rows than that number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;dropStale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;onScreen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;shown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;onScreen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toSet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;counted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sightings&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;MIN_SIGHTINGS&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;bases&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;counted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;groupingBy&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;picked&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;base&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;eachCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;victim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;counted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;shown&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;minWithOrNull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;compareBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bases&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;picked&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;base&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;lastSeen&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;victim&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When there are too many, the victim is chosen in a fixed order: a second reading of the same bubble first (the same row dated differently on two screens), then whichever row was seen selected longest ago. A row on the current screen never goes. A rule like "drop anything between two rows I can see" was considered and left out, because the order of rows is only as good as the neighbours seen so far and that rule could drop a real one.&lt;/p&gt;

&lt;p&gt;This also explains the plain-row marker in Rule 3. Giving a doubtful entry the oldest timestamp does not delete it; it just puts it first in the queue if the count says there are too many.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would copy into other projects
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Treat one accessibility snapshot as a rumour.&lt;/strong&gt; Require repeated sightings before acting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Only trust complete rows.&lt;/strong&gt; Anything clipped by the viewport is partial data; wait for it to be whole.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;When two items look identical, do not let one's absence delete the other.&lt;/strong&gt; Demote it instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Find a number the other app shows and use it as a ceiling.&lt;/strong&gt; An independent count catches errors your own logic cannot see.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fail visibly.&lt;/strong&gt; "Only 4 of 5 were on screen, scroll a little" costs the user a second; a silent wrong share costs a conversation.&lt;/li&gt;
&lt;li&gt;Keep it all in memory, for the current selection, and clear it when selection ends.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;QuickDial is on &lt;a href="https://play.google.com/store/apps/details?id=com.ashwar.quickdialbridge&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w47-selection" rel="noopener noreferrer"&gt;Google Play&lt;/a&gt;. It prepares photos for you to send; you choose the app and the person and press send yourself. QuickDial is not affiliated with WhatsApp LLC or Meta.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;AI Disclosure: this article was drafted and published by an AI agent on the developer's behalf, from the app's source code.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>a11y</category>
    </item>
    <item>
      <title>Is my battery wearing out? A monthly range trend that survives weather, short rides and time zones</title>
      <dc:creator>Ashwar Sadh</dc:creator>
      <pubDate>Fri, 20 Nov 2026 06:15:49 +0000</pubDate>
      <link>https://dev.to/ashwar_sadh_f7abe6f82c8e9/is-my-battery-wearing-out-a-monthly-range-trend-that-survives-weather-short-rides-and-time-zones-5bdp</link>
      <guid>https://dev.to/ashwar_sadh_f7abe6f82c8e9/is-my-battery-wearing-out-a-monthly-range-trend-that-survives-weather-short-rides-and-time-zones-5bdp</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I'm the developer of ScooterLog, and this post is published from my account. It was drafted and published by an AI agent working on my behalf from the app's source code. ScooterLog is an independent app, not affiliated with, endorsed by or sponsored by Ola Electric.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.kkfe.scooterlog&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w47-monthly" rel="noopener noreferrer"&gt;ScooterLog&lt;/a&gt; keeps a charge history and trip log for connected electric scooters. One chart in it answers a question every rider eventually asks: &lt;strong&gt;is the battery getting worse?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The raw data cannot answer that directly. All it has is timestamped readings of battery percent, odometer and charging state. This post is about turning those into one number per month that is honest enough to compare month against month, and about the three decisions that keep that number from lying.&lt;/p&gt;

&lt;h2&gt;
  
  
  The number: full-charge range, per month
&lt;/h2&gt;

&lt;p&gt;For each calendar month, take the rides in that month and compute&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;full_range_km = km ridden / percent used * 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is "how far would 100% have taken me this month". If it drifts down over many months, that is a reasonable sign of battery wear. If it jumps around, it is weather, riding mode and how hard you ride.&lt;/p&gt;

&lt;p&gt;Here is the function, trimmed to what matters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;monthly_range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vehicle_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;months&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Real range on 100% per IST calendar month, from that month's own rides
    (km / % used). A month needs &amp;gt;= 15% ridden to count."""&lt;/span&gt;
    &lt;span class="n"&gt;since&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;_now_ms&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;months&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;86400000&lt;/span&gt;
    &lt;span class="c1"&gt;# ... SELECT source_ms, battery_soc, odometer, charging_state, lat, lng&lt;/span&gt;
    &lt;span class="c1"&gt;#     FROM history WHERE user_id=? AND vehicle_id=? AND source_ms&amp;gt;=?&lt;/span&gt;
    &lt;span class="c1"&gt;#     ORDER BY source_ms&lt;/span&gt;
    &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;_trips&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'pct_used'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'pct_used'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'%Y-%m'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gmtime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'start_ms'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;IST_MS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;km&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pct&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;km&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'km'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pct&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'pct_used'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;full_range_km&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;km&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;pct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;km&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;km&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rides&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;km&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pct&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pct&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three decisions are hiding in there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 1: sum first, then divide
&lt;/h2&gt;

&lt;p&gt;Each ride has its own km and percent. It is tempting to compute km per percent for each ride and average the results. Don't. A 2 km errand that used 1% and a 40 km ride that used 14% are not equal witnesses: the first one's percent is rounded to a whole number, so its ratio can be off by a large factor, while the second one's is off by a few percent at most.&lt;/p&gt;

&lt;p&gt;Summing kilometres and summing percent across the month, then dividing once, weights every ride by how much battery it actually used. Small rides add a little noise to a big total instead of equal noise to an average.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 2: refuse a month that has not ridden enough
&lt;/h2&gt;

&lt;p&gt;A month with only 3% of riding gives you &lt;code&gt;km / 3 * 100&lt;/code&gt;, which is a rounding error multiplied by thirty. So the function drops any month where the summed percent is under 15:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pct&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The chart then shows nothing for that month, and the front end says so in plain words ("Appears once a month has about 15% of riding.") instead of drawing a dubious bar. A missing bar is better than a precise-looking wrong one, especially on a chart whose whole point is a trend.&lt;/p&gt;

&lt;p&gt;The same floor is used when the app estimates km per 1% from rides for the range planner, so the two screens never disagree about how much data is enough.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision 3: bucket by the rider's calendar, not the server's
&lt;/h2&gt;

&lt;p&gt;The server stores timestamps as UTC milliseconds. A ride that starts at 11 pm IST on the 30th is already the 1st in UTC. Bucket by UTC and that late-evening ride lands in the wrong month, which on a month-sized chart quietly moves part of one month's range into the next.&lt;/p&gt;

&lt;p&gt;The fix is one line: shift the start time by the rider's offset before converting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="no"&gt;IST_MS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;19800&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;   &lt;span class="c1"&gt;# +05:30&lt;/span&gt;
&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'%Y-%m'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gmtime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'start_ms'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;IST_MS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding the offset and then reading the result as if it were UTC (&lt;code&gt;gmtime&lt;/code&gt;) gives the local calendar month without any time-zone database. It is hard-coded to IST because that is where the app's riders are. For a global product you would store each rider's zone and apply that instead; I would rather say that plainly than pretend the constant is general.&lt;/p&gt;

&lt;p&gt;A ride is assigned to the month it &lt;strong&gt;started&lt;/strong&gt; in. A ride that crosses midnight on the last day of the month is counted whole, not split, because its kilometres and its percent belong together.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the chart says, and what it refuses to say
&lt;/h2&gt;

&lt;p&gt;The front end takes the first and last months on the chart and writes a sentence from them: the last month's range, how many rides it rests on, and the change against the first month. Then it adds the caveat that is the honest part:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A steady fall across months points to battery wear; one month can also move with weather and riding mode.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It deliberately says "points to", not "proves". Two months are two points; the app does not fit a line or put a number on wear. And with a single qualifying month it shows that month's figure and says the trend appears from next month, rather than comparing a month with itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Known limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The query window is &lt;code&gt;months * 31&lt;/code&gt; days back from now, so the oldest month on the chart can be cut part way through. The 15% floor limits the damage, but a partial first month can still read a little off.&lt;/li&gt;
&lt;li&gt;Rides come from sparse readings, so a ride's distance comes from the odometer difference and its percent from the battery difference between its first and last readings. Anything that hides those (a missed reading, a half-seen charge) shifts a month. That is why the ride reconstruction has its own rules about when to trust a ride, and why this function only sums what those rules accepted.&lt;/li&gt;
&lt;li&gt;A scooter ridden mostly in an eco mode one month and a fast mode the next will show a range change that is not battery wear at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Sum numerators and denominators across the period, then divide once.&lt;/li&gt;
&lt;li&gt;Set a minimum amount of data and show nothing below it.&lt;/li&gt;
&lt;li&gt;Bucket by the user's calendar. Shifting a UTC timestamp by a fixed offset and reading it with &lt;code&gt;gmtime&lt;/code&gt; is enough when the zone is fixed.&lt;/li&gt;
&lt;li&gt;Write the caveat into the sentence the user reads, not only into the docs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ScooterLog is on &lt;a href="https://play.google.com/store/apps/details?id=com.kkfe.scooterlog&amp;amp;utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=2026-w47-monthly" rel="noopener noreferrer"&gt;Google Play&lt;/a&gt;. It is a log and planner: it does not control the scooter and is not a security service. ScooterLog is an independent app, not affiliated with, endorsed by or sponsored by Ola Electric.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;AI Disclosure: this article was drafted and published by an AI agent on the developer's behalf, from the app's source code.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>sqlite</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
