Skip to content

refactor(macos): keep unsent Team Library edits in memory and switch sign-ins in process - #4473

Merged
datlechin merged 14 commits into
feat/core-account-company-serverfrom
feat/macos-team-library-sessions
Nov 24, 2026
Merged

datlechin merged 14 commits into
feat/core-account-company-serverfrom
feat/macos-team-library-sessions

Conversation

@datlechin

@datlechin datlechin commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Stacked on #4470, after #4471 (merged into its branch). Team Library keeps no unsent edit on disk, so a switch of sign-in stays in process. The invariants, kept once here and on TeamLibrarySync:

  • I1. Unsent edits (pushes still to go, conflicts not resolved) live only in memory, for the open session. Nothing about them is written to disk.

  • I2. The read cache sits in TeamLibraryCache/<digest of server and account>/. Only the open session's folder is read; every other one is deleted, best-effort, on sign-out, switch and launch. No owner record, no marker, no adoption.

  • I3. The library 0.88 and earlier kept (TeamLibrary/, team_library.json) is read once: a flag (com.TablePro.teamLibrary.earlierLibraryConsidered) is written, synchronized and read back first; if it does not stick nothing is read and the store is deleted. Once set, the store is only ever deleted, never read. On that launch, for the tablepro.app sign-in the core restored only, its cache is copied into that account's folder and its files are deleted. Its unsent edits are uploaded once, automatically, under that session's bearer, outside the sync queue and with no hold; what is refused or conflicts is listed once in a notice that never blocks, and dropped. Ending the session cancels the upload, and the close lists what it had not sent. Any other sign-in, with or without an entitlement, and choosing a company server, signed in or not, set the flag and delete the store unread at that moment.

  • I4. A switch or sign-out stays in process, in two steps.

    • End the session: the moment the account reports a sign-out of any kind, another account or server, or a lost team_library, the session ends for good, synchronously on the main actor. Nothing of it shows any more (library, Welcome, Favorites, publish menus), its unsent edits are listed as discarded, and no result of it is recorded or shown after any await: sync, the 0.88 upload, publish and resolve re-check their session after every await. A returning team_library opens a new session; the old one is never revived.
    • Drop the store: each session has its own store object. The ended one's folder is deleted after the pass in flight drains, never the next session's, and the next session opens without waiting for it.
    • Sign Out and quit first stop sync, wait for the pass in flight and ask push, discard or cancel; the 0.88 upload finishes before that, outside the hold. An edit the server refuses stays listed as unsent with why until it is discarded, or until a later publish of the same item is accepted, or the team turns out to hold it as sent: the latest wins. The core's session id lives only in its process and is read with the status from one snapshot; the bearer middleware refuses a token of another session; a publish is bound to the session shown at its confirmation and checked again before it is sent.
  • I5. Quitting with unsent edits asks Upload, Discard or Cancel. Discard drops them only in applicationWillTerminate, so a later quit step that fails keeps them. While edits wait, the Team Library header shows them as not uploaded; the count covers pending edits, conflicts and refused edits, and follows every change.

  • I6. Losing team_library ends the session as an involuntary sign-out does, and lists what it discarded.

  • I7. Until the restore settles, a sign-in, a server choice or a license key waits, and a restored sign-in refuses them (AccountError.signOutFirst).

  • Holds: a sign-out and a quit each take a TeamLibraryHold and release it on every path. Sign Out is one flow (AccountSettingsModel.signOut()) that owns its hold and asks with an NSAlert that does not depend on the Settings window; an involuntary sign-out while it asks closes the question, and one during the upload ends the flow, with the discard listed once by the session's close.

  • The core carries the session id inside SignedIn, so AccountStatusInfo reads it from the same status snapshot; the separate channel and Account::session_id() are gone. The restore mark is read before that snapshot.

  • Removed: the relaunch on sign-out, the delete marker, the owner record, the connection-editor move, and the per-file owner feat(macos): sign in through the core, with a company server option #4471 added.

  • A store file that development builds of the account move wrote names its owner; the migration reads it only for that owner, rejects an owner that is null or malformed, reads each file once, and deletes any other unread.

  • C# bindings regenerated for the session id; the Linux app's test statuses gain the new SignedIn field.

Stable blockers

  • A delayed 401 retry in the bearer middleware can resend a push after its session ended, when team_library is lost and regained within the request: the retry checks only the core session id, which survives the flap.

Follow-ups

  • Keep a fingerprint of a Keep Theirs choice across launches, so a later publish of the unchanged local copy does not overwrite the team's version (the copy itself stays off disk).
  • Bind a confirmed publish to the store's lifetime, not only the core session id, so a confirmation open across a team_library flap does not go out under the new store.
  • Track accepted batches of the one-time 0.88 upload in the store, so a sign-out during a multi-batch upload does not list them as discarded.

