Skip to content

docs(session): define broker SDK contract - #895

Merged
benvinegar merged 4 commits into
mainfrom
docs/session-broker-sdk-contract
Aug 29, 2026
Merged

benvinegar merged 4 commits into
mainfrom
docs/session-broker-sdk-contract

Conversation

@benvinegar

@benvinegar benvinegar commented Aug 29, 2026

Copy link
Copy Markdown
Member

Summary

  • define the implementation contract for a reusable one-daemon-per-application session broker SDK
  • target one @hunk/session-broker package whose root resolves Node or Bun automatically through conditional exports
  • freeze identity, protocol negotiation, authentication, delivery, lifecycle, selector, and supervision semantics
  • document blocking security, compatibility, runtime, and packaging release gates
  • clarify that the current generic WebSocket and raw HTTP broker surfaces remain internal and unauthenticated

Why

The generic broker workspaces already contain reusable routing and lifecycle machinery, but later extraction phases would otherwise have to independently decide security, compatibility, discovery, delivery, and packaging behavior. This contract gives those phases one reviewed target while keeping Hunk review semantics application-owned.

The useful core/daemon/host/runtime boundaries remain internal modules. Consumers install one package and call one portable API; the package export map selects the Bun or Node server implementation without runtime-specific imports.

Important boundaries

  • one daemon serves one immutable application identity and many sessions
  • Hunk review state, resources, commands, and browser capability protocol stay outside the generic package
  • remote operation, browser/edge runtimes, and a universal cross-application daemon remain out of scope
  • coordinator/random-endpoint migration still requires explicit product approval before implementation
  • npm publication remains blocked on @hunk scope and trusted-publisher verification

Validation

  • bun test packages/session-broker-core packages/session-broker packages/session-broker-bun packages/session-broker-node — 44 passed
  • focused Hunk broker/config/launcher/client/server tests — 74 passed
  • bun run typecheck
  • bun run deps:check — 360 modules / 1,454 dependencies, no violations
  • bun run check:docs
  • targeted oxfmt --check for changed Markdown files
  • git diff --check
  • multiple fresh-context architecture, security, protocol, packaging, and release reviews; all findings dispositioned

Tested on Linux x86_64 with Bun 1.3.10 and Node 24.14.1 installed. The contract selects Bun 1.3.14 as the future public floor; clean-package attestation on that exact version remains a release gate.

This PR description was generated by Pi using gpt-5.6-sol

@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
hunk-web Ignored Ignored Preview Aug 29, 2026 1:53pm

Request Review

@greptile-apps

greptile-apps Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR defines the forward-looking contract and phased release gates for extracting the session broker into a reusable, authenticated, one-daemon-per-application SDK.

  • Defines package ownership, application/session identity, protocol negotiation, authentication, authorization, delivery, lifecycle, discovery, and supervision semantics.
  • Separates generic broker responsibilities from Hunk-owned review and browser capability protocols.
  • Documents migration compatibility and security, runtime, packaging, and publication gates while warning that current generic surfaces remain internal and unauthenticated.

Confidence Score: 4/5

The protocol contract should be corrected before implementation because its replay-window range cannot be enforced with the specified duplicate-tracking state.

The document requires a 64-bit bitmap to track an inclusive 128-value acceptance range, forcing conforming implementations to disagree about valid requests or lose replay detection.

Files Needing Attention: docs/session-broker-sdk.md

Important Files Changed

Filename Overview
docs/session-broker-sdk.md Introduces the complete SDK architecture and release contract, but its replay-window range cannot be represented by the specified bitmap.
packages/session-broker/README.md Clearly marks the present WebSocket and raw HTTP broker surfaces as unauthenticated, internal-only APIs and links to the future contract.
docs/browser-review-rebuild.md Clarifies that Hunk browser-review capabilities and semantics remain separate from the generic broker SDK.
docs/module-boundaries.md Adds the broker contract reference without changing the existing package-to-src dependency boundary.
.changeset/humble-toes-battle.md Adds an empty maintenance changeset appropriate for the documentation-only change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Host[Application host] --> Supervisor[Session broker host and supervisor]
    Supervisor --> Daemon[One daemon for immutable appId]
    ProducerA[Session producer A] --> Daemon
    ProducerB[Session producer B] --> Daemon
    Caller[Authenticated caller] --> Daemon
    Daemon --> Core[Broker core: identity, routing, limits, state]
    Daemon --> Adapter{Runtime adapter}
    Adapter --> Node[Node HTTP and WebSocket]
    Adapter --> Bun[Bun HTTP and WebSocket]
    Daemon -. application-owned commands and schemas .-> Hunk[Hunk review semantics]
    Hunk -. separate capability .-> Browser[Browser review protocol]
Loading
Prompt To Fix All With AI
### Issue 1
docs/session-broker-sdk.md:310-314
**Replay window exceeds bitmap**

When concurrent requests arrive out of order, the contract accepts sequences across the inclusive 128-value range from `highest - 63` through `highest + 64` while specifying only a 64-bit seen bitmap, causing implementations either to reject requests described as valid or lose duplicate-detection state and accept replayed requests.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "docs(session): define broker SDK contrac..." | Re-trigger Greptile

Comment thread docs/session-broker-sdk.md Outdated
Comment on lines +310 to +314
Caller sessions start at sequence string `"1"` and use a 64-sequence sliding replay window so up
to 32 concurrent HTTP requests may arrive out of order. The daemon tracks the highest accepted
uint64 value plus a 64-bit seen bitmap. It
accepts an unseen sequence from `highest - 63` through `highest + 64`, advances and shifts the
window for a new high value, and rejects duplicates, older values, or larger forward jumps. Caller

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Replay window exceeds bitmap

When concurrent requests arrive out of order, the contract accepts sequences across the inclusive 128-value range from highest - 63 through highest + 64 while specifying only a 64-bit seen bitmap, causing implementations either to reject requests described as valid or lose duplicate-detection state and accept replayed requests.

Knowledge Base Used: Session protocols and clients

Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/session-broker-sdk.md
Line: 310-314

Comment:
**Replay window exceeds bitmap**

When concurrent requests arrive out of order, the contract accepts sequences across the inclusive 128-value range from `highest - 63` through `highest + 64` while specifying only a 64-bit seen bitmap, causing implementations either to reject requests described as valid or lose duplicate-detection state and accept replayed requests.

**Knowledge Base Used:** [Session protocols and clients](https://app.greptile.com/modem/-/custom-context/knowledge-base/modem-dev/hunk/-/docs/session-protocols-and-clients.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch—the original wording was ambiguous. The 64-bit design is sufficient because the bitmap stores only accepted sequences from highest - 63 through highest; values above highest have never been accepted and need no replay bit until they advance and shift the window. I clarified that algorithm in cc24a43 and also specified sequence-zero reservation, initial state, atomic admission, safe uint64 arithmetic, delta-64 clearing, and exhaustion behavior.

Responded by Pi using gpt-5.6-sol.

This comment was generated by Pi using GPT-5.6 Sol

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed. With highest tracking the greatest admitted sequence, the bitmap only needs to record accepted values at or below it; future values cannot be replays until they advance the high-water mark. The clarified delta handling, including clearing rather than shifting by 64, atomic admission, uint64-safe comparisons, sequence-zero reservation, and opening a new caller session before exhaustion, resolves the finding.

@benvinegar
benvinegar merged commit c75a9a3 into main Aug 29, 2026
12 checks passed
@benvinegar
benvinegar deleted the docs/session-broker-sdk-contract branch August 29, 2026 14:00
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.

1 participant