Skip to content

feat(sdk): expose session lifecycle surface - #1542

Merged
samuv merged 2 commits into
mainfrom
impl/sdk-session-lifecycle-surface
Sep 15, 2026
Merged

samuv merged 2 commits into
mainfrom
impl/sdk-session-lifecycle-surface

Conversation

@samuv

@samuv samuv commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add SDK-owned readonly session snapshot, transcript, capability, and mode projections
  • expose inspection, mutation, clear, and retry operations on the ergonomic session lifecycle
  • preserve request controls and session affinity across existing and new lifecycle calls
  • document the workflows and refresh the public API reports and generated SDK reference

Development stage

  • Plan / Interface — Bounded/Architectural behavioral and exact-interface contract; no implementation
  • Implementation — stacked on the approved Plan / Interface PR and intended to merge after it
  • Combined — compact one-task Bounded/Architectural exception
  • Spike / Routine — acceptance-plan spine exempt

Contract linkage

The directing user approved proceeding as a stack before #1501 merges. The merge order remains #1501 followed by this PR.

Interface conformance

Matches the approved contract.

Issue relationship

Closes #1468

Type of change

  • Behavioral/interface plan
  • Bug fix
  • New feature
  • Refactoring (shared run/retry startup choreography)
  • Dependency update
  • Documentation/process
  • Other (describe):

Test plan

Baseline checks

  • Acceptance-plan checker through CGO_ENABLED=0 task docs
  • SDK linting (task sdk:lint)
  • SDK typecheck (task sdk:typecheck)
  • SDK unit suite (task sdk:test): 49 files, 261 tests
  • SDK build (task sdk:build)
  • SDK API reports (task sdk:api:check)
  • Markdown generation and link checks (CGO_ENABLED=0 task docs)
  • Full repository lint/test: Go runtime and engine code are unchanged
  • Site build: generated references and strict link checks passed; site build not run locally
  • Landed plan strict trace: docs: define SDK session lifecycle surface #1501 is not landed; the repository-wide command currently stops on unrelated acceptance metadata
  • Final implementation review: /panel-review

Changes

Area Change
Session projections Detached readonly snapshots, transcripts, capabilities, title normalization, token usage, and strict mode validation
Lifecycle API Snapshot, transcript, rename, set-mode, compact, clear, and retry operations
Request path Separate RequestOptions on create/get/fork/run/close/delete and all new operations, with affinity merging
Verification Descriptor drift guards, protocol integrity, successor semantics, retry choreography, and injected gRPC/HTTP parity
Documentation TSDoc, API reports, generated API reference, and the sessions-and-runs guide

User-facing change

TypeScript applications can inspect and manage a session through stable SDK-owned values and can retry an eligible failed model step through the ordinary Run lifecycle.

Special notes for reviewers

  • Review snapshot/transcript completeness and detachment in session-projections.ts.
  • Review shared run/retry cancellation and busy-state release in client.ts.
  • No changelog file is changed. PR feat(sdk): generate release changelog entries #1482 owns the automated SDK changelog path.

@samuv
samuv added this pull request to stack #1543 September 15, 2026 07:06
@samuv samuv self-assigned this Sep 15, 2026
@samuv
samuv force-pushed the impl/sdk-session-lifecycle-surface branch from 157d0b2 to 9f06d9d Compare September 15, 2026 08:10
Base automatically changed from plan/sdk-session-lifecycle-surface to main September 15, 2026 08:18
@samuv
samuv force-pushed the impl/sdk-session-lifecycle-surface branch from 9f06d9d to 165c79c Compare September 15, 2026 08:18
@kantord

kantord commented Sep 15, 2026

Copy link
Copy Markdown
Member

Review: implementation of the session lifecycle surface

