Supported Word for Mac API for lifetime-safe conditional text replacement

nader alsheikh 0 Reputation points
2026-10-24T03:23:02.3033333+00:00

Is there a supported production Word for Mac API that can provide either of the following guarantees for a live document?

  1. A native operation compares a host-issued expected open-lifetime and all-edit state token, then performs one specified text replacement or refuses with zero mutation as one atomic operation.
  2. A native, owner-scoped critical section continuously excludes all relevant edits from capture/admission through preview and commit, permits the owner's one mutation, and fences stale owners after expiry or release. Lifetime transitions may proceed if they atomically revoke old authority before any old-intent write; copies/new opens must not inherit that authority.

These are architecture hypotheses, not claims that an existing API supplies them. The host version of interest is Word for Mac 16.112.4, build 16.112.26090911; that is bundle metadata, not proof of loaded-version or runtime capability. If a later supported build or a narrower enforceable document/storage scope is required, please identify it.

The operation is deliberately restricted to plain main text with tracking off, no existing revisions, a known uniform formatting profile and known Unicode/range measurements. It must preserve unaffected text and measured target/adjacent formatting, and refuse unknown or unsupported structures/formatting. General rich-text editing and native Undo are outside this question.

A successful guarantee must cover edits made through the Word UI, VBA, other add-ins, remote coauthors and relevant internal document changes. An edit followed by exact restoration or Undo/Redo must invalidate old intent unless a continuously held native fence prevented the edit. Old authority must not authorize a copy, reopened document, new open lifetime or unrelated active document. Local mutexes, equal-text checks, pane/session IDs and user pause instructions do not provide host enforcement.

Could the Word team clarify:

  • The exact supported API/signature, Mac minimum build, requirement set, licensing/channel requirements, supported storage modes and runtime admission check for either shape, if one exists.
  • The native identity/token or fence semantics across unsaved edits, formatting/structure/tracking changes, copy/Save As, close/reopen, pane reload, host restart and queued stale requests. How is ABA or token reuse prevented?
  • The comparison/commit enforcement point or continuous exclusion interval, and whether each conflicting writer participates. If a writer/storage mode is excluded, what supported enforcement makes that restriction reliable?
  • Whether stale, expired or mismatched authority guarantees zero mutation; whether a multi-command failure can leave partial changes; and how returned results remain tied to the original bound lifetime and how committed, refused and unknown completion are distinguished after crash, cancellation or a lost response. Is an authoritative read-only reconciliation possible without replaying the mutation?
  • For an exclusion API, how owner mutation occurs without releasing the fence, how preview-duration limits and renewal work, and how stale owners are prevented from writing after expiry or release.
  • What normative documentation or attributable supported-contract clarification establishes these guarantees for Word on Mac, including known exceptions. If no supported Mac mechanism satisfies either shape, an explicit statement of that supported scope would also be useful.

The reviewed documentation describes queued asynchronous execution, adjusting tracked ranges and insertText, Document members, document properties, event lifecycle and requirement-set availability. Those descriptions did not establish the complete native conjunction. A pointer to a supported stronger contract would be more useful than another read-then-write example.

Finite experiments can challenge a documented guarantee but cannot establish universal atomicity. Any candidate would still need independent contract review and bounded disposable-document host tests before use.

Microsoft 365 and Office | Development | Office JavaScript API
0 comments No comments

2 answers

