Expose versioned session activity in the Rust SDK - #2600
Conversation
Pin generated contracts to the authoritative runtime commit, add validated Rust query/event APIs and connection-scoped reduction, and document scoped cancellation semantics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
| const schema = await response.text(); | ||
| JSON.parse(schema); | ||
| await fs.mkdir(schemaDirectory, { recursive: true }); | ||
| await fs.writeFile(schemaPath, schema); |
| throw new Error( | ||
| `Failed to fetch ${schemaName} at ${commit}: ${response.status} ${response.statusText}`, | ||
| ); | ||
| } |
| } finally { | ||
| fs.rmSync(stagingDir, { recursive: true, force: true }); | ||
| } | ||
| } |
| const schema = await response.text(); | ||
| JSON.parse(schema); | ||
| await fs.mkdir(schemaDirectory, { recursive: true }); | ||
| await fs.writeFile(schemaPath, schema); |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Generated by SDK Consistency Review Agent for #2600 · copilot · sonnet50 · 49.6 AIC · ⌖ 12.4 AIC · ⊞ 8.3K
| /// response, or an unknown contract version is reported as | ||
| /// [`SessionActivitySupport::Unsupported`](crate::session_activity::SessionActivitySupport::Unsupported). | ||
| /// A malformed version 1 response is an error. | ||
| pub async fn activity(&self) -> Result<crate::session_activity::SessionActivitySupport, Error> { |
There was a problem hiding this comment.
This PR is mostly the routine multi-language codegen refresh (updated pinned CLI schema → regenerated rpc/session-events types for Node, Python, Go, .NET, and Java), which is expected to be one-sided per-SDK output and doesn't need cross-SDK mirroring.
However, this PR also adds substantial hand-written, non-generated functionality only to Rust:
Session::activity()(this method) — a high-level, ergonomic wrapper over the rawsession.metadata.activityRPC call- The new
rust/src/session_activity.rsmodule:SessionActivitySnapshot,SessionActivityReducer(connection-scoped ordering/dedup logic for activity snapshots +session.activity_changedevents),SessionActivitySupport/SessionActivityUnsupportedReasoncapability detection, etc. - A new example (
rust/examples/session_activity.rs) and README section documenting the recommended subscribe-then-query pattern.
None of the other five SDKs (Node.js, Python, Go, .NET, Java) expose an equivalent high-level activity()/get_activity() helper or a reducer/ordering utility — they only get the raw generated session.metadata.activity() RPC call (e.g. Java's generated SessionMetadataApi.activity()), with no idiomatic wrapper, capability-detection helper, or reducer for correctly ordering session_activity_changed events against the query result.
Since this looks like meaningful new SDK-level API surface (not just internals), consider whether the other language SDKs should get an equivalent convenience API (session-level activity()/GetActivity() method plus a small helper for safely reconciling the query result with change events) to keep feature parity, or whether this is intentionally scoped as a Rust-only experiment for now.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Core ordering and decoding bugs, Java compile failures, and unsafe CI secret handling remain.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Balanced
Findings: 4
New issues introduced by this change (5)
| Severity | Finding |
|---|---|
.github/workflows/codegen-check.yml — For fork and Dependabot PRs this skips regeneration, after which the unchanged-worktree check… |
|
.github/workflows/java-codegen-check.yml — Skipping generation for fork and Dependabot PRs makes the subsequent clean-worktree check a no-op,… |
|
go/rpc/zsession_encoding.go — This decoder unmarshals activity events into SessionActivityChangedData, but that generated type… |
|
rust/src/session_activity.rs — A delayed snapshot from an older epoch can replace newer state because every epoch mismatch is… |
|
go/rpc/zsession_encoding.go — The generated file is not gofmt-formatted (gofmt -d reports a 784-line diff), so formatting/lint… |
What changed in this PR
Adds versioned Rust session activity support while temporarily sourcing generated contracts from a pinned runtime commit.
Changes:
- Adds Rust activity querying, validation, reduction, documentation, and tests.
- Regenerates cross-language protocol contracts.
- Updates codegen workflows for private runtime schemas.
| File | Description |
|---|---|
scripts/codegen/utils.ts |
Fetches pinned schemas and normalizes primitive literals. |
scripts/codegen/rust.ts |
Applies primitive normalization to Rust generation. |
scripts/codegen/python.ts |
Applies primitive normalization to Python generation. |
rust/tests/e2e/rpc_session_state_extras.rs |
Tests legacy activity handling. |
rust/tests/e2e/rpc_server_plugins.rs |
Adapts plugin request fields. |
rust/src/session.rs |
Adds the high-level activity query. |
rust/src/session_activity.rs |
Implements activity validation and reduction. |
rust/src/lib.rs |
Exports the activity module. |
rust/src/generated/session_events.rs |
Regenerates Rust event contracts. |
rust/src/generated/rpc.rs |
Regenerates Rust RPC contracts. |
rust/src/errors.rs |
Adds invalid-activity protocol errors. |
rust/README.md |
Documents activity semantics and cancellation. |
rust/examples/session_activity.rs |
Demonstrates subscribe-before-query usage. |
nodejs/src/generated/session-events.ts |
Regenerates TypeScript event contracts. |
nodejs/src/generated/rpc.ts |
Regenerates TypeScript RPC contracts. |
nodejs/src/cliVersion.ts |
Pins the runtime contract commit. |
nodejs/scripts/set-cli-version.js |
Clears temporary contract pins on updates. |
nodejs/package.json |
Records the contract commit. |
java/sdk/src/generated/java/com/github/copilot/generated/SubagentTaskModelSource.java |
Adds task-model source values. |
java/sdk/src/generated/java/com/github/copilot/generated/SubagentStartedEvent.java |
Adds task-model source data. |
java/sdk/src/generated/java/com/github/copilot/generated/SubagentModelSelectionSource.java |
Adds model-selection source values. |
java/sdk/src/generated/java/com/github/copilot/generated/SubagentFailedEvent.java |
Adds model-selection metadata. |
java/sdk/src/generated/java/com/github/copilot/generated/SubagentCompletedEvent.java |
Adds model-selection metadata. |
java/sdk/src/generated/java/com/github/copilot/generated/SessionProcessActivity.java |
Adds process activity counts. |
java/sdk/src/generated/java/com/github/copilot/generated/SessionMainAgentWaitReason.java |
Adds wait-reason values. |
java/sdk/src/generated/java/com/github/copilot/generated/SessionMainAgentState.java |
Adds agent-state values. |
java/sdk/src/generated/java/com/github/copilot/generated/SessionMainAgentActivity.java |
Adds main-agent activity data. |
java/sdk/src/generated/java/com/github/copilot/generated/SessionEvent.java |
Registers new event subtypes. |
java/sdk/src/generated/java/com/github/copilot/generated/SessionCompactionCompleteEvent.java |
Adds active-factory summary data. |
java/sdk/src/generated/java/com/github/copilot/generated/SessionBackgroundAgentActivity.java |
Adds background-agent counts. |
java/sdk/src/generated/java/com/github/copilot/generated/SessionAutoTierRecommendationEvent.java |
Adds recommendation events. |
java/sdk/src/generated/java/com/github/copilot/generated/SessionActivityChangedEvent.java |
Adds activity-change events. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SubagentSettingsEntry.java |
Adds auto-invocation configuration. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionsGetClientMetadataParams.java |
Adds metadata batch parameters. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionSandboxDisableForSessionResult.java |
Adds sandbox-disable results. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionSandboxDisableForSessionParams.java |
Adds sandbox-disable parameters. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionSandboxApi.java |
Adds sandbox-disable RPC access. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionProcessActivity.java |
Adds RPC process activity data. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionModelSetAllowedModelsResult.java |
Adds model-policy results. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionModelSetAllowedModelsParams.java |
Adds model-policy parameters. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionModelApi.java |
Adds allowed-model RPC access. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionMetadataUpdateClientMetadataParams.java |
Adds metadata patch parameters. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionMetadataGetClientMetadataParams.java |
Adds metadata query parameters. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionMetadataApi.java |
Adds client-metadata RPC access. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionMetadataActivityResult.java |
Expands activity query results. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionMainAgentWaitReason.java |
Adds RPC wait-reason values. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionMainAgentState.java |
Adds RPC agent-state values. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionMainAgentActivity.java |
Adds RPC agent activity data. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFsAppendFileParams.java |
Clarifies append behavior. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryRunResult.java |
Adds pause metadata. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryRunFromToolResult.java |
Adds pause metadata. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryPauseResult.java |
Adds factory-pause results. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryPauseParams.java |
Adds factory-pause parameters. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryPauseAtCheckpointResult.java |
Adds checkpoint results. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryPauseAtCheckpointParams.java |
Adds checkpoint parameters. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryGetRunResult.java |
Adds pause metadata. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryGetRunDetailResult.java |
Adds resume eligibility. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryCancelResult.java |
Adds pause metadata. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionFactoryApi.java |
Adds factory-pause RPCs. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/SessionBackgroundAgentActivity.java |
Adds RPC background-agent counts. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/ServerSessionsApi.java |
Adds batch metadata access. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/ServerPluginsApi.java |
Updates plugin API documentation. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/PluginsEnableParams.java |
Adds plugin working directory. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/PluginsDisableParams.java |
Adds plugin working directory. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/FactoryRunTerminal.java |
Adds terminal pause metadata. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/FactoryRunSummary.java |
Adds resume eligibility. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/FactoryRunStatus.java |
Adds paused status. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/FactoryRunResult.java |
Adds pause metadata. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/FactoryPauseCheckpointAction.java |
Adds checkpoint actions. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/FactoryAgentOptions.java |
Updates option semantics. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/FactoryAbortParams.java |
Adds execution tokens. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/ClientMetadata.java |
Adds generated metadata type. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/CapiSessionOptions.java |
Documents the fast tier. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/AutoTier.java |
Adds the fast tier. |
java/sdk/src/generated/java/com/github/copilot/generated/rpc/AgentInfo.java |
Adds invocation configuration. |
java/sdk/src/generated/java/com/github/copilot/generated/RecommendedAutoTier.java |
Adds recommended tiers. |
java/sdk/src/generated/java/com/github/copilot/generated/FactoryRunSettledStatus.java |
Adds paused status. |
java/sdk/src/generated/java/com/github/copilot/generated/CustomAgentsUpdatedAgent.java |
Adds invocation configuration. |
java/sdk/src/generated/java/com/github/copilot/generated/CompactionCompleteCompactionTokensUsedCopilotUsageTokenDetail.java |
Adds billing model data. |
java/sdk/src/generated/java/com/github/copilot/generated/CompactionCompleteCompactionTokensUsedCopilotUsage.java |
Adds default billing model data. |
java/sdk/src/generated/java/com/github/copilot/generated/AutoTier.java |
Adds the fast tier. |
java/sdk/src/generated/java/com/github/copilot/generated/AssistantUsageCopilotUsageTokenDetail.java |
Adds billing model data. |
java/sdk/src/generated/java/com/github/copilot/generated/AssistantUsageCopilotUsage.java |
Adds default billing model data. |
java/scripts/codegen/fetch-schemas.test.mjs |
Tests commit-based schema fetching. |
java/scripts/codegen/fetch-schemas.mjs |
Fetches schemas from a pinned commit. |
go/rpc/zsession_encoding.go |
Regenerates Go event encoding. |
.github/workflows/update-copilot-dependency.yml |
Supplies schema-fetch credentials. |
.github/workflows/java-codegen-check.yml |
Adjusts private Java codegen validation. |
.github/workflows/codegen-check.yml |
Adjusts private shared codegen validation. |
Files not reviewed (4)
- go/rpc/zrpc_encoding.go: Generated file
- go/rpc/zsession_encoding.go: Generated file
- go/rpc/zsession_events.go: Generated file
- go/zsession_events.go: Generated file
Suppressed comments (2)
.github/workflows/codegen-check.yml:72
- This exposes
RUNTIME_TRIAGE_TOKENtonpm run generatefrom the pull-request checkout. A same-repository PR can modify the codegen package or scripts and read/exfiltrate this private-schema token. Do not pass repository secrets to code from a PR head; fetch the immutable schemas in a trusted workflow/step without executing PR code, then run generation against the staged files.
env:
RUNTIME_TRIAGE_TOKEN: ${{ secrets.RUNTIME_TRIAGE_TOKEN }}
run: npm run generate
.github/workflows/java-codegen-check.yml:62
- This passes the private runtime token to the Java code generator checked out directly from the PR head, so a same-repository PR can alter that script and extract the secret. Stage the immutable schemas using trusted workflow code without exposing the token to the checkout, then run the PR's generator only against those staged inputs.
working-directory: ./java/scripts/codegen
env:
RUNTIME_TRIAGE_TOKEN: ${{ secrets.RUNTIME_TRIAGE_TOKEN }}
run: npm run generate
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| run: npm ci | ||
|
|
||
| - name: Run codegen | ||
| if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.fork == false && github.actor != 'dependabot[bot]') |
| run: npm test | ||
|
|
||
| - name: Run codegen | ||
| if: github.event_name != 'pull_request' || (github.event.pull_request.head.repo.fork == false && github.actor != 'dependabot[bot]') |
| case SessionEventTypeSessionActivityChanged: | ||
| var d SessionActivityChangedData | ||
| if err := json.Unmarshal(raw.Data, &d); err != nil { | ||
| return err | ||
| } |
| if current.activity_epoch != snapshot.activity_epoch { | ||
| self.current = Some(snapshot); | ||
| return SessionActivityReduction::ReplacedEpoch; |
| AgentID *string `json:"agentId,omitempty"` | ||
| Data json.RawMessage `json:"data"` | ||
| Ephemeral *bool `json:"ephemeral,omitempty"` | ||
| ID string `json:"id"` | ||
| ParentID *string `json:"parentId"` |
The authoritative runtime PR head moved after CI fixes without changing either generated schema. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
SDK Consistency ReviewScope of this PR is intentionally Rust-only for the ergonomic activity layer, per the PR description ("add validated Rust access for Cross-SDK gap worth tracking: Only the Rust SDK ships a hand-written ergonomic wrapper around the raw generated types:
The other five SDKs currently only expose the raw generated call (e.g. Go's
Since the runtime contract ( Recommendation: No changes required in this PR — the description frames this as Rust-first — but consider filing a tracking issue to bring the same capability-detection + reducer ergonomics to the other five SDKs before/around the next stable release of this contract, so consumers get consistent guarantees regardless of language.
|
|
Thanks for the detailed work here — the capability-detection shape is sensible, and session activity is a legitimate SDK capability once the runtime contract is real. This PR isn't ready to merge because it is still pinned to an unreleased runtime contract ( For tracking, I've moved this to draft - please mark as ready to review when appropriate. Please bring this back once:
Happy to re-review once the runtime ships and these are addressed. |


Summary
fe8a752a5442916234d59611eda30f68ba0821f9until a containing Copilot CLI package is releasedsession.metadata.activityandsession.activity_changedusing one sharedSessionActivitySnapshotCompatibility
The executable runtime remains pinned to Copilot CLI
1.0.83. The new activity contract requires runtime commitfe8a752a5442916234d59611eda30f68ba0821f9until a containing package release exists. Consumers should pin this SDK commit (0a0417f118c07db242e850faed0f6526928ef81e) until the next SDK release is published.Capability detection is structural: only
contractVersion == 1is supported. Missing method, legacy two-field responses, and unknown versions are unsupported/unknown rather than synthesized idle state.The authoritative runtime head advanced from
3225633fbdface9b6cfb0997aea1356d66552d31after CI fixes. Bothapi.schema.jsonandsession-events.schema.jsonare byte-for-byte identical between those commits, so the follow-up only updates provenance pins; no SDK API or generated contract changed.Validation
473 passed)Broad existing E2E suites were also exercised; environment/runtime setup failures outside this change remained in Node/.NET, while the focused activity and generated-contract validation passed.