What this changes
Adds Settings > Daily Tasks to the Poki app: create, edit, and delete up to 20 independent daily schedules in local iPhone time, with optional public reminder names. Includes English, Simplified Chinese, and Traditional Chinese text.
- Foreground only: automatic starts require Poki to be in the foreground, unlocked, on, and idle. An unlocked Home Screen/another app, a locked phone, or a busy/suspended/terminated Poki gets a repeating notification instead. Opening Poki after a missed occurrence does not automatically run it; tap its reminder.
- Automatic approval floor: unattended runs use at least
.balanced(Balanced in the current UI, corresponding to the requested Moderate level). Never Ask becomes confirmation for the run; Permissive becomes Balanced; stricter preferences remain stricter. The core's rules and classifier both read this temporary floor. Saved preferences are not modified, and the floor stays until the running task unwinds, including cancellation. - Queueing and deduplication: all tasks due together while foreground/idle are queued before the first starts. Each start still requires the foreground and readiness gates. Notification taps wait in order and mark a request as manually started. The absolute due instant is atomically claimed before submission, preventing replay while allowing a later local occurrence after westward travel. Edits invalidate stale notifications and preserve the previous claim.
- Reminder lifecycle: ten-second grace for automatic submission, repeating fallback requests for future days, serialized correction when claims/edits race an add, authorization checks, and failed-add backoff (30, 60, 120 seconds ... up to an hour). Denied authorization is rechecked only once a minute.
- New task semantics: daily-task sends bypass continuation routing for
continue/继续instructions; ordinary chat sends retain their existing continuation behavior.
Chinese daily-task copy consistently uses 每日任务/每日任務 and 执行/執行. The notification budget is defined once in DailyTask.capacity. Removed the duplicate/misleading tests and the preview-only single-task format/migration. The README documents the behavior and signed-device checks.
A claim guarantees at-most-once submission of an occurrence, not completion or automatic recovery after interruption. iOS owns cold-launch reminders; tapping/authentication remains required after termination. No new background privileges, release/version/channel changes, preview workflows, installation helpers, or phone changes are included in this PR.
How you tested it
- Before/after regression: the original code failed a 20-task-budget check (actual 60) and rejected a second 09:00 occurrence after Tokyo → Los Angeles travel on the same calendar date. Both pass after the fix.
- Local checks: all 24 Foundation/UserNotifications/policy assertions pass against production source using a standalone assertion adapter, plus Swift parsing/type checks and
git diff --check. This Mac has only Command Line Tools. - Fork CI: run 44297041566 passed all 24 XCTest methods below in SwiftPM and the complete external iPhone build. That run then failed before Simulator tests started because the fork wrapper parsed a custom runtime identifier as numeric version components. The wrapper now uses runtime metadata; Simulator-only run 44299109119 passed all 30 selected app-hosted tests (24 above plus the six send-path/continuation/language checks below), with
TEST SUCCEEDED. The production logic is unchanged between these runs. The final follow-up only corrects two pending-task translations and an explanatory comment; catalog JSON/terminology checks pass. - Signed device: the earlier background-capable preview 0.4.5 (1685) was owner-tested, including notification execution. The foreground-only revision has CI coverage and has not yet been installed/re-tested on the owner's phone. OS notification delivery, lock-screen launch, and approval presentation remain the signed-device checks in
native/ios-app/README.md. - Upstream checks: pending maintainer approval for the fork contribution; see the current checks on this PR.
Test behavior and failure conditions
DailyTaskTests — persistent schedule/claim behavior:
testClaimIsPersistedBeforeSubmissionAndSurvivesReopening: prevents replay; fails if submission precedes the on-disk claim or reopening loses it.testOnlyLatestDueOccurrenceCanRunAndTomorrowCanRunAgain: protects late-tap expiry and daily recurrence; fails if an older occurrence or a duplicate runs, or tomorrow is blocked.testEditingOrCancellingRejectsAnAlreadyDeliveredNotification: protects stale revisions; fails if an old/deleted task's notification remains executable.testTwoSameTimeTasksWaitInTapOrderAndClaimIndependently: protects manual FIFO/independent claims; fails if a tap overwrites another task or claims leak between tasks.testEditingKeepsTheDueClaimAndRemovingLeavesOthersWaiting: protects an existing claim and another queued task; fails if a prompt edit replays it or deletion drops unrelated work.testAnEditInFlightCannotResurrectADeletedSchedule: protects deletion during save; fails if a stale editor can recreate the task.testAtCapacityEditingIsAllowedButAddingDoesNotReplaceAnyTask: protects the 20-task budget; fails if the cap changes, task 21 is accepted, editing is blocked, or existing data is overwritten.testPersistenceFailureDoesNotSubmit: protects the claim-before-effects boundary; fails if failed persistence still invokes submission.testWestwardTravelDoesNotSkipTheNextLocalDueInstant: protects Tokyo → Los Angeles recurrence across reopening; fails if the repeated calendar date blocks the later due instant or allows its duplicate.
DailyTaskSchedulerTests — the same scheduler used by the timer, with injected time, foreground, lock state, readiness, and submission:
testForegroundTickSubmitsOnceAndALaterTapCannotReplayIt: protects the automatic path's claim; fails if a later tick/tap submits it again or loses the automatic marker.testBackgroundDueTimeRequiresATapEvenAfterReturningToForeground: protects other-app/Home Screen use; fails if background or merely returning to Poki starts the missed task.testLockedOrUnknownLockStateCannotQueueAnAutomaticRun: protects the actual lock gate; fails if locked/unknown state queues a run, or unlocking backfills it.testBusyAtDueTimeLeavesTheOccurrenceForNotification: protects current work; fails if a busy tick queues/replaces it or stops offering the fallback.testTwoTasksDueTogetherQueueBeforeTheFirstMakesPokiBusy: protects same-minute automatic FIFO; fails if the second task requires a tap or starts while the first is busy.testColdStartAndLongSuspensionDoNotBackfillAutomaticRuns: protects missed occurrences; fails if initialization or a clock gap creates an automatic request.testTappedRequestWaitsForForegroundAndReadinessWithoutBecomingAutomatic: protects manually started work; fails if it runs in the background/while busy or incorrectly receives the automatic marker.testRestartingTheClockAfterAnIdlePeriodObservesTheNextCrossing: protects restarting the timer after no tasks; fails if an old cursor makes the next legitimate crossing look like suspension.
DailyTaskRemindersTests — the production reconciler/factory and real UNCalendarNotificationTrigger objects, with a fake notification center:
testRefreshRegistersARepeatingRequestAndSkipsTheClaimedOccurrence: protects request repetition, preview privacy, and grace-window correction; fails ifrepeatsis false, instructions leak, or the next calendar match is today rather than tomorrow after a claim. This checks configuration, not OS delivery.testDeniedAuthorizationDoesNotAddOrLogEveryTick: protects denied permissions; fails if 60 ticks repeatedly query/add/log rather than waiting, or registration cannot resume.testFailedAddsBackOffAndRecoverWithoutPerSecondLogs: protects retry/backoff; fails if attempts/logs exceed seconds 0/30 before 90, or recovery at 90 does not register the request.testClaimWhileAddIsInFlightCannotRestoreTodaysReminder: protects add/claim ordering; fails if the stale second-10 request wins over the corrected request.testDeletionWhileAddIsInFlightRemovesTheStaleRequest: protects add/delete ordering; fails if completing an add resurrects the deleted request.
AutomaticTaskApprovalsTests — the thread-safe transient policy consumed by the core/classifier:
testAutomaticFloorCannotDisableAskingOrWeakenAStrongerLevel: protects minimum safety without weakening stricter choices; fails if asking stays off or a stronger level is lowered.testEndingAnOlderRunCannotDropANewerRunsFloor: protects overlapping cancellation/unwind; fails if an old token clears a newer floor or the final token fails to restore normal choices.
ChatHarnessTests — real ChatModel.send with a local scripted model:
testDailyTaskContinuePrefixesReachTheModelAsNewTasks: protects both English/Chinese scheduled instructions; fails if they select saved-task continuation or never reach the model in a new conversation.testAutomaticSendKeepsApprovalFloorUntilCancellationWithoutChangingPreferences: protects send-path policy wiring/lifetime; fails if the running request sees Never Ask/Permissive, settings are overwritten, or cancellation leaks the floor.- Existing
testTimeQualifiedContinuationRequiresTheOwnersChoice: protects ordinary continuation selection; fails if the daily-task bypass accidentally changes normal chat routing. - Existing
testUnknownContinuationAsksBeforeStartingTheModel: protects unknown ordinary continuation; fails if normal chat starts the model rather than asking. - Existing
testAmbiguousContinuationWaitsForTheOwnersChoice: protects ambiguous ordinary continuation; fails if normal chat chooses a task without the owner.
LanguageTests:
-
testNotificationActionsRefreshWithLanguageWithoutChangingTheirMeaning: protects localized notification categories/actions; fails if Daily Tasks disappears on refresh, Traditional Chinese is wrong, or foreground/authentication requirements are dropped. -
I removed passcodes, tokens, and private screen contents from this PR.
-
I release this contribution under the AGPL-3.0-only license.
Activity
13Thanks for the careful work on this. The claim before submission, the stale notification checks and the lock screen gate all look right to us, and approvals still go through the normal send path, judging from reading the code. Before we merge, could you look at these:
- Tests. testClockLeavesLockedOccurrenceForNotificationInsteadOfRunningOnUnlock uses ready: false to stand in for a locked phone, but the lock check lives in checkClock and is never exercised. testOpeningPokiWithoutATapDoesNotQueueAnOccurrence never opens anything, and testReminderRemainsRepeatingWhileSuccessfulOccurrenceIsSuppressed checks only reminderSecond, not that the request repeats or that today's reminder is suppressed. Please either drive the real path (for example by injecting the lock state and clock into the scheduler) or rename these to what they prove. testForegroundCanSubmitAndTapDoesNotReplayIt repeats what the cold launch test already proves. The single task format and its migration test seem to exist only in your fork's previews; if nothing upstream ever wrote that format, they can go. For each remaining test, a line in the PR body saying which behavior it protects and which regression would make it fail would help.
- Notification budget. iOS keeps only the 64 soonest notifications, and we plan more scheduled local notifications soon (suggestions and to-do reminders). Please cap daily tasks at 20 and keep the cap in one constant.
- Starting while someone is using another app. If the phone is unlocked but the user is in another app, please send the notification instead of taking over the screen. Auto start only when Poki is already in the foreground and idle. A run that nobody started by hand should also use at least the Moderate approval level, even if the user picked Relaxed.
- Retry loop. If adding a reminder fails, for example after notifications are turned off, refreshReminders retries every second and logs a line each time. Please back off or check authorization first.
- Wording. Simplified Chinese mixes 每日任务 and 定时任务, and Traditional Chinese mixes 每日任務 and 排程任務. The rest of the app says 执行任务 for running a task. Please use 每日任务 and 执行 throughout.
- Smaller points. When two tasks are due in the same minute, the second waits for a tap instead of queueing. A prompt that starts with 继续 or continue goes through task continuation. Travelling west skips a day because the claim stores a calendar day rather than the due time.
Daily tasks are a feature we really want, so thanks again for building it.
Thanks for the detailed review. I agree with your suggestions, including foreground-only automatic execution and at least Moderate approvals for automatic runs. I will address all six points: make the tests match the real behavior, cap daily tasks at 20, fix reminder retry behavior, unify the wording, and cover the queueing, continuation, and time-zone cases. I will follow up with the changes and a per-test explanation of the behavior and regression each test protects.
Implemented the six review changes in dcbe0ff4, with final wording/comment cleanup in 2fefbc66, and updated the PR description:
- Tests: the timer now uses
DailyTaskSchedulerwith injected time, foreground, lock state, and readiness. The notification reconciler accepts a test center but constructs real repeatingUNCalendarNotificationTriggerrequests. Removed the duplicate/overstated tests and the preview-only single-task migration. The PR body has a behavior + failure-condition line for every remaining relevant test. - Budget:
DailyTask.capacityis the single 20-task limit used by saving and the UI. - Starting/safety: automatic requests are queued only in the foreground while unlocked and idle; queued automatic starts also require the foreground gate. Home Screen/other-app use follows the notification path. Automatic sends apply a transient Balanced-or-stricter floor (
.balanced, the current code's Moderate equivalent) to both core rules and classifier decisions, even with Never Ask/Permissive saved. Saved preferences remain untouched; cancellation/unwind releases the floor. - Retry: authorization denial is checked at most once per minute. Failed adds back off 30/60/120 seconds up to an hour, logging only a failed attempt. In-flight claims/deletions are reconciled serially.
- Copy: the added Chinese entries consistently use 每日任务/每日任務 and 执行/執行, including the pending-task footer and notification action.
- Edge cases: the entire same-minute batch queues before starting its first task; scheduled instructions bypass continuation while normal chat keeps it; persistent claims now store absolute due instants, with a Tokyo-to-Los-Angeles same-date regression test.
Validation: 24 XCTest methods and the full external iPhone build passed in 44297041566. That run stopped before Simulator tests because the fork's runtime selector could not parse a custom runtime suffix. The selector now uses runtime metadata; Simulator-only verification 44299109119 passed all 30 selected XCTest methods, including the real send-path checks, existing continuation controls, and notification-action localization/authentication assertions (TEST SUCCEEDED). Final translation JSON/terminology checks also pass. The earlier owner-tested 1685 device build predates this revision; the foreground-only revision has not been installed on that phone.
The current upstream PR checks and iOS Duo are awaiting maintainer approval. Could you approve their run when convenient? Thanks again for the detailed review.
Thanks, @KKtwo. Your agreement to the Poki Contributor Agreement (version 1) is on record and covers your later pull requests too. 已记录你的同意,之后的 pull request 不会再询问。
I agree to the Poki Contributor Agreement
Thanks @KKtwo for working through the earlier review. We read the approval floor for automatic runs: it raises Never Ask and Permissive to at least Balanced only while an automatic run is active, and leaves the saved preference unchanged. That part looks right to us.
One thing blocks merging now: after recent merges the branch conflicts with main in three files.
native/ios-app/Poki/Chat/PokiDetailsView.swift: the Settings list changed (the Signing & Updates page was restyled and a Screen History entry was added). Please keep both, with Daily Tasks added to the new layout.native/ios-app/Poki/Runtime/LiveCore.swift: the Screen History tool was wired in next to the approval-mode line. When you resolve it, please keepconfig.approvalMode = { ApprovalClassifier.effectiveMode }so the floor for automatic runs still applies.native/ios-app/Shared/Localizable.xcstrings: both sides added strings, so keep both sets.
These look mechanical, so a merge or rebase of main should be enough. Please comment here when it's updated, and we'll take another look.
Thanks for working through the scheduling and approval feedback. Please rebase the three conflicting files. Returning just after the due time can still start a missed task without a tap. Please cover that short background interval and preserve existing schedules if their file cannot be read.
Thanks for this, scheduled daily tasks are a great fit for Poki. We are reviewing it now and will come back with feedback soon.