Skip to content

feat(platform): auto-sync OneDrive/SharePoint documents - #2507

Merged
larryro merged 6 commits into
mainfrom
fix/onedrive-sso-entra-id
Jul 6, 2026
Merged

larryro merged 6 commits into
mainfrom
fix/onedrive-sso-entra-id

Conversation

@larryro

@larryro larryro commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Reuse the Entra ID SSO token as a Microsoft Graph token so members can import and auto-sync OneDrive/SharePoint files right after signing in (Files.Read + Sites.Read.All scopes documented in SSO + documents pages).
  • Replace the old processing-records/backoff OneDrive sync workflow with a durable workflow loop: list every active sync config, then reconcile each config in its own iteration (sync_one_config) so failures are isolated and the engine can persist/retry per step.
  • Add idempotent sync-workflow provisioning on config upsert (install + schedule compensation), folder reconcile (batch import + prune), stop-sync UI, and Microsoft account persistence for token refresh.

This branch also includes two earlier commits not yet on main:

  • fix: implement cursor agent cli as a sandbox external agent
  • feat(platform): return-loop notifications and actionable email

Test plan

  • Sign in with Entra ID SSO and confirm the Microsoft 365 import entry appears on Documents when Graph scopes are granted
  • Import a OneDrive folder with sync enabled; confirm files land in the correct folder path and RAG indexing runs
  • Edit/delete a file in OneDrive; wait for the */15 schedule (or trigger manually) and confirm add/update/delete reconcile
  • Stop syncing from document row actions; confirm sync config deactivates and files remain
  • Verify workflow execution shows list_active_configs → loop_configs → per-config sync_one_config steps
  • Run bun run --filter @tale/platform test for onedrive + workflow structure tests

Definition of done

  • Green gate — platform typecheck, convex codegen, onedrive tests, workflow structure test, oxlint on changed files
  • Security gate — org-scoped sync config updates; token refresh via stored credentials; no secrets in code
  • Tests — onedrive import/reconcile/sync-workflow/structure tests; microsoft_account tests; onedrive-import-dialog test
  • Migration — N/A (no schema migration; uses existing onedriveSyncConfigs table)
  • Locales — en/de/fr strings for stop-sync + SSO scope guidance
  • Docs — en/de/fr enterprise-sso + documents pages updated
  • Accessibility — stop-sync uses existing row-action patterns
  • Sweep — workflow JSON, onedrive ops, SSO adapters, UI, locales, docs touched together
  • Observed — manual OneDrive sync verification pending in deployed environment
  • Commits — single feature commit on branch tip; branch pushed to origin/fix/onedrive-sso-entra-id

larryro added 3 commits July 6, 2026 00:07
Reuse the Entra ID SSO token as a Microsoft Graph token so members can
import OneDrive/SharePoint files right after signing in, and reconcile
every active sync config on a schedule.

- capture the granted OAuth scope on SSO login and thread the Graph token
- provision the sync workflow install + schedule idempotently on upsert
- drive per-config reconcile through a workflow loop (durable, retryable,
  observable) instead of processing-records/backoff
- reconcile folders (batch import + prune) and single files; add stop-sync
Use a Set for slug membership checks and negate booleans directly so the
lint job passes on provision_defaults_mutations.
Patching indexable file metadata now marks the row queued again when
ragStatus was unset; align the internal_mutations tests with that behavior.
@larryro
larryro marked this pull request as ready for review July 6, 2026 00:04
larryro added 3 commits July 6, 2026 08:38
When a file or subdirectory is deleted at the OneDrive/SharePoint source,
the folder-sync reconcile pruned the orphaned documents by calling
`deleteDocumentById` directly. That left two artifacts behind:

- the now-empty subfolder rows lingered in the hub (the reported bug), and
- the documents' RAG vector index was never purged, so removed files stayed
  retrievable by the assistant.

Reconcile is the only place a source-side deletion is noticed — the document
was never deleted through Tale's UI — so it must do the full cleanup. Mirror
the generic drive-reconcile path in document_action.ts:

- resolve the sync-target root and pass `cleanupAncestorsUpTo` so each prune
  reaps its now-empty ancestor folders, stopping at (never deleting) the root;
- route blob-bearing docs through `deleteDocumentFromRag` (staggered, with the
  externalItemId/fileId snapshot guard against an interleaving re-upload) so
  the vector index is dropped; metadata-only docs delete directly.

Covered by onedrive/run_folder_reconcile.test.ts.
`fetchChildren` read only the first Graph `/children` page and ignored
`@odata.nextLink`, so a synced folder with more than one page (~200 direct
children) listed only its first page. On the next sync run, every file past
the first page looked "gone" to the reconcile and was pruned — deleting live
documents (row, blob, and now RAG index) whose source files still exist.

Follow `@odata.nextLink` to the end so large folders list in full. Bound the
walk with a fail-safe page cap that THROWS rather than truncating: a short
read would silently re-introduce the mass-delete, so failing the sync (which
leaves every document untouched) is the safe outcome.

Recurring sync reads `/me/drive` only (SharePoint and the browse picker are
one-time imports where a truncated page is a missing import, not a deletion),
so this is the one listing on the destructive path. Covered by
list_folder_contents.test.ts.
Add the missing OneDrive sync mock, point the external-agent spec at the
correct i18n key, symlink token-sources into E2E fixtures, and give org
scaffold more reload attempts on cold CI boot.
@larryro
larryro enabled auto-merge (squash) July 6, 2026 01:29
@larryro
larryro merged commit 863c99e into main Jul 6, 2026
50 of 51 checks passed
@larryro
larryro deleted the fix/onedrive-sso-entra-id branch July 6, 2026 01:29
@larryro
larryro restored the fix/onedrive-sso-entra-id branch July 6, 2026 02:50
@yannickmonney
yannickmonney deleted the fix/onedrive-sso-entra-id branch July 7, 2026 07:34
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