Test plan

  • Rust: each_sign_in_has_its_own_session_id_which_every_bearer_carries_and_a_sign_out_ends, each_launch_restores_the_sign_in_under_a_session_id_of_its_own_that_no_file_keeps; the FFI status tests assert the id.
  • Swift new: unsentEditsStayInMemory, eachAccountReadsOnlyItsFolder, restoredCompanySignInReadsItsCache, noSignInAtLaunchLoadsNothing, earlierLibraryIsUploadedOnce, earlierUploadEndsWithTheSession, ownedEarlierStoreIsReadOnlyForItsOwner, unsavedFlagReadsNothing, signInWithoutEntitlementDiscardsTheEarlierLibrary, consideredEarlierLibraryIsNeverReadAgain, lostFeatureClosesTheSession, earlierLibraryNeverReachesAnotherSignIn, involuntarySignOutDiscards, signOutWaitsForThePushInFlight, holdWaitsForThePassThatIsOut, quitAsksAboutUnsentEdits, stoppedQuitReleasesTheHold, failedUploadAtQuitAsksAgain, refusedEditStaysUnsent, switchingWhileSignedInIsRefused, anotherSignInsBearerIsRefused, queuedPublishIsRefusedAfterTheSignInEnds, AccountServicesTests.switchingWaitsForTheRestore, AccountSettingsModelTests.uploadThenSignOut, discardThenSignOut, involuntarySignOutClosesTheQuestion, involuntarySignOutDuringUpload, signOutWithoutASessionReleasesTheHold.
  • Changed on purpose:
    • TeamLibrarySyncTests.serverErrorQueuesThePush: the queued edits stay in memory, so no relaunch between the failure and the push.
    • keepTheirs: after a relaunch nothing of the conflict is on disk, rather than the choice being stored.
    • identicalConflictIsNoConflict and demotedWriterDropsItsEdits: edits from before a launch come from the 0.88 store, the only place they can be on disk; they are uploaded once, and demotedWriterDropsItsEdits now expects them listed as not taken.
    • The conflicted() helper makes its conflict with a publish whose push waits while another admin writes, since 0.88 edits no longer become conflicts to resolve.
    • From feat(team-library): editors publish to the Team Library and see their role #4472: editorMadeMemberDropsItsEdits, editorKeepsItsEdits and adminMadeEditorKeepsItsEdits make their unsent edit in memory with a failed push instead of saving it to disk and relaunching; a demoted editor's edit is now listed as refused rather than gone.
    • pushAnsweredAfterSignOut: the store drops after the pass in flight, so the test syncs once before checking.
    • signOutWaitsForThePushInFlight became signOutEndsTheSessionAtOnce: the session ends at the sign-out, so the edit whose push is out is listed as discarded and its late answer records nothing.
    • signOutClears, involuntarySignOutDiscards, lostFeatureClosesTheSession, lostFeatureDropsTheLibrary: the folder goes once the pass in flight drains, so they wait for it.
    • AccountSettingsModelTests.signOutConfirmationNamesUnsentTeamChanges: Sign Out lists the edits with sync stopped; signOut() is now the whole flow and asks through an injected prompt, so signOutForgetsLoadedData and lateResultFromAnOldAccountIsDropped pass one.
    • TeamLibrarySyncTests.lostFeatureDropsTheLibrary: losing team_library now closes the session.
    • AccountSettingsModelTests.useStoredLicenseKey and refusedLicenseKey, TelemetryTests.licenseKeySwitchesAccount, AccountServicesTests.chooseCompanyServer: a switch while signed in is refused.

@datlechin datlechin changed the title refactor(macos): one Team Library folder per server and account, opened and closed with the session refactor(macos): one Team Library store owned by the core's sign-in, whose id every bearer carries Nov 24, 2026
@datlechin datlechin changed the title refactor(macos): one Team Library store owned by the core's sign-in, whose id every bearer carries refactor(macos): a switch of sign-in relaunches, and Team Library keeps one owner-checked store Nov 24, 2026
@datlechin
datlechin force-pushed the feat/macos-team-library-sessions branch from a472897 to c8e02c5 Compare November 24, 2026 10:42
@datlechin datlechin changed the title refactor(macos): a switch of sign-in relaunches, and Team Library keeps one owner-checked store refactor(macos): keep unsent Team Library edits in memory and switch sign-ins in process Nov 24, 2026
…n a lost feature, and own Sign Out's hold in one flow
…n, and decide the store on a company server choice
…' into feat/macos-team-library-sessions

# Conflicts:
#	apple/TablePro/Core/Services/TeamLibrary/TeamLibrarySync.swift
#	apple/TablePro/Resources/Localizable.xcstrings
#	apple/TableProTests/TeamLibrary/TeamLibrarySyncTests.swift
@datlechin
datlechin merged commit 2429572 into feat/core-account-company-server Nov 24, 2026
36 checks passed
@datlechin
datlechin deleted the feat/macos-team-library-sessions branch November 27, 2026 16:37
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.

1 participant