Skip to content

fix: align Apple clients with the current server contract - #13

Merged
cheetahbyte merged 5 commits into
mainfrom
fix/server-contract-alignment
Nov 15, 2026
Merged

cheetahbyte merged 5 commits into
mainfrom
fix/server-contract-alignment

Conversation

@lauragarden

@lauragarden lauragarden commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Align the macOS and iOS clients with the current bot contract (server main at 49f32d1), matching crumble-project/android#17. Copy bot/openapi into apfelkern/Contract and regenerate the client.

  • Upload raw file bytes into the bot or group library, then send file IDs instead of inline attachments. Read transcript file metadata, download by file ID, and show deleted-file placeholders. Retries reuse completed uploads within the same chat, connection, and request; a deleted or missing library file causes the next retry to upload again.
  • Consume server schedule timing and previews, reasoning previews, citation presentation, chat working state, and job-history items. Remove the local interpreters these projections replace; retain the recurrence builder that writes cron expressions.
  • Replace installation-linked push presence with independent chat attention and exact reply acknowledgements on both apps. Report only mounted, active chats, and acknowledge ready reply surfaces in the viewport.
  • Keep newer job-history results when loads finish out of order, preserve the newest page when an older-page refresh fails, and avoid starving slow history loads with repeated polling.
  • Allow edits to completed one-time automations when the trigger is unchanged. Preserve the saved timestamp so editing cannot accidentally schedule another run.
  • Check that snapshot schema definitions match OpenAPI components before sharing generated types.
flowchart LR
  View["Mounted, active chat"] --> CA["ChatAttention"]
  Surface["Visible reply text or ready card"] -- replyReferences --> CA
  CA -- "Serialized view reports and seen batches" --> Server[(Server)]
Loading

Why

The server no longer accepts inline attachments and has removed the group attachment route and installation-linked push presence. It suppresses pushes account-wide when a matching chat is active or its reply has been seen. The native clients need to report that attention and consume the server projections instead of duplicating their interpretation.

Evidence

  • python3 apfelkern/scripts/contract.py --check: generated output matches byte-for-byte.
  • apfelkern swift build and swift test --no-parallel: 329 shared tests and 5 BotAvatar tests passed.
  • BotAvatar unsigned iOS Simulator build passed.
  • macOS swift test: 114 tests passed. scripts/check-app-bundle.sh passed.
  • Unsigned iOS app and test-target build passed. All 112 unit tests passed on iPhone 18 Pro Simulator, iOS 27.0.
  • SwiftLint passed in all three projects, with existing warnings and no errors.
  • All six CI checks passed for ef59bdb. The existing aRefreshInFlightCollapsesBehindTheClearAndTheHeartbeatStopsWithIt test failed once in the push run and passed on one rerun; the simultaneous pull-request run and a focused local run also passed. Its timing sensitivity remains unresolved.
  • Existing CI jobs exceed the two-minute unit-test-job target: macOS took 4m52s, and the apfelkern jobs took 7m41s and 7m15s. Workflows were not changed.
  • Regression tests failed before their fixes and passed afterward:
    • An unchanged completed automation trigger no longer blocks a rename. A changed past trigger still blocks saving, and the original fractional-second timestamp is preserved.
    • Delayed newest-page and older-page history loads finish while polling continues. Explicit newer loads still supersede older ones.
    • The original history regressions cover out-of-order results and failed older-page refreshes.
  • Existing file tests cover upload bytes and headers, file IDs in sends, partial failures and retries, reupload after deleted-file rejection, deleted-file download suppression, late downloads, and connection changes.
  • Existing attention tests cover mount/activity gates, bot versus group identity, serialized clears, connection identity rotation, batching and retries, rejected-batch splitting, session termination, surface readiness, and viewport checks.
  • A separate static review found no further issues in the two follow-up fixes. This was not a live UI review.

The standard iOS build and unit-test scripts failed locally with missing-type diagnostics despite those types being present in source. Equivalent Xcode commands passed using fresh derived data at ios/build/verify-pr13; existing build data was not deleted. The cause of the default-output failures remains unverified.

Not verified against a live server or interactively: viewport geometry under real toolbars, keyboard, and covering sheets; macOS appearsActive; and account-wide suppression of an iPhone push while a Mac shows the chat. A potential sheet-occlusion issue remains unconfirmed. UI tests were not run.

Risk & Rollback

Reversibility: Reversible, with no persisted-data migration. Reverting restores behavior that does not work with the current file and attention APIs. Accepted seen acknowledgements are not undone.

Blast Radius: Shared transport and models, both apps' bot and group chats, automation editors, reasoning controls, job history, iOS push presence, and macOS window lifecycle. Push registration, notification settings, payloads, and tap routing are unchanged.

Intentional differences from Android:

  • Saving automations and bots is not blocked by a failed preview. A schedule preview problem blocks a new or changed trigger, not an unchanged saved trigger.
  • A failed group send still restores its text to an empty composer.
  • The viewport check excludes toolbar and composer areas.
  • Job-question and group cards are not acknowledged.

Clearing a view is best-effort and bounded to two seconds. A lost clear expires after the server's 120-second presence TTL. Uploads from failed sends can remain in the server Library.

The server dropped inline base64 attachments. Messages now carry `files`,
IDs from a file library that clients upload raw bytes into first, and
transcripts list file metadata, including markers for deleted files,
instead of `attachments`. The group attachment route by entry and index is
gone, and so is push presence.

Update the contract copy to server main. `contract.py` now points the
event schemas' `$defs` at the shared OpenAPI components after checking
they match, and Generated is regenerated from it.

