Skip to content

fix(mobile): let the agents search draft debounce stand while typing - #6766

Merged
iscekic merged 3 commits into
mainfrom
kwf/janitor-mobile-agents-search-99b89f0c7e
Sep 28, 2026
Merged

iscekic merged 3 commits into
mainfrom
kwf/janitor-mobile-agents-search-99b89f0c7e

Conversation

@iscekic

@iscekic iscekic commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fix proof

Typing in the Agents search box persists the draft with saveDraft then immediately calls flushDraft on every keystroke, which cancels the 500 ms draft debounce and forces an encrypted SQLCipher write

Asserted value: apps/mobile/src/components/agents/use-session-search-input.ts. Sense check (jev): probability 0.94

The scripts were proven on an earlier base, so only the head ran.

Head d036745dc7e9

Head log: backend-assert 48681b688aae exited 0
$ git diff --unified=0 332f0c033e0781f85b7782c75ee4f2f595a7e2a8 d036745dc7e9d50b28326af4475973fa53e4eda9 -- apps/mobile/src/components/agents/use-session-search-input.ts
diff --git a/apps/mobile/src/components/agents/use-session-search-input.ts b/apps/mobile/src/components/agents/use-session-search-input.ts
--- a/apps/mobile/src/components/agents/use-session-search-input.ts
+++ b/apps/mobile/src/components/agents/use-session-search-input.ts
+
@@ -122,5 +119 @@ export function useSessionSearchInput({
-    void (async () => {
-      const { saveDraft, flushDraft, SESSION_SEARCH_DRAFT_KEY } = await getDrafts();
-      saveDraft(uid, SESSION_SEARCH_DRAFT_KEY, text);
-      void flushDraft(uid, SESSION_SEARCH_DRAFT_KEY);
-    })();
+    saveDraft(uid, SESSION_SEARCH_DRAFT_KEY, text);

Changelog for users

  • Typing in the Agents search box no longer triggers an encrypted storage write per keystroke, so the list filters smoothly.

Changelog for maintainers

  • The search draft now commits through the 500 ms durable debounce instead of being flushed on every keystroke.
  • A new hook flushes the pending search draft when the app leaves the active state and on unmount, preserving durability inside the debounce window.
  • The lazy dynamic import of the drafts module is gone; the hook now imports it statically, so unit tests that import this hook load encrypted-kv (expo-sqlite/drizzle).
  • Reviewers should check the background/unmount flush path first, since dropping it would lose the in-flight draft on a kill.

E2E proof

Typing in the Agents search box persists the draft with saveDraft then immediately calls flushDraft on every keystroke, which cancels the 500 ms draft debounce and forces an encrypted SQLCipher write plus an eviction listEntries scan per character, so search typing does extra storage work on the JS thread while the list is filtering; let the debounce stand instead of flushing each keystroke.

Code trace: apps/mobile/src/components/agents/use-session-search-input.ts:11 changed in e6ebcba5907e0730b29db851f902978e29fb7b07. Sense check (jev): probability 0.95

Changed lines
-import type * as DraftsModule from '@/lib/persist/drafts';
-
-// Durable draft persistence is loaded lazily via dynamic import so pure unit
-// tests that import this hook never load encrypted-kv (expo-sqlite/drizzle).
-
-let draftsPromise: Promise<typeof DraftsModule> | null = null;
-
-// eslint-disable-next-line typescript-eslint/promise-function-async -- conflicting require-await rule
-function getDrafts(): Promise<typeof DraftsModule> {
-  draftsPromise ??= import('@/lib/persist/drafts');
-  return draftsPromise;
-}
+import { SESSION_SEARCH_DRAFT_KEY, saveDraft } from '@/lib/persist/drafts';
+import { useDraftFlushOnBackground } from '@/lib/persist/use-draft-flush';
-  // Persist the visible typed string (durable, flushed). Skipped while the
+  // Persist the visible typed string through the 500 ms durable draft
+  // debounce — the per-key pending timer is left to commit on its own so
+  // typing never forces an encrypted write per keystroke. Skipped while the
+  // The debounced write still has to survive a background/kill inside the
+  // window, so flush the pending search draft when the app leaves `active`
+  // and on unmount.
+  useDraftFlushOnBackground(userId, SESSION_SEARCH_DRAFT_KEY, true);
+
-    void (async () => {
-      const { saveDraft, flushDraft, SESSION_SEARCH_DRAFT_KEY } = await getDrafts();
-      saveDraft(uid, SESSION_SEARCH_DRAFT_KEY, text);
-      void flushDraft(uid, SESSION_SEARCH_DRAFT_KEY);
-    })();
+    saveDraft(uid, SESSION_SEARCH_DRAFT_KEY, text);
Owner request

Fix 1 janitor finding in mobile/agents-search. Fix every one; the proof covers each.

  1. Typing in the Agents search box persists the draft with saveDraft then immediately calls flushDraft on every keystroke, which cancels the 500 ms draft debounce and forces an encrypted SQLCipher write plus an eviction listEntries scan per character, so search typing does extra storage work on the JS thread while the list is filtering; let the debounce stand instead of flushing each keystroke.
    Trace: apps/mobile/src/components/agents/use-session-search-input.ts:125: Typing in the Agents search box persists the draft with saveDraft then immediately calls flushDraft on every keystroke, which cancels the 500 ms draft debounce and forces an encrypted SQLCipher write plus an eviction listEntries scan per character, so search typing does extra storage work on the JS thread while the list is filtering; let the debounce stand instead of flushing each keystroke. (janitor area performance-reliability).
    Files: apps/mobile/src/components/agents/use-session-search-input.ts.

@iscekic iscekic added the kwf-janitor Admitted to the workflow from a janitor finding label Sep 26, 2026
@kilo-code-bot

kilo-code-bot Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The only change since the previous review (c5ca7f6b6) is a style-only reorder of the @/lib/persist/drafts import names in the mobile search-input hook; both symbols are still used exactly as before, so the debounced-draft behavior and the background/unmount flush path are unchanged and no new issues are introduced.

Files Reviewed (1 file)
  • apps/mobile/src/components/agents/use-session-search-input.ts
Previous Review Summary (commit c5ca7f6)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit c5ca7f6)

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the single-file change that stops flushing the Agents search draft on every keystroke and instead relies on the 500 ms durable draft debounce plus a background/unmount flush hook; the AppState subscription is removed on cleanup and the module-level pending-timer map is bounded, so no memory leak is introduced.

Files Reviewed (1 file)
  • apps/mobile/src/components/agents/use-session-search-input.ts

Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

@iscekic iscekic self-assigned this Sep 26, 2026
@iscekic

iscekic commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

bot: Fixed failing checks in d036745.

@iscekic iscekic added the human-ready The PR is ready for human review. label Sep 26, 2026
@iscekic iscekic added merge-by-human the merge bot routed this PR to a human merge-by-bot and removed human-ready The PR is ready for human review. merge-by-human the merge bot routed this PR to a human labels Sep 26, 2026
@iscekic
iscekic marked this pull request as draft September 28, 2026 08:41
@iscekic
iscekic marked this pull request as ready for review September 28, 2026 08:45
@iscekic
iscekic marked this pull request as draft September 28, 2026 08:53
@iscekic
iscekic marked this pull request as ready for review September 28, 2026 09:02
@iscekic
iscekic marked this pull request as draft September 28, 2026 09:18
@iscekic
iscekic marked this pull request as ready for review September 28, 2026 09:30
@iscekic
iscekic merged commit 8b5ea58 into main Sep 28, 2026
29 checks passed
@iscekic
iscekic deleted the kwf/janitor-mobile-agents-search-99b89f0c7e branch September 28, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kwf-janitor Admitted to the workflow from a janitor finding merge-by-bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants