Amp threads synchronization UML sequence diagram

octoco-dash
Smart (Opus 4.5)
Unlisted
The current project follows a "literate coding" approach where: - Only Amp is allowed to make code changes. - Commit messages need to be detailled and include the link to the last Amp thread. - The Amp thread may have been handed off from previous threads, which can be explored. Draw a UML Sequence Diagram in Mermaid to show how Amp threads are synchronized with the application.
Searched codebase
Explored 4 files

Now I have a clear picture of the sync architecture. Let me create the sequence diagram:

Ran mermaid

The diagram shows the complete synchronization flow:

  1. User triggers sync via the "Refresh Data" button in Streamlit
  2. Incremental fetch - queries the last updated_at timestamp to only fetch new/modified threads
  3. OAuth token acquisition - uses client credentials flow with auth.ampcode.com
  4. Paginated thread fetching - loops through pages via nextCursor until exhausted
  5. Entity upserts - creates/updates Thread, User, and Repository records
  6. Usage backfill - fetches usage data for any threads missing usage_usd
  7. Returns summary - reports counts back to the UI