Bot and group sends upload each attachment before sending its file ID,
keeping optimistic rows, drafts, reply targets, and local image previews.
Each pending send keeps the IDs it uploaded, so a retry under the same
request ID uploads only what an earlier attempt missed. A server rejection
for a deleted or missing library file drops those IDs, and the next retry
uploads again from the retained bytes. Uploads stop when the connection
changes and never move between chats or connections.

Transcript file IDs drive downloads and the image cache, scoped by chat
and cleared on a new connection. Previews follow the MIME type. A file
deleted from its library shows a placeholder in every message that lists
it, is never fetched, and a download that finishes after the deletion is
dropped. Desktop screenshots still load by entry and index.

To compile against the new contract, `pushPresence` and its iOS call are
removed, leaving presence unreported until chat attention replaces it, and
job history reads the transcript page inside the new history response.
Test fixtures gain the newly required `replyReferences`, `working`,
`items`, and schedule label fields.
…projections

The server now projects what the apps used to compute locally, and the
Android client already reads these projections. Read them here too and
delete the local logic they replace.

Automations: `Schedule` carries the server's `description`, `timing`,
and `nextRunLabel`, which the list, the bot details, and the rows show.
The local cron phrases, next-run labels, cron parser, and next-run
calculation are gone. The editor asks `POST /v1/schedules/preview` for
the draft's trigger. A request waits 250 ms for the trigger to settle,
and SwiftUI cancels it when the trigger changes. An answer for an older
trigger, another draft, or another connection is dropped. A preview
problem disables Save. If no preview is available, because it is still
loading or the request failed, saving still works and the server checks
the trigger. The draft therefore no longer checks the trigger or the time
zone itself. The recurrence builder stays because it writes the cron.
Optimistic rows read "Saving…" until the server answers, and a paused
row says so at once. The list rereads every minute while it is shown, as
on Android, so the relative next-run labels stay current.

Reasoning: the composer control and the bot form use
`POST /v1/reasoning/preview` for the offered levels, their labels, and
the level a turn runs at. These replace the local clamping and the reads
of the model list. Previews are cached per connection. They load after
the same short wait, and a cancelled or failed request shows no control.
A level that the server already offered for the same model shows as
itself until its own preview arrives, so picking a level doesn't hide
the control.

Chat: replies show the server's `presentation` text and citations. The
local citation parsing and per-turn source collection are gone, and so
are group `sources`. `ChatSnapshot.working` replaces inferring the work
state from the transcript. `isRunning` follows it, as on Android.
`Message.blocks` is the generated `TranscriptBlock` array, which HTTP
and the event stream share.

Jobs: history pages carry the server's task, reply, and step items. They
replace deriving steps from the transcript, and their labels and icons
come from the server. The server attaches a step's result to the page
that holds its call. So a refresh rereads older pages for loaded steps
that are still unfinished, as Android does. Transcript downloads still
use the raw messages.
The server now suppresses a push account-wide when any fresh view shows
the reply's chat, and skips one the owner has already seen. Pass 1
removed the installation-linked presence endpoint, so neither app told
the server anything. Port the Android design to both apps.

apfelkern gains ChatAttention, a testable controller independent of
push registration and notification permission. It reports one view's
bot or group chat through PUT /v1/chat-attention/views/{viewId} only
while the app or window is active, the route shows that chat, and the
chat's view is mounted. Reports go out one at a time with the newest
state, so a pending heartbeat refresh collapses and can't land after a
clear; it refreshes every 30 seconds. Each connection gets a new view
ID and the old view clears through the old session, and disconnect
clears within two seconds before sign-out revokes the session.

Seen acknowledgements use the server's replyReferences, now kept on
Message from HTTP and both event streams. A surface counts only when it
is the exact one referenced, ready, and inside the uncovered part of
the chat's scroll view while the chat has attention: nonempty reply
text without its citations, or a held action, bot request, call
request, or credential or login card whose board has the server's
state. Fetched or streamed history never counts on its own. Batches of
up to 100 per chat keep their chat across navigation, retry with
bounded backoff while the connection lasts, split a refused batch so
only refused events are dropped, and stop when the session ends.

A live reply for the chat on screen reloads its newest page, so
references that trail the event arrive. The reload is dropped when a
snapshot, a newer reload, a new selection, or a new connection lands
first, and the merge keeps drafts and sends in flight.

Both apps report: macOS while the main window appears active, since a
Mac showing the chat should stop the iPhone's push, and iOS while its
scene is active, with a short background grace so the clear can land.
Each app has a single chat window or scene, so one view per process.
The iOS push controller keeps its foreground registration retry as
setForeground(_:); push registration, notification settings, local
delivery, payloads, and tap routing are unchanged.
Overlapping history loads (the watch poll, a status change, opening the
job) applied in the order they finished, and mergeJobItems keeps existing
items only up to the arriving page's first ID, so an older load that
landed late cut items a newer one had added and could put back an
unfinished copy of a finished step. Only the newest load now applies.

A failed request for an older page while re-reading unfinished steps
also threw away the newest page and showed an error. The search now
stops there and keeps the steps it found.
@lauragarden lauragarden self-assigned this Nov 15, 2026
Allow saving an existing automation when its trigger is unchanged, keeping its original timestamp so completed runs stay completed. Share the preview gate with both apps.

Skip redundant polling history loads while the latest load is pending, without blocking job status refreshes or explicit newer loads. Add regression coverage for both failures.
@cheetahbyte
cheetahbyte merged commit 42e2061 into main Nov 15, 2026
6 of 7 checks passed
@cheetahbyte
cheetahbyte deleted the fix/server-contract-alignment branch November 15, 2026 12:46
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