Add per-turn conversation and user state - #729
Merged
Mehak Bindra (MehakBindra) merged 32 commits intoAug 26, 2026
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Copilot started reviewing on behalf of
Mehak Bindra (MehakBindra)
August 13, 2026 22:19
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces a new per-turn state subsystem for the apps package, enabling conversation-scoped and user-scoped mutable state that is loaded before dispatch, persisted at end-of-turn, and sealed after processing to prevent post-turn access.
Changes:
- Added
TurnState/TurnStateContainerabstractions with dirty-tracking and sealing semantics. - Implemented
TurnStateLoader+createStateLoaderto load/save JSON state envelopes with configurable key prefix and TTL. - Wired state into the activity processing lifecycle (
AppOptions.state,ctx.state) and added focused unit + dispatch lifecycle tests.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/apps/src/state/turn-state.ts | New turn-scoped state object with dirty tracking, snapshot iterators, and sealing behavior. |
| packages/apps/src/state/container.ts | New container for per-turn conversation + user scopes, with delete + seal helpers. |
| packages/apps/src/state/loader.ts | New loader for persisted state (keying, TTL checks, load/save/delete) and state-loader factory. |
| packages/apps/src/state/options.ts | New StateOptions type for storage, key prefix, and TTL configuration. |
| packages/apps/src/state/index.ts | Barrel exports for the new state subsystem. |
| packages/apps/src/index.ts | Exposes the state subsystem as part of the public apps package API. |
| packages/apps/src/contexts/activity.ts | Adds optional state to activity context options and propagates it in toInterface(). |
| packages/apps/src/app.ts | Adds AppOptions.state and constructs a TurnStateLoader for the processor. |
| packages/apps/src/app.process.ts | Loads state before dispatch (when enabled) and saves+seals it in finally. |
| packages/apps/src/state/state.spec.ts | Unit tests covering TurnState, TurnStateLoader, and createStateLoader. |
| packages/apps/src/app.process.spec.ts | End-to-end lifecycle tests for load/expose/persist/seal, including failure cases. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
This reverts commit f783ba1.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Mehak Bindra (MehakBindra)
marked this pull request as draft
August 14, 2026 00:48
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Mehak Bindra (MehakBindra)
marked this pull request as ready for review
August 14, 2026 20:10
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Mehak Bindra (MehakBindra)
requested review from
Corina (corinagum) and
Lily Du (lilyydu)
August 25, 2026 18:40
Lily Du (lilyydu)
approved these changes
Aug 25, 2026
Lily Du (lilyydu)
left a comment
Contributor
There was a problem hiding this comment.
LGTM but looks liek there's some merge conflicts!
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e719380b-bd6a-4ae8-9650-6ffcee53fb7d
…into mehakbindra-sync-main
Corina (corinagum)
approved these changes
Aug 26, 2026
Lily Du (lilyydu)
approved these changes
Aug 26, 2026
pull Bot
pushed a commit
to Mattlk13/teams.ts
that referenced
this pull request
Aug 28, 2026
## Summary Adds a first-class, per-connection OAuth lifecycle to `@microsoft/teams.apps`, modeled on `microsoft/teams.net` and using the turn-state support from microsoft#729. - adds `OAuthFlow` for silent token lookup, interactive sign-in, sign-out, and completion/failure callbacks - supports `AppOptions.oauthFlows`, `app.addOAuthFlow(...)`, and `app.getOAuthFlow(...)` - routes token exchange, verify-state, and sign-in failure invokes across multiple connections - persists pending attribution and exchange deduplication in turn state, with bounded process-local fallback when state is disabled - adds `ctx.getConnectionStatus()`, including direct token checks that correct stale silent-SSO status results - handles channel/group-chat OAuth cards consistently with Teams SSO behavior - replaces the Graph-only example with a Graph and GitHub OAuth example ## Public API ```ts const app = new App({ oauthFlows: ['graph', 'github'] }); const graph = app.getOAuthFlow('graph'); graph .onSignInComplete(async (ctx, token) => { /* use token */ }) .onSignInFailure(async (ctx, failure) => { /* handle failure */ }); const token = await graph.signIn(ctx); await graph.signOut(ctx); const statuses = await ctx.getConnectionStatus(); ``` ## Compatibility and behavior - retains existing OAuth settings, context helpers, events, routes, response shapes, explicit legacy connection overrides, and the TypeScript sign-in activity override - registered flows do not enable eager per-turn token lookup - omitted state is enabled internally for registered flows; explicit `state: false` keeps bounded process-local tracking - expected token misses (`400`, `404`, `412`) trigger interactive fallback; unexpected service or transport failures propagate - verify-state continues only for connection misses; unexpected HTTP failures preserve their status - successful exchanges are marked processed before callbacks, so retries remain deduplicated if a callback throws ## Breaking changes - `ctx.signin()` previously treated every token lookup failure as a missing token and sent an OAuth card. It now sends a card only for expected token-miss responses (`400`, `404`, `412`). Unexpected service and transport failures propagate and may produce a `500` for the turn instead of silently switching to interactive sign-in. - OAuth invoke spans are unified under `microsoft.teams.oauth`, with `oauth.operation` distinguishing token exchange, verification, and failure. Existing `oauth.result` values also move to lifecycle-specific values. Dashboards and alerts using the previous span names or result values must migrate; this must be called out in the release changelog. The non-HTTP error value remains `exception`. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0d88953d-cdee-4a28-ac2d-36a5fee72da5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AppOptions.stateandctx.state, loading before dispatch and saving infinallyset()for persisted mutationsIStorage<string, string>state: truededicated process-local string storage instead of casting or reusing legacyAppOptions.storage; production apps can providestate.storageIStorage.setas a minimal key/value contract; expiration and other policies remain owned by the configured providerInvokeResponsethrough the publicactivity.responseevent, matching its declared contractAppOptions.storage,app.storage, andctx.storageaccess in favor ofstate.storageor application-owned persistenceIListStorageandListLocalStorage; Python still exposes list storage, while the .NET state/storage design does not include this generic abstractionPorts the combined state foundation from microsoft/teams.py#553 and microsoft/teams.py#554, aligned with microsoft/teams.net while keeping TypeScript keyed state explicit and JSON-native. Standardized TTL and other per-write options are intentionally deferred until the SDK has a concrete cross-provider requirement.
Validation