labs
한국어 hello@taklabs.dev

Why a home widget Done took 4 seconds: the LiveActivityIntent 3-second wait

The 3-second stall after tapping Done on the home widget was the system waiting for a Live Activity session, because `CompleteHabitIntent` is a `LiveActivityIntent`. I moved the home widget's Done into the widget extension as a plain `AppIntent` and wrapped every store write in `NSFileCoordinator`, since the app and the widget now write to the same file.

Curlet is an iOS app where a pet reacts when you keep up your habits. The home screen widget has a Done button, and after you tap it the button shimmers for 3.5 to four seconds before the pet and its line finally change. In the previous PR (#18) I tried reloading the widget sooner, and the delay stayed. This post covers the second attempt, PR #19.

Where was the time going?

For #18 I had no device log, so I read the code and guessed that perform was slow because it only reloaded the widget after the card and reminder syncs finished. This time I started from a log taken on a real iPhone 13 Pro. From the tap to the end of perform took 0.47 seconds, so the time was lost after that:

38.345 Starting timeout timer (3.000000 seconds), we're still waiting on the target to take the assertion
41.310 Assertion hit the timeout
41.321 chronod  Resuming reloads

Once perform returned, the system started a 3-second timer and let widget reloads resume only when it expired. CompleteHabitIntent is a LiveActivityIntent, so the system expected it to start a Live Activity session and waited for one that never came. The wait begins after perform finishes, which is why pulling the reload earlier on the app side, as #18 did, could not help.

tap Done run CompleteHabitIntent perform done in 0.47 s start 3 s timer, wait for Live Activity session timer expires, resume reloads Widget System App process

What did I change?

I made the home widget's Done a plain AppIntent that runs inside the widget extension, which removes both the 3-second wait and the app launch.

  • A new WidgetCompleteHabitIntent lives only in the widget target (isDiscoverable = false). If the App Group is missing it does not save, since writing to a folder the app can't read would be pointless. After saving it calls WidgetReload.pet() so the lock screen widget redraws too.
  • The choice of which habit the button points at moved into completeFromButton(habitID:on:), so both intents share one rule.
  • The existing CompleteHabitIntent now serves only the places where a real Live Activity exists: the morning card and the body-double card.

I could have put the new intent in both the app target and the widget target, but then the system would decide which process runs it. I wanted the widget extension to be the one place it runs, so it lives only in the widget target.

What breaks when the app and the widget write the same file?

Until now the design was that the app writes and the widget only reads, and the README said so. After this change both the app and the widget extension write curlet.json. I moved the read-modify-write in CurletStore's update, write, importFile and restoreBackup inside an NSFileCoordinator write block (.forMerging), so writes from the two processes are serialized. Inside the block, encode writes directly instead of going through the coordinator again, because nested coordinator calls deadlock.

I wrote the test first: twoStoresWritingAtOnceLoseNothing, where two stores take turns doing 40 update calls. Before the coordinator went in, it failed three times out of three runs:

Expectation failed: try await app.load().morningActivityDays == Set(days)

One side's write overwrote the other's and data disappeared. That becomes a real bug the moment the widget extension is a writer, and with the coordinator in place the test passed. The widget Done rule got the same treatment: three tests (the named habit; a button with no habit picks the first undone one; a deleted habit changes nothing) failed first, then I implemented it.

What did I leave out?

If you tap Done on the home widget during a body-double session that has crossed midnight, it counts for today, not yesterday. BodyDoublePolicy.completionDay would normally return yesterday there, but the widget extension has no reliable way to read the Live Activity list and the case is rare, so I settled on today.

The Done button on the Live Activity cards (the morning card and body-double) may hit the same 3-second wait. Dismissing those cards needs the app process, so this PR leaves them alone. Also, after a widget Done, the morning card and reminders only catch up the next time the app launches. Until then a card may still show Done for a habit that is already completed, and tapping it returns .already and changes nothing.

How did I check it?

Before merging I ran the review, simplify and ship skills once each, and all four acceptance criteria passed. just ios-test passed 4 + 252 + 21, the Debug build had zero warnings, and the Release build succeeded. The work spanned five sessions, and most of the roughly $7 went to Opus.

perform system wait 0 0.5 1 1.5 2 2.5 3 3.5 4 seconds Time after tapping Done (seconds)

At PR time I left the real-device check on the checklist as a task for me, and did it myself later. With the app closed on the 13 Pro, tapping the home widget Done now changes it within one second. The 3-second wait is gone.

If a widget intent feels slow, look in the log for what the system waits on after perform returns before you trim the work inside perform. #18 trimmed first and missed, while #19 found the wait in three timestamped log lines. Checking in that order would have saved me a PR.

Build stats

ModelInputOutputCache readCache writeUSD
claude-opus-5-526667,56117,602,117343,791$7.17
claude-sonnet-5-5226,886204,71466,163$0.25
Total28874,44717,806,831409,954$7.42
claude-opus-5-518,013,735claude-sonnet-5-5277,785
Tokens by model
03-review1harvest1review1ship1simplify1
Skill calls

Counted from 5 session transcripts at 2026-11-14T02:18Z (PR #19, sessions 2026-11-10 to 2026-11-10). Tokens include subagents; USD is list price. Code: +165 / −32 lines.