Path: blob/main/src/vs/platform/agentHost/common/state/AGENTS.md
13399 views
Protocol versioning instructions
This directory contains the protocol version system. Read this before modifying any protocol types.
Overview
The protocol has living types (in sessionState.ts, sessionActions.ts) and version type snapshots (in versions/v1.ts, etc.). The versions/versionRegistry.ts file contains compile-time checks that enforce backwards compatibility between them, plus a runtime map that tracks which action types belong to which version.
The latest version file is the tip — it can be edited. Older version files are frozen.
Adding optional fields to existing types
This is the most common change. No version bump needed.
Add the optional field to the living type in
sessionState.tsorsessionActions.ts:Add the same optional field to the corresponding type in the tip version file (currently
versions/v1.ts):Compile. If it passes, you're done. If it fails, you tried to do something incompatible.
You can also skip step 2 — the tip is allowed to be a subset of the living type. But adding it to the tip documents that the field exists at this version.
Adding new action types
Adding a new action type is backwards-compatible and does not require a version bump. Old clients at the same version ignore unknown action types (reducers return state unchanged). Old servers at the same version simply never produce the action.
Add the new action interface to
sessionActions.tsand include it in theISessionActionorIRootActionunion.Add the action to
ACTION_INTRODUCED_INinversions/versionRegistry.tswith the current version number. The compiler will force you to do this — if you add a type to the union without a map entry, it won't compile.Add the type to the tip version file (currently
versions/v1.ts) and add anAssertCompatiblecheck inversions/versionRegistry.ts.Add a reducer case in
sessionReducers.tsto handle the new action.Update
../../../protocol.mdto document the new action.
When to bump the version
Bump PROTOCOL_VERSION when you need a capability boundary — i.e., a client needs to check "does this server support feature X?" before sending commands or rendering UI. Examples:
A new client-sendable action that requires server-side support (the client must know the server can handle it before sending)
A group of related actions that form a new feature area (subagents, model selection, etc.)
When bumping:
Bump
PROTOCOL_VERSIONinversions/versionRegistry.ts.Create the new tip version file
versions/v{N}.ts. Copy the previous tip and add your new types. The previous tip is now frozen — do not edit it.Add
AssertCompatiblechecks inversions/versionRegistry.tsfor the new version's types.Add
ProtocolCapabilitiesfields insessionCapabilities.tsfor the new feature area.Assign your new action types version N in
ACTION_INTRODUCED_IN.Update
../../../protocol.mdversion history.
Adding new notification types
Same process as new action types, but use NOTIFICATION_INTRODUCED_IN instead of ACTION_INTRODUCED_IN.
Raising the minimum protocol version
This drops support for old clients and lets you delete compatibility cruft.
Raise
MIN_PROTOCOL_VERSIONinversions/versionRegistry.tsfrom N to N+1.Delete
versions/v{N}.ts.Remove the v{N}
AssertCompatiblechecks and version-grouped type aliases fromversions/versionRegistry.ts.Compile. The compiler will surface any code that referenced the deleted version types — clean it up.
Update
../../../protocol.mdversion history.
What the compiler catches
| Mistake | Compile error |
|---|---|
| Remove a field from a living type | Current extends Frozen fails in AssertCompatible |
| Change a field's type | Current extends Frozen fails in AssertCompatible |
| Add a required field to a living type | Frozen extends Current fails in AssertCompatible |
Add action to union, forget ACTION_INTRODUCED_IN entry | Mapped type index is incomplete |
Add notification to union, forget NOTIFICATION_INTRODUCED_IN entry | Mapped type index is incomplete |
| Remove action type that a version still references | Version-grouped union no longer extends living union |