Skip to content

fix(desktop): stop the shipped task prompt default from blocking sync hydration (#11481) - #11678

Merged
kodjima33 merged 4 commits into
BasedHardware:mainfrom
RatnamOjha:fix/task-prompt-default-sync
Aug 16, 2026
Merged

kodjima33 merged 4 commits into
BasedHardware:mainfrom
RatnamOjha:fix/task-prompt-default-sync

Conversation

@RatnamOjha

@RatnamOjha RatnamOjha commented Aug 16, 2026 •

Copy link
Copy Markdown
Collaborator

Issue summary

A task prompt customized on one Mac cannot reach another Mac that is still on the shipped default, and it can also come back after Reset to Default.

This fixes the client-side ownership rule behind both behaviors.

Why it happens

The oversized-prompt protection is intended to preserve user-authored text that could not be synced to the server. However, it cannot currently distinguish that from the shipped task default.

The shipped task default is 13,120 code points against a 10,000-character sync bound. On the first settings push, promptForSync therefore omits it from the PATCH and records unsyncedOversizedOwner.task.

applyRemotePrompt then sees an oversized prompt owned by the current user and refuses the remote prompt. Because the getter falls back to the shipped default when no custom prompt is stored, this affects fresh installs as well.

The fix

Both promptForSync and applyRemotePrompt now receive the assistant's shippedDefault explicitly and use it to distinguish shipped defaults from user-authored oversized prompts.

oversized + == shipped default  -> omit from sync, do NOT claim ownership
oversized + != shipped default  -> omit from sync, claim ownership (unchanged)

Remote hydration now preserves a local prompt only when it is oversized, owner-matched, and not the shipped default.

The default is passed explicitly at each call site rather than through an assistant-name → default dictionary, so the compiler forces every call site to provide the correct default.

Reset semantics

"Reset to Default" means this device has no custom local opinion, so account state may hydrate again.

This is important because the reset path clears the stored prompt and then writes the editor's default back through the setter, which re-establishes the ownership stamp.

Comparing against the shipped default survives that flow; checking only whether the stored key exists would not.

This behavior is covered by:

testRemoteHydrationAppliesAfterTheResetPathTheEditorPerforms

Relationship to #11580

Related to #11580; neither PR depends on the other.

#11580 addresses a separate backend contract mismatch between the desktop shipped task prompt and the backend validation bound.

This PR is entirely client-side and does not change the backend contract. The oversized shipped default is still omitted from the PATCH as before; this change ensures that omission does not cause the default to be treated as user-authored local state.

The two changes can therefore be reviewed and merged independently.

Verification

xcrun swift build -c debug --package-path Desktop
→ Build complete!

APIClientAssistantSettingsTests
→ 13 tests, 0 failures

SettingsSyncManager sibling suites
→ 39 tests, 0 failures

swiftlint-wrapper.sh lint
→ 0 violations across 1287 files

scripts/pr-preflight --base upstream/main
→ 21 checks passed

The three new regression tests fail against the pre-fix implementation and pass with the fix:

testShippedDefaultIsOmittedFromSyncWithoutBlockingLaterHydration
testRemoteHydrationAppliesAfterResetToDefault
testRemoteHydrationAppliesAfterTheResetPathTheEditorPerforms

The existing protection cases for genuinely oversized user-authored prompts also remain green and unchanged.

Refs: #11481
Failure-Class: none

Review in cubic

The oversized-prompt protection could not tell text the user wrote from text
every install ships, so it defended the shipped default as though it were
unsynced user data — and that defence blocks the account's real prompt forever.

The shipped task default is 13,120 code points against a 10,000 bound, so on the
first settings push `promptForSync` omits it (correct: it cannot be sent) and
stamps `unsyncedOversizedOwner.task`. `applyRemotePrompt` then sees "oversized and
owned by me" and refuses every remote prompt. A task prompt customised on one Mac
can therefore never hydrate onto a Mac still sitting on the default — which is
every fresh install, since the getter falls back to the default when nothing is
stored.

Both functions now take the assistant's `shippedDefault` and use it as the
discriminator:

  oversized + == shipped default  -> omit from sync, do NOT claim ownership
  oversized + != shipped default  -> omit from sync, claim ownership (unchanged)

and hydration preserves a local prompt only when it is oversized, owner-matched,
*and* not the shipped default.

The parameter is explicit rather than an assistant-name -> default dictionary so
the compiler forces all six call sites to name their default; a lookup table
would fail open — straight back to this bug — for an assistant nobody registered.
Passing it for insight and memory too means the same defect cannot reappear if
either default outgrows its bound; both are well under it today (3,576 and 6,262
code points).

Reset semantics, chosen deliberately: "Reset to Default" means this device has no
custom local opinion, so account state may hydrate again. That matters because the
reset path re-stamps ownership — `TaskPromptEditorView.resetToDefault()` clears the
stored prompt, then assigns the editor's `@State`, which fires `.onChange` and
writes the default straight back through the setter, calling
`recordLocalPromptOwner`. Comparing against the shipped default survives that; "is
the UserDefaults key set?" would not, because after a UI reset the key is present
and the stamp restored.

Client-only. It needs nothing from the backend: the oversized default is still
omitted from the PATCH exactly as before. It neither fixes nor depends on the
backend bound mismatch tracked in BasedHardware#11580.

Existing test call sites take the new argument; no assertion changed. The
`testEachAssistantPromptUsesItsBackendBound` table became a tuple array so the
per-assistant default is read without a force unwrap.

Verification:
  xcrun swift build -c debug --package-path Desktop   -> Build complete!
  xcrun swift test --filter APIClientAssistantSettingsTests -> 10 tests, 0 failures
  swiftlint-wrapper.sh lint                           -> 0 violations in 1287 files

Refs: BasedHardware#11481
Failure-Class: none
Three cases over the two decisions that were conflated: whether a prompt claims
unsynced ownership on push, and whether hydration may overwrite it on pull.

  fresh install on the shipped default   testShippedDefaultIsOmittedFromSyncWithout...
  reset to default                       testRemoteHydrationAppliesAfterResetToDefault
  reset as the editor performs it        testRemoteHydrationAppliesAfterTheResetPath...

Ownership is asserted through its observable consequence — whether a later pull is
allowed to hydrate — rather than by reading the bookkeeping key. That keeps these
tests on sync behaviour instead of internals, and avoids inline UserDefaults key
literals, which `omi_inline_userdefaults_key` rightly rejects.

The remaining matrix rows were already covered and are deliberately not duplicated:
a small custom prompt staying server-authoritative
(testRemoteHydrationRemainsServerAuthoritativeForSyncableTaskPrompt), an oversized
prompt owned by another account still being replaced
(testRemoteHydrationReplacesOversizedPromptOwnedByAnotherAccount), and a genuinely
user-authored oversized prompt staying protected
(testRemoteHydrationPreservesOversizedUnsyncedLocalTaskPrompt). Those three passed
before and after and were not touched — they are the guard proving the protection
was narrowed, not removed.

The editor-path case earns its place beside the direct reset because it exercises
the `.onChange` write that re-stamps ownership over the shipped default, which is
exactly why the discriminator has to be the prompt text rather than the presence
of the UserDefaults key.

Red baseline: with the two new conditions removed from SettingsSyncManager (the
`shippedDefault` parameter kept so the suite still compiles), these three fail and
the other ten pass:

  testShippedDefaultIsOmittedFromSyncWithoutBlockingLaterHydration
  testRemoteHydrationAppliesAfterResetToDefault
  testRemoteHydrationAppliesAfterTheResetPathTheEditorPerforms
  -> Executed 13 tests, with 3 failures

Each restores the stored prompt and auth owner, and runs under a distinct owner id
so it cannot inherit a stamp from a sibling test.

Verification:
  xcrun swift test --filter APIClientAssistantSettingsTests -> 13 tests, 0 failures

Refs: BasedHardware#11481
@RatnamOjha
RatnamOjha marked this pull request as ready for review August 16, 2026 13:20

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

… state

`withTaskPromptState` restored state in the wrong order. The `defer` assigned
`analysisPrompt = originalPrompt` before restoring `authUserId`, and the
`analysisPrompt` setter calls `SettingsSyncManager.recordLocalPromptOwner`, which
reads `currentOwnerID` — still the test's synthetic owner at that point.

Every test using the helper therefore left
`assistantPrompt.unsyncedOversizedOwner.task` pointing at "owner-fresh-install",
"owner-reset" or "owner-editor-reset" instead of the value it started with,
leaking into the app's real UserDefaults and into whichever test ran next.

Restoring `authUserId` first means the setter stamps the original owner, which is
the state the helper promised to put back.

Reported by cubic on BasedHardware#11678.

Verification:
  xcrun swift test --filter APIClientAssistantSettingsTests -> 13 tests, 0 failures

Refs: BasedHardware#11481
Failure-Class: none
Comparing against the current shipped default only recognises the default this
build ships. The reset path persists the default it saw, so once the app ships a
new one that stored text stops matching, is reclassified as user-authored, has
ownership claimed on the next push, and blocks the account's prompt again — the
same defect this PR set out to fix, resurfacing across a version boundary.

The classification is now recorded where it is actually known. Every write of a
prompt already computes `isCustom`, so `recordLocalPromptOwner` takes that answer
and persists it alongside the ownership stamp; `isShippedDefault` then treats a
prompt as shipped when the text matches *or* the marker says it did when written.
Writing a shipped default also releases any claim the previous value held, since
there is no longer unsynced user text to protect.

An absent marker means a build older than this one wrote the value, and the bool
default of `false` leaves those installs on the text comparison exactly as before
— the fallback is the previous behaviour, not a new one.

The parameter is required rather than defaulted so all three assistants state
their answer at the call site, matching the `shippedDefault` argument already
threaded through the sync seams.

Scope note: the marker is only consulted for the oversized path, which is where
ownership is claimed. Insight and memory ship well under the bound today, so this
changes nothing for them until a default grows past it — which is precisely the
case it exists to survive.

Red baseline — with only the marker consultation removed (text comparison alone,
so the change is isolated from the parameter plumbing):

  testPersistedPreviousShippedDefaultStillHydrates
  -> Executed 15 tests, with 1 failure

The test drives the real order: an older build's write, then this build's push —
the push is what re-claims ownership, so a version of the test that skipped it
passed either way and proved nothing. It failed to reproduce until that step was
added.

Reported by cubic on BasedHardware#11678.

Verification:
  xcrun swift test --filter APIClientAssistantSettingsTests -> 15 tests, 0 failures
  ... plus 3 sibling SettingsSyncManager suites            -> 41 tests, 0 failures
  swiftlint-wrapper.sh lint                                -> 0 violations, 1287 files

Refs: BasedHardware#11481
Failure-Class: none

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct client-side ownership rule: shipped oversized default no longer claims unsynced-owner and blocks remote prompt hydration (#11481). Tests + changelog included.

@kodjima33
kodjima33 merged commit abf87fa into BasedHardware:main Aug 16, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants