Skip to content

feat(agent): add bounded snapshot subscriptions - #97

Open
ben-ranford wants to merge 21 commits into
feat/65-subscription-dependenciesfrom
feat/65-snapshot-subscriptions
Open

ben-ranford wants to merge 21 commits into
feat/65-subscription-dependenciesfrom
feat/65-snapshot-subscriptions

Conversation

@ben-ranford

@ben-ranford ben-ranford commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • problem: Automation clients must poll for state changes and manually manage missed revisions.
  • change: Add the explicitly negotiated stave.snapshot.subscribe/v1 extension. Each physical JSONL connection owns one subscription, writes its full baseline first, and coalesces later updates into one pending full snapshot. Unsubscribe, close, cancellation and output failure stop and join the producer.
  • compatibility: Existing protocol version 1.0 and polling payloads are preserved. Clients and host policy must both select the extension. Action authorization and confirmation remain application-owned. Separate Server/BindSession instances isolate physical clients; hosts supply bounded, interruptible writers.

Closes #65

This PR targets feat/65-subscription-dependencies, containing #78, #94 and #79, so its diff contains only #65. After those prerequisites land, rebase the #65 commits onto current main and retarget before the merge gate.

Validation

  • make fast
  • make verify
  • make ci — final exit 0; /tmp/stave-pr97-handler-ci.log after the handler cleanup.
  • All subscription and bound-session lifecycle tests repeated 10 times under -race.
  • Real two-client slow-writer isolation, monotonic coalescing/full resync, baseline ordering, duplicate subscribe, ID-less unsubscribe, exact negotiation and authority/redaction regressions.
  • Polling history bounds and behavior-preserving handler decomposition; independent production and test reviews passed.
  • Provider failure, oversized baseline/update, writer failure, EOF, context/server/session close, cancel and shutdown cleanup paths.
  • Separate schema and relative-reference checks; architecture review CLEAR and bounded cleanup review found no material change needed.

Release Notes

  • changelog: Add opt-in bounded full-snapshot subscriptions for automation clients.
  • follow-up: Final release and publication remain controlled by the held Release Please PR; this change creates no tag or release.

Scope firewall: A review item belongs here only if it directly prevents #65 acceptance and is an incremental correction in the initially touched subscription, bridge, negotiation or schema surface. Shared files or wording do not justify adjacent work.

@ben-ranford ben-ranford added area:agent Semantic snapshots, JSONL/JSON-RPC, automation, and accessibility type:feature Additive user-facing library capability or workflow priority:p1 Foundational or high-impact milestone work labels Sep 13, 2026
@ben-ranford ben-ranford added this to the v1.1.0 milestone Sep 13, 2026
@ben-ranford ben-ranford self-assigned this Sep 13, 2026
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 12:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-14T13:20:07.997322Z 206483d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c76bf29516

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread schema/protocol/snapshot-subscriptions.json Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Compatibility and subscription cleanup issues, plus the required changelog update, remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds an opt-in, negotiated full-snapshot subscription extension with bounded delivery, session integration, schemas, documentation, and lifecycle tests.

Changes:

  • Adds subscription protocol types, negotiation, and capability support.
  • Implements bounded coalescing delivery and cleanup.
  • Adds session bridging, validation, documentation, and tests.
File summaries
File Reviewed change
scripts/rigor/generated/public-api.txt Updates generated public API inventory.
schema/protocol/subscription_schema_test.go Validates schema separation and references.
schema/protocol/snapshot-subscriptions.json Defines the subscription wire schema.
runtime/agent/subscription.go Implements bounded subscription state and production.
runtime/agent/subscription_test.go Tests negotiation and baseline behavior.
runtime/agent/subscription_lifecycle_test.go Tests lifecycle and failure cleanup.
runtime/agent/subscription_delivery_test.go Tests coalescing and client isolation.
runtime/agent/session_bridge.go Bridges sessions to snapshots and publications.
runtime/agent/server.go Handles negotiation, delivery, and lifecycle cleanup.
protocol/protocol.go Adds extension constants and wire types.
docs/snapshot-subscriptions.md Documents subscription usage and responsibilities.
docs/README.md Links the subscription guide.
capability/capability.go Adds subscription capability negotiation data.
Review details

Suppressed comments (4)

docs/snapshot-subscriptions.md:6

  • This adds user-visible protocol behavior, but CHANGELOG.md's Unreleased section remains empty. The repository contribution rules require updating the changelog for user-visible behavior changes (CONTRIBUTING.md:38); please add the advertised subscription entry.
Snapshot subscriptions are an opt-in extension for automation clients that need
full semantic snapshots after state changes. They do not change Stave protocol
version `1.0`, the existing `stave.snapshot` polling request, or any existing
v1 payload.

runtime/agent/server.go:432

  • This subscription-specific error path also discards a writer failure. With an active subscription, a failed response write here leaves Serve reading and the producer waiting instead of joining it; propagate the write error and enter the normal cleanup path.
					_ = write(protocol.Response{JSONRPC: protocol.JSONRPC, ID: r.ID, Error: protocol.Errorf(protocol.InvalidRequest, "invalid snapshot unsubscribe request")})

runtime/agent/server.go:285

  • When a regular s.Notify write fails, the preceding error branch only records the failure and falls through; this cleanup runs only when the notifications channel closes. If the input remains open, an active subscription producer can keep waiting and snapshotting after the output failure, so the connection does not satisfy the required stop-and-join behavior. Treat the writer error as connection termination and close/join the current subscription before returning.
				} else {
					subscriptionMu.Lock()
					if subscription != nil {
						subscription.close()
						subscription = nil

runtime/agent/server.go:421

  • Server.Close can close s.notify while the baseline is being written. The writer's closed-channel branch may run before this assignment and observe no subscription; after that, this code installs the producer, but the local notifications channel is already nil and no later close signal will reach it. The producer can then remain alive until input EOF despite the server being closed. Coordinate installation with the close lifecycle or recheck the closed state after installing and immediately close/join the producer.
			if response.Error == nil && baseline != nil {
				subscriptionMu.Lock()
				subscription = newSnapshotSubscription(ctx, *baseline, subscriptionWake, s.opt.SnapshotPublicationWaiter, func(waitCtx context.Context) (protocol.SnapshotResult, bool) {
					result, err := s.subscriptionSnapshot(waitCtx)
					return result, err == nil
				})
				subscriptionMu.Unlock()
  • Files reviewed: 12/13 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread runtime/agent/server.go Outdated
Comment thread runtime/agent/server.go Outdated
Comment thread runtime/agent/server.go
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 13:47
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 13:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22f735dce3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread schema/protocol/snapshot-subscriptions.json
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 14:29
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 14:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e033631e7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread runtime/agent/server.go
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 15:11
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 15:11

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4f04a1f2a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread runtime/agent/server.go
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 15:41
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 15:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0387bb37b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread runtime/agent/server.go Outdated
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 16:25
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 16:25
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 16:30
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 16:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a67025f1dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread schema/protocol/snapshot-subscriptions.json
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 16:39
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 16:39
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 16:45
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 16:45
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 16:47
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 16:47
@ben-ranford
ben-ranford marked this pull request as draft September 14, 2026 13:14
@ben-ranford
ben-ranford marked this pull request as ready for review September 14, 2026 13:14
@sonarqubecloud

Copy link
Copy Markdown

@ben-ranford

Copy link
Copy Markdown
Owner Author

Sonar API audit

Reviewed commit: 206483d5fce3136034c05c69ed2745d52b0327e8.

Live public SonarCloud API queries for PR #97 returned:

  • Open issues: 0 (api/issues/search, resolved=false, all severities; total 0).
  • Security hotspots: 0 (api/hotspots/search; total 0).
  • Current-head Sonar check: passed (check run 103988958849).

Audited via CLI at 2026-09-14T13:18:17.598128+00:00. Project visibility was verified as public. No findings were changed or suppressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Semantic snapshots, JSONL/JSON-RPC, automation, and accessibility priority:p1 Foundational or high-impact milestone work type:feature Additive user-facing library capability or workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants