App Sync Workflow
Purpose
Design, implement, test, or diagnose server-side sync behavior without mixing the sync contract into unrelated routing, persistence, OpenAPI, RPC, auth, or background-job work.
The practical decision is how clients and the server agree on state over time: what changed, what the client has already seen, how writes avoid duplication, how conflicts are detected, how deletions are represented, and how both sides recover after retries, offline edits, or partial failure.
When To Use
- Use this skill when adding or changing incremental sync endpoints, change feeds, cursor or token semantics, idempotent writes, conflict handling, optimistic concurrency, tombstones, deleted-record feeds, client checkpointing, sync-related background jobs, or API contracts for app state synchronization.
- Use this skill when diagnosing duplicated writes, missed changes, stale cursors, conflict loops, wrong-owner sync data, deleted records reappearing, retry bugs, out-of-order changes, pagination drift, or partial sync failures.
- Use this skill when a Vapor or Hummingbird service needs a sync contract for an Apple app, web app, CLI, or another service.
- Use this skill when deciding whether sync should be ordinary HTTP routes, OpenAPI-backed endpoints, JSON-RPC, gRPC, server-sent events, WebSockets, polling, or background jobs.
- Do not use this skill for ordinary CRUD routes, database migrations, generated OpenAPI plumbing, auth, observability, Docker, Fly.io, or local SwiftPM work unless sync semantics are the reason for the change.
- Do not absorb client-side storage or Apple-platform background task behavior. Hand client persistence and app scheduling to Apple-platform skills.
Source Check
Use repo-local Swift files, checked-out dependency sources, Dash MCP or Dash HTTP for installed Swift package DocC, and then official docs or source when Dash/local coverage is missing or stale. Check one of those source-specific paths before claiming framework, protocol, or HTTP behavior:
Use OpenAPI, RPC, persistence, auth, observability, deployment, or Apple-platform docs when the sync design depends on generated contracts, transport semantics, schema, identity, logging, background jobs, deployment guarantees, or client behavior.
Planning Workflow
- Inspect project shape:
Package.swift
- Vapor or Hummingbird route and middleware structure
- API contract files, generated code, or RPC definitions
- persistence models, migrations, indexes, timestamps, version fields, tombstones, and audit tables
- auth tenant/account ownership boundaries
- background jobs or queues
- tests for pagination, conflicts, retries, offline edits, and deleted records
- Identify the sync job:
- full initial snapshot
- incremental changes since cursor
- push local client changes
- reconcile conflicts
- propagate deletes
- enqueue expensive side effects
- stream or poll for updates
- Define the server-owned truth:
- stable object identity
- version or revision token
- ordering key for changes
- delete representation
- ownership and authorization scope
- retention window for change history
- Define client contract:
- cursor format and lifetime
- page size and ordering
- retry behavior
- idempotency key behavior
- conflict response shape
- when clients must restart a full sync
- Add tests that prove retry, conflict, pagination, deletion, and authorization behavior.
Contract Shape
Keep sync contracts boring and explicit.
Name:
- resource types included in the sync
- route or method used to fetch changes
- route or method used to submit writes
- cursor, token, timestamp, revision, or ETag fields
- ordering rule
- page size and next-page behavior
- conflict and validation errors
- deletion/tombstone representation
Do not expose database row order as the sync order unless it is intentionally stable, indexed, and documented.
Opaque cursors are usually safer than client-parsed cursors because the server can evolve internal ordering. If cursors expire, define the exact restart behavior.
Idempotent Writes And Retries
Assume clients, proxies, and background tasks may retry after timeouts or network loss.
For write APIs:
- use client-generated stable IDs or explicit idempotency keys when duplicate creation is a risk
- define whether repeated identical writes return the existing result or an error
- keep idempotency scope bounded by actor, resource, operation, and retention window
- make side effects such as emails, notifications, webhooks, or jobs idempotent too
- test retry after success-but-lost-response
Do not rely on clients "not retrying" as a correctness rule.
Conflict Handling
A conflict exists when a client writes based on state the server no longer accepts.
Use a clear mechanism:
- revision field
- ETag or conditional request
- updated-at version with documented precision limits
- server-side compare-and-swap
- domain-specific merge policy
Return conflict information that lets the client decide what to do next without leaking data from resources the actor cannot access.
Use 409 Conflict for domain conflicts and 412 Precondition Failed for failed HTTP preconditions when the API uses conditional request semantics. Keep the repository's existing status-code style when it already documents one.
Deletes And Tombstones
Deleted state must be syncable.
Decide:
- soft delete, tombstone table, audit log, or hard delete with change-feed record
- how long deleted records remain visible to sync
- whether deletes include actor, timestamp, reason, or version
- whether child records cascade, detach, or remain independently syncable
- what happens when a client updates a deleted record
Do not hard-delete records from sync history before all active clients can learn about the deletion unless the app has a full-resync fallback.
Background Work And Streams
Use background jobs when sync writes trigger expensive side effects that should not block the request.
Use streaming, WebSockets, or server-sent events only when polling or ordinary incremental sync is not enough. Streaming transports still need replay or catch-up behavior after disconnects.
Hand transport-specific decisions to openapi-rpc-workflow when the main question is API style, generated contracts, JSON-RPC, gRPC, MCP-style tools, WebSockets, or plain HTTP.
Use persistence-workflow when the main risk is schema, indexes, migrations, query performance, or transaction boundaries.
Auth, Privacy, And Observability
Every sync query and write must be scoped to the authenticated actor and tenant.
Test:
- actor only receives authorized records
- actor cannot advance a cursor into another tenant's data
- conflict responses do not leak private resource state
- deleted records remain scoped correctly
Use auth-authorization-workflow for identity and policy design.
Use observability-tracing-workflow for safe sync diagnostics, including cursor names, page counts, operation IDs, conflict counts, retry counts, and latency. Do not log raw cursors if they contain sensitive state.
Testing
Choose tests that prove sync correctness:
- initial empty sync
- initial full sync
- incremental sync after one change
- pagination with stable ordering
- retry of a successful write
- duplicate create attempt
- stale revision conflict
- delete propagation
- update after delete
- cursor expiration or retention-window miss
- unauthorized cross-tenant read and write
- background job idempotency if side effects are queued
Prefer deterministic fixtures with explicit clocks, IDs, and revision values when the repository's test setup allows it.
Handoffs
Use vapor-server-workflow or hummingbird-server-workflow for framework route, middleware, request context, and handler structure.
Use openapi-rpc-workflow when the sync API contract, generated types, or transport style is the primary work.
Use persistence-workflow for models, migrations, query design, transactions, indexes, and data-retention behavior.
Use auth-authorization-workflow for identity, tenant scoping, permissions, tokens, and session behavior.
Use observability-tracing-workflow for logs, metrics, traces, conflict counters, and privacy-safe diagnostics.
Use deployment skills when background workers, queue processes, or hosted runtime config must be deployed.
Output Shape
Return:
Sync shape: resources, routes or transport, cursor, ordering, idempotency, conflict model, delete model, jobs, auth scope, and tests.
Docs used: HTTP, Vapor, Hummingbird, OpenAPI/RPC, persistence, auth, observability, jobs, deployment, or Apple-platform docs consulted.
Behavior: fetch, write, retry, conflict, delete, pagination, retention, authorization, and background work.
Command path: exact build, test, migrate, run, job, or HTTP commands run or recommended.
Validation: tests, migration checks, manual HTTP checks, job checks, or diagnostic evidence.
Handoffs: framework, OpenAPI/RPC, persistence, auth, observability, background jobs, deployment, or client follow-up when the task crosses this skill's boundary.
Guardrails
- Do not design sync around unstable database row order.
- Do not rely on clients avoiding retries.
- Do not leak cross-tenant or private resource state through cursors, conflicts, logs, or deleted-record feeds.
- Do not hard-delete sync history without a documented full-resync fallback or retention decision.
- Do not turn sync into a custom transport when ordinary HTTP routes or existing OpenAPI/RPC guidance fits.
- Do not duplicate Apple-platform client storage or background-execution guidance in this server-side workflow.
1---2name: app-sync-workflow3description: Plan, implement, test, and diagnose app sync contracts in server-side Swift services, including incremental change feeds, cursor or token semantics, idempotent writes, conflict handling, optimistic concurrency, deleted-record/tombstone behavior, background job handoffs, API-shape coordination, and Vapor or Hummingbird integration.4license: Apache-2.05---67# App Sync Workflow89## Purpose1011Design, implement, test, or diagnose server-side sync behavior without mixing the sync contract into unrelated routing, persistence, OpenAPI, RPC, auth, or background-job work.1213The practical decision is how clients and the server agree on state over time: what changed, what the client has already seen, how writes avoid duplication, how conflicts are detected, how deletions are represented, and how both sides recover after retries, offline edits, or partial failure.1415## When To Use1617- Use this skill when adding or changing incremental sync endpoints, change feeds, cursor or token semantics, idempotent writes, conflict handling, optimistic concurrency, tombstones, deleted-record feeds, client checkpointing, sync-related background jobs, or API contracts for app state synchronization.18- Use this skill when diagnosing duplicated writes, missed changes, stale cursors, conflict loops, wrong-owner sync data, deleted records reappearing, retry bugs, out-of-order changes, pagination drift, or partial sync failures.19- Use this skill when a Vapor or Hummingbird service needs a sync contract for an Apple app, web app, CLI, or another service.20- Use this skill when deciding whether sync should be ordinary HTTP routes, OpenAPI-backed endpoints, JSON-RPC, gRPC, server-sent events, WebSockets, polling, or background jobs.21- Do not use this skill for ordinary CRUD routes, database migrations, generated OpenAPI plumbing, auth, observability, Docker, Fly.io, or local SwiftPM work unless sync semantics are the reason for the change.22- Do not absorb client-side storage or Apple-platform background task behavior. Hand client persistence and app scheduling to Apple-platform skills.2324## Source Check2526Use repo-local Swift files, checked-out dependency sources, Dash MCP or Dash HTTP for installed Swift package DocC, and then official docs or source when Dash/local coverage is missing or stale. Check one of those source-specific paths before claiming framework, protocol, or HTTP behavior:2728- [HTTP Semantics RFC 9110](https://httpwg.org/specs/rfc9110.html)29- [Vapor routing](https://docs.vapor.codes/basics/routing/)30- [Vapor validation](https://docs.vapor.codes/basics/validation/)31- [Vapor Fluent migrations](https://docs.vapor.codes/fluent/migration/)32- [Vapor queues](https://docs.vapor.codes/advanced/queues/)33- [Hummingbird documentation](https://docs.hummingbird.codes/)34- [Hummingbird Testing](https://docs.hummingbird.codes/2.0/documentation/hummingbird/testing/)35- [Swift Jobs](https://github.com/hummingbird-project/swift-jobs)3637Use OpenAPI, RPC, persistence, auth, observability, deployment, or Apple-platform docs when the sync design depends on generated contracts, transport semantics, schema, identity, logging, background jobs, deployment guarantees, or client behavior.3839## Planning Workflow40411. Inspect project shape:42 - `Package.swift`43 - Vapor or Hummingbird route and middleware structure44 - API contract files, generated code, or RPC definitions45 - persistence models, migrations, indexes, timestamps, version fields, tombstones, and audit tables46 - auth tenant/account ownership boundaries47 - background jobs or queues48 - tests for pagination, conflicts, retries, offline edits, and deleted records492. Identify the sync job:50 - full initial snapshot51 - incremental changes since cursor52 - push local client changes53 - reconcile conflicts54 - propagate deletes55 - enqueue expensive side effects56 - stream or poll for updates573. Define the server-owned truth:58 - stable object identity59 - version or revision token60 - ordering key for changes61 - delete representation62 - ownership and authorization scope63 - retention window for change history644. Define client contract:65 - cursor format and lifetime66 - page size and ordering67 - retry behavior68 - idempotency key behavior69 - conflict response shape70 - when clients must restart a full sync715. Add tests that prove retry, conflict, pagination, deletion, and authorization behavior.7273## Contract Shape7475Keep sync contracts boring and explicit.7677Name:7879- resource types included in the sync80- route or method used to fetch changes81- route or method used to submit writes82- cursor, token, timestamp, revision, or ETag fields83- ordering rule84- page size and next-page behavior85- conflict and validation errors86- deletion/tombstone representation8788Do not expose database row order as the sync order unless it is intentionally stable, indexed, and documented.8990Opaque cursors are usually safer than client-parsed cursors because the server can evolve internal ordering. If cursors expire, define the exact restart behavior.9192## Idempotent Writes And Retries9394Assume clients, proxies, and background tasks may retry after timeouts or network loss.9596For write APIs:9798- use client-generated stable IDs or explicit idempotency keys when duplicate creation is a risk99- define whether repeated identical writes return the existing result or an error100- keep idempotency scope bounded by actor, resource, operation, and retention window101- make side effects such as emails, notifications, webhooks, or jobs idempotent too102- test retry after success-but-lost-response103104Do not rely on clients "not retrying" as a correctness rule.105106## Conflict Handling107108A conflict exists when a client writes based on state the server no longer accepts.109110Use a clear mechanism:111112- revision field113- ETag or conditional request114- updated-at version with documented precision limits115- server-side compare-and-swap116- domain-specific merge policy117118Return conflict information that lets the client decide what to do next without leaking data from resources the actor cannot access.119120Use `409 Conflict` for domain conflicts and `412 Precondition Failed` for failed HTTP preconditions when the API uses conditional request semantics. Keep the repository's existing status-code style when it already documents one.121122## Deletes And Tombstones123124Deleted state must be syncable.125126Decide:127128- soft delete, tombstone table, audit log, or hard delete with change-feed record129- how long deleted records remain visible to sync130- whether deletes include actor, timestamp, reason, or version131- whether child records cascade, detach, or remain independently syncable132- what happens when a client updates a deleted record133134Do not hard-delete records from sync history before all active clients can learn about the deletion unless the app has a full-resync fallback.135136## Background Work And Streams137138Use background jobs when sync writes trigger expensive side effects that should not block the request.139140Use streaming, WebSockets, or server-sent events only when polling or ordinary incremental sync is not enough. Streaming transports still need replay or catch-up behavior after disconnects.141142Hand transport-specific decisions to `openapi-rpc-workflow` when the main question is API style, generated contracts, JSON-RPC, gRPC, MCP-style tools, WebSockets, or plain HTTP.143144Use `persistence-workflow` when the main risk is schema, indexes, migrations, query performance, or transaction boundaries.145146## Auth, Privacy, And Observability147148Every sync query and write must be scoped to the authenticated actor and tenant.149150Test:151152- actor only receives authorized records153- actor cannot advance a cursor into another tenant's data154- conflict responses do not leak private resource state155- deleted records remain scoped correctly156157Use `auth-authorization-workflow` for identity and policy design.158159Use `observability-tracing-workflow` for safe sync diagnostics, including cursor names, page counts, operation IDs, conflict counts, retry counts, and latency. Do not log raw cursors if they contain sensitive state.160161## Testing162163Choose tests that prove sync correctness:164165- initial empty sync166- initial full sync167- incremental sync after one change168- pagination with stable ordering169- retry of a successful write170- duplicate create attempt171- stale revision conflict172- delete propagation173- update after delete174- cursor expiration or retention-window miss175- unauthorized cross-tenant read and write176- background job idempotency if side effects are queued177178Prefer deterministic fixtures with explicit clocks, IDs, and revision values when the repository's test setup allows it.179180## Handoffs181182Use `vapor-server-workflow` or `hummingbird-server-workflow` for framework route, middleware, request context, and handler structure.183184Use `openapi-rpc-workflow` when the sync API contract, generated types, or transport style is the primary work.185186Use `persistence-workflow` for models, migrations, query design, transactions, indexes, and data-retention behavior.187188Use `auth-authorization-workflow` for identity, tenant scoping, permissions, tokens, and session behavior.189190Use `observability-tracing-workflow` for logs, metrics, traces, conflict counters, and privacy-safe diagnostics.191192Use deployment skills when background workers, queue processes, or hosted runtime config must be deployed.193194## Output Shape195196Return:1971981. `Sync shape`: resources, routes or transport, cursor, ordering, idempotency, conflict model, delete model, jobs, auth scope, and tests.1992. `Docs used`: HTTP, Vapor, Hummingbird, OpenAPI/RPC, persistence, auth, observability, jobs, deployment, or Apple-platform docs consulted.2003. `Behavior`: fetch, write, retry, conflict, delete, pagination, retention, authorization, and background work.2014. `Command path`: exact build, test, migrate, run, job, or HTTP commands run or recommended.2025. `Validation`: tests, migration checks, manual HTTP checks, job checks, or diagnostic evidence.2036. `Handoffs`: framework, OpenAPI/RPC, persistence, auth, observability, background jobs, deployment, or client follow-up when the task crosses this skill's boundary.204205## Guardrails206207- Do not design sync around unstable database row order.208- Do not rely on clients avoiding retries.209- Do not leak cross-tenant or private resource state through cursors, conflicts, logs, or deleted-record feeds.210- Do not hard-delete sync history without a documented full-resync fallback or retention decision.211- Do not turn sync into a custom transport when ordinary HTTP routes or existing OpenAPI/RPC guidance fits.212- Do not duplicate Apple-platform client storage or background-execution guidance in this server-side workflow.