This is the implementation PR stacked on the plan (#1501, base plan/sdk-session-lifecycle-surface). Scope is tight and matches the contract: new session-projections.ts, client.ts lifecycle methods, index.ts exports, four test files, three API reports, one Go API-report pin, and two user-docs pages. No proto, no Go runtime, no generated-code changes — exactly as the plan's "Interface: None" promised.

Interface conformance — verified against the plan, field by field

  • All 16 projection interfaces (SessionSnapshot, SessionTranscript, ServerCapabilities, SessionTitle, …) match the plan's printed types exactly, including createdAtUnix: bigint, contextWindow: bigint, revision?: bigint.
  • SessionMode const/type is the 0–3 pair mirroring proto PermissionMode (Unspecified/Default/Plan/AcceptEdits), confirmed against harness.proto (enum PermissionMode).
  • Session/Sessions signatures match the plan, including the trailing RequestOptions additions to run/close/delete/create/get/fork.
  • Root index.ts exports every approved type plus the SessionMode value. All three API reports (node/deno/default) updated, and the Go pin (sdk_typescript_api_report_test.go) updated in lockstep.

Correctness — the parts most likely to hide bugs, all clean

  1. Projection detachment (AC1.1/1.2): arrays via [...]/.map, bytes via .data.slice(), records built on Object.create(null). args/content/structuredContent are string primitives — no detachment needed. Correct.
  2. Provider-private omission (AC1.2): transcriptMessage() maps only role/text/toolCalls/toolResult/parts — never reasoning, providerPhase, reasoningItemId. The descriptor guard asserts those three are in ConversationMessageSchema (so drift is caught) while the projection excludes them. This is the right structural defense.
  3. Fail-closed protocol integrity (AC1.3): projectSessionSnapshot returns undefined on empty ID, ID mismatch, or unknown mode (sessionMode() → undefined); every caller (#snapshot, transcript, get) throws ProtocolError. get() gained real correlation validation vs. the old bare-nil check.
  4. Shared run/retry choreography (the flagged refactor): both route through #startRun; #assertRunAvailable preserves SessionBusyError + single-consumption; retry sends {case:"retry",{sessionId}} with no prompt encoding. Signal composition is AbortSignal.any([requestOptions.signal, runAbort.signal]) — caller cancel and run abort both work. AbortSignal.any is already used across the SDK, so no new runtime-support risk.
  5. Affinity merging (AC2.2): threaded via sessionAffinityIfRepresentable(id, requestOptions); unrepresentable IDs strip the conflicting session-id header via the pre-existing withoutSessionAffinity. No raw.ts change needed — the 2-arg signature already existed.
  6. Successor isolation (AC3.1): clear() binds the successor to #baseOperations (the unwrapped ops), so it doesn't inherit the source's affinity hint; source handle stays open. fork/get similarly bind fresh.
  7. Capability refresh (AC2.1): #promptCapabilities relaxed from readonly; every snapshot-bearing op refreshes it via promptCapabilities(sessionCapabilities, capabilities) (session-specific first, server fallback) so a later run() follows a mode-driven model change.

Test coverage — every AC proof resolves

All 12 named vitest proofs from the plan exist with matching titles (the base64 anchors check out): projection completeness/omission/rejection, lifecycle mapping, affinity + typed errors, successor semantics, retry-as-ordinary-run, run/retry control preservation, and dual-transport parity (both a coverage test and a per-failure-class normalization test across injected gRPC + HTTP). The descriptor guard is a hardcoded field-list toEqual against the generated schema — the anti-drift mechanism works as designed.

Notes (non-blocking)

Verdict

Approve. The implementation faithfully realizes the approved contract, the risky parts (detachment, fail-closed validation, shared cancellation/affinity, successor isolation) are all handled correctly, and the descriptor-drift guard gives it durable teeth. No ship blockers. The only follow-through items are process, not code: land #1501 first, flip the plan to landed so the strict AC trace runs, and get the /panel-review pass.

@samuv
samuv merged commit 5828a72 into main Sep 15, 2026
35 checks passed
@samuv
samuv deleted the impl/sdk-session-lifecycle-surface branch September 15, 2026 08:30
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.

SDK: complete the ergonomic session lifecycle surface

2 participants