Sort by: Newest
  1. Hin Vo 1,745 Reputation points Independent Advisor
    2026-10-24T04:16:39.9166667+00:00

    Hi @nader alsheikh

    Currently, I have not found a supported Word for Mac API that explicitly provides either of the guarantees described in your question.

    Atomic compare-and-replace: From my understanding, the Word JavaScript API uses a queued and batched execution model (context.sync()). The documented patterns are generally read-then-write operations. I have not found documentation describing a host-issued document lifetime/edit-state token, nor an API that atomically validates such a token and either performs a mutation or refuses it as a single native operation.

    Owner-scoped exclusion / locking: I have not found documentation for a document-level lock, critical section, lease, fence, renewal mechanism, or stale-owner revocation model that would prevent edits from all other writers while allowing a single owner to perform updates. The documented event model appears to provide change notifications rather than enforcement guarantees.

    Failure handling and reconciliation: I have not found documentation stating that a context.sync() batch is treated as a transactional operation with rollback semantics, nor documentation describing how to definitively distinguish committed, refused, or unknown outcomes following a crash, cancellation, or lost response.

    Please note that this summary reflects my understanding of the currently available documentation and should not be considered an authoritative product statement. To help you explore this scenario further, I recommend posting your question in the Tech Community forums, where you can engage with developers and specialists who have experience with Word add-ins, document automation, and advanced API behaviors. Because this topic involves architecture-level guarantees and supported platform behavior, community experts may be able to share additional insights, implementation experiences, or references that are not covered in the documentation.

    If you have any additional concerns, feel free to comment below. I would be more than happy to assist.

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-10-24T03:24:05.65+00:00

    No supported Word for Mac API documented for build 16.112.4 provides either the requested compare-and-replace transaction or an owner-scoped fence covering UI, VBA, add-ins, coauthors, lifecycle changes, and stale requests.

    Why the existing APIs do not satisfy either contract

    Word.run and context.sync() are not a conditional transaction. Office.js queues proxy-object commands and dispatches them asynchronously at context.sync(). The documented contract says that commands run as a batch, but it does not provide:

    • an opaque document-lifetime/all-edit version token;
    • an atomic “compare token, then replace or make no change” primitive;
    • transaction rollback or a zero-mutation guarantee if one command fails;
    • fencing across task-pane reload, close/reopen, Save As, host restart, or lost responses;
    • an authoritative operation-status query for reconciling unknown completion.

    Consequently, placing a read and insertText in one batch does not establish compare-and-swap semantics, and separate sync() calls necessarily leave an admission interval between observation and mutation.^1^

    Tracked ranges are references, not state tokens or locks. Tracking keeps a proxy object usable and adjusts it around surrounding document changes; it does not attest that no intervening edit occurred or prevent another writer from editing.^2^

    Events cannot implement the required fence or token. Word events may be triggered by UI edits, JavaScript add-ins, VBA, and remote coauthors, but handlers are destroyed when the add-in is refreshed, reloaded, or closed. Events are notifications after host activity, not synchronous admission controls, and are not persisted in the file.^3^

    The new coauthoring-lock API is not a solution

    CoauthoringLockCollection.add(options) can add a lock for a specified range, with lock types including Reservation and Ephemeral. A lock exposes its range, owner, and type, and can be removed with unlock(); the collection can remove ephemeral locks.^4^ ^5^ ^6^

    However, its documented scope is decisive:

    • It belongs to production requirement set WordApiDesktop 1.4 on Word for Mac.
    • It works only with legacy coauthoring locks.
    • It does not apply to modern OneDrive or SharePoint coauthoring.
    • Calling it on a modern document fails with GeneralException.^7^

    Even in a legacy-lock document, the public contract does not specify the required lease duration, renewal, stale-owner fencing, ABA prevention, atomic authority revocation, crash semantics, copy/reopen behavior, or participation by every relevant writer. It also permits unlock() to remove a lock belonging to another user, which is not the requested owner-only release model.^5^

    Therefore, the API should not be elevated into the proposed lifetime-safe critical section without a stronger attributable support contract.

    Version and runtime admission

    Word for Mac 16.112.4 is newer than the documented minimum for WordApiDesktop 1.4, which is version 16.100.4 (25090553). That establishes potential requirement-set availability, not the stronger concurrency semantics and not loaded-runtime support.^8^

    The supported runtime admission check is:

    const available = Office.context.requirements.isSetSupported(
      "WordApiDesktop",
      "1.4"
    );
    
    if (!available) {
      throw new Error("WordApiDesktop 1.4 is unavailable in this runtime.");
    }
    

    Desktop-only sets cannot be activation requirements in an add-in-only XML manifest; a unified manifest can declare them under requirements.capabilities.^9^

    This check answers only whether the requirement set is exposed. It cannot determine whether a document uses legacy rather than modern coauthoring, nor convert the lock into the requested contract.

    Supported architectural conclusion

    For a live, independently editable Word document, client-side Office.js checks can provide optimistic detection only. They cannot provide the stated safety guarantee. Restricting content to plain text, disabling tracking, or validating formatting reduces replacement complexity but does not close the concurrency and lifetime gaps.

    A design requiring this guarantee must move mutation admission to a system that owns all writes and offers a documented transaction or compare-and-swap primitive. If users, VBA, other add-ins, or Word coauthoring may bypass that authority, the guarantee no longer holds.

    For a normative Word-team statement covering unpublished semantics, open an SLA-backed Microsoft 365 support request for a business-critical dependency. API bugs belong in the Office JavaScript API GitHub repository; feature requests belong in the Microsoft 365 Developer Platform channel.^10^ Request written confirmation specifically addressing atomic rollback, legacy-lock writer coverage, lease/fencing behavior, lifecycle identity, and unknown-completion reconciliation; absence of such a contract should be treated as unsupported rather than inferred through testing.


    References

    1. Application-specific API model
    2. Word.Coauthoring class-Remarks
    3. Work with events using the Word JavaScript API
    4. Word.CoauthoringLockCollection class
    5. Word.CoauthoringLock class-Remarks
    6. Word.CoauthoringLockType enum-Remarks
    7. Word.CoauthoringLockCollection class-Remarks
    8. Word JavaScript API requirement sets
    9. Word JavaScript API desktop-only requirement set 1.4
    10. Office Add-ins additional resources
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.