Add per-turn conversation and user state - #729
Open
Mehak Bindra (MehakBindra) wants to merge 19 commits into
Open
Add per-turn conversation and user state#729Mehak Bindra (MehakBindra) wants to merge 19 commits into
Mehak Bindra (MehakBindra) wants to merge 19 commits into
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
Comment on lines
+332
to
+338
| try { | ||
| await this.options.stateLoader.save( | ||
| context.state, | ||
| conversationId, | ||
| userId | ||
| ); | ||
| } finally { |
| * @param userId User ID. | ||
| */ | ||
| userKey(conversationId: string, userId: string): string { | ||
| return `${this.keyPrefix}:user:${conversationId}:${userId}`; |
Collaborator
There was a problem hiding this comment.
These should be escaped
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 mutationsIStorageIStorage.setas a minimal key/value contract; expiration and other policies remain owned by the configured providerAppOptions.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