Agent Host Protocol: Keeping Coding-Agent Sessions in Sync Across Devices

A practical guide to AHP's action, reducer, replay, and channel model for reconnectable cross-device coding-agent sessions.

AI Engineering•~11 min read•November 25, 2026•By QZ-L Editorial
#coding-agents#protocols#developer-tools#session-state
Looking for related guides? Start with the qz-l Learning Center and explore more tutorials in this topic cluster.

A coding agent is easy to start and surprisingly easy to lose. You launch a task in an editor, the window closes, the laptop sleeps, or a tool call waits for approval while you walk away. A separate chat interface may show the same repository, but it does not necessarily show the same session, the same pending command, or even the same view of the work.

That is the problem behind the Agent Host Protocol (AHP). It is an open, state-based protocol for keeping AI-agent sessions synchronized across clients. One client might be VS Code, another a phone, and another a terminal or web application. The agent host remains the source of authority, while each client gets a consistent way to display and mutate session state.

AHP is not an agent framework and not a description of how a model should reason. It is more comparable to a protocol for controlling a remote, stateful application. That narrower scope matters: it makes the protocol useful across many agent implementations without forcing them to share model-specific behavior.

The integration problem AHP addresses

Historically, each product can give an agent a chat surface by integrating directly with the agent runtime. A VS Code extension has one set of lifecycle rules. A web app has another. A mobile app needs resumable state and approval controls. Reusing the same integration in all of these places means carrying the host's internals into every client.

The cost becomes visible as soon as a session has to outlive a client:

  • Closing a VS Code window can terminate a session owned by that window.
  • Switching from a laptop to a phone should not start a duplicate task.
  • A disconnected phone should keep a pending approval from being lost or applied twice.
  • Tool output from a terminal host should appear in every client with the same ordering.
  • Clients should be able to add features gradually instead of implementing every host-specific command.

GitHub's engineering description says the protocol originated in exactly this setting: one Copilot integration was tied to the VS Code extension lifecycle, while Copilot was expanding to a mobile app, a standalone app, GitHub surfaces, and custom hosts. The answer was a shared session protocol that independently implemented hosts and clients could use.

For a team, AHP offers a practical architectural question: what should remain in the agent runtime, and what should become a portable protocol boundary? AHP puts session state, channel routing, actions, replay, and capability negotiation at the boundary. It leaves the model and agent behavior outside the protocol core.

Channels organize the session

AHP uses JSON-RPC 2.0 as its message framing. It does not depend on a particular transport implementation: a reliable, ordered, bidirectional stream can carry the messages.

Every push-style interaction is scoped to a URI-identified channel. Common channels include:

  • ahp-root:// for available agents and the session catalogue
  • ahp-session:/<uuid> for lifecycle, metadata, and a session's state
  • ahp-chat:/<cid> for turns, streaming, tool calls, and input requests
  • Terminal, automation, telemetry, TCP, and other channels for optional capabilities

Channel identity is a routing key. It appears at the top level of commands and notifications instead of being embedded inconsistently in payload fields. That gives a client a simple dispatch rule: inspect (channel, method or action type), then apply or ignore the event.

The protocol requires or expects core surfaces for root, session, and chat interaction, then lets hosts and clients negotiate optional features. A small terminal client may implement chat and session state only. A richer UI may also display terminal state or OpenTelemetry. This is more maintainable than forcing every implementation to understand every capability.

The x- namespace is reserved for implementation-defined extensions. Those extensions can be useful for a specific host or ecosystem, but they are not portable AHP behavior. An interoperability test should verify the standard channels separately from vendor-specific additions.

Actions are the mutation mechanism

AHP does not let a client mutate a reducer state object directly. State changes arrive as actions wrapped in an ActionEnvelope.

At a conceptual level, an envelope contains:

ActionEnvelope
  channel: URI
  action:  discriminated-union action
  serverSeq: monotonic sequence number
  origin: client identity and client sequence, or server
  rejectionReason: present only when the server rejected the action

The server assigns serverSeq, so the client can restore the correct order after reconnection. The origin distinguishes a client action from an action produced by the agent backend. A rejection marker tells the client that a previously optimistic change should be reversed.

For example, a client can dispatch a chat/turnStarted action when a user sends a message. The server applies that action and starts agent processing. Streaming text arrives as separate server-originated actions. A chat/turnCancelled action can ask the server to stop a turn.

This design separates UI state from side effects, while keeping the common interactive path simple. The client dispatches an action to the server. The server both changes state and performs the side effect—starting, cancelling, or creating work. It does not require a separate command API for common interactions and a second API for state updates.

Optimistic state and reconciliation

One of the protocol's strongest ideas is optimistic local state. A client can display a submitted message immediately instead of waiting for a round trip. It does not mark that message final until the server echoes the action.

The official guide describes three projections:

  1. Confirmed state: the last state acknowledged by the server.
  2. Pending actions: optimistic mutations that have not been echoed or rejected.
  3. Optimistic state: confirmed state with the pending actions replayed locally.

The UI renders optimistic state, giving immediate feedback while preserving confirmed state for reconciliation.

When an action envelope arrives, the client follows one of three paths:

  • Own action echoed: remove it from the pending queue and apply it to confirmed state.
  • Foreign or server action: apply it to confirmed state, then rebase the remaining pending actions.
  • Rejected action: remove the pending action and revert its optimistic effect.

Most chat actions are append-oriented, such as adding a turn or appending response text. Rebasing still works even if another client changed the conversation in the meantime. A true conflict—two clients trying to abort the same turn, for example—is server-wins: the host is authoritative and the losing optimistic update is rejected or reconciled.

That is a useful trade-off for a shared UI. Optimistic feedback feels immediate, but the client must preserve pending actions long enough to rebase them without silently overwriting server state.

Reconnecting without replaying the whole session

Long agent sessions are likely to encounter poor networks. A phone might approve a tool call, lose signal, and reconnect while the host continues working.

In AHP, reconnecting sends a request that includes:

  • the client's identity
  • lastSeenServerSeq
  • the channels to subscribe to

The server can replay missed action envelopes in order if they remain in its replay window. The client resets confirmed state and applies those actions. If the replay gap is too old, the server sends fresh snapshots instead.

Both paths converge the client, but they have different costs. Replay gives ordered, incremental recovery. Snapshots are larger but avoid depending on old action history. A host can therefore choose replay-window and snapshot limits according to session size and retention needs.

One detail is important for implementers: session-added and session-removed notifications are not replayed. The reconnecting client should re-fetch the session catalogue. Otherwise, a client could replay old chat actions while failing to discover a deleted or newly created session.

The protocol also has no magical way to merge all concurrent mutations. It is a sequencing and reconciliation design, not a general distributed-write solver. Teams should document which actions are append-only, which can conflict, and how each conflict should be resolved.

A practical integration checklist

AHP is portable, but adopting it still requires an explicit implementation plan.

1. Choose a host and client model

The AHP repository publishes client libraries for Rust, TypeScript, Kotlin, Go, Swift, and .NET, along with open-source hosts and clients. A project can also implement the specification directly.

Before choosing a library, identify the authoritative host process. It might run beside VS Code, in an isolated cloud sandbox, or as a standalone service. The host is responsible for session lifecycle and side effects, regardless of which UI is connected.

2. Implement the core channels first

Start with root, session, and chat channels. Verify session discovery, subscription, action sequencing, snapshot/replay behavior, and version negotiation before adding terminal or automation features.

The protocol is transport-agnostic. JSON-RPC framing matters, but the choice of WebSocket or another reliable bidirectional transport affects deployment, load balancing, buffering, and observability.

3. Make state authoritative and auditable

The server should validate every client action and reject unsafe or stale mutations. Keep per-action origin and sequence data in logs if your host needs forensic traceability.

Use stable channel IDs and avoid encoding mutable session state into the URI itself. Snapshot and replay storage should have size limits and retention policies.

4. Separate the protocol from permissions

A synchronized chat turn does not grant a tool permission. The host must enforce authentication, authorization, tool approval, tenant isolation, and secrets handling. A mobile client may approve an action only if the user and device are authorized to do so.

Also distinguish session visibility from execution capability. A viewer may see streamed output but should not dispatch cancellation or tool actions unless policy allows it. The protocol carries state and origin; it does not replace the host's authorization boundary.

5. Treat reconnect behavior as a test matrix

Test at least these conditions:

  • A client disconnects before a server echo arrives.
  • Two clients dispatch actions while disconnected.
  • Replay crosses a sequence gap.
  • Replay exceeds the host buffer and requires a snapshot.
  • A server rejects an optimistic action.
  • The session catalogue changes during the gap.
  • A message is duplicated, reordered, or received after an explicit cancellation.

These tests matter more than a happy-path chat demo. They verify that state converges rather than merely that messages appear.

Trade-offs to accept

AHP improves portability, but it introduces complexity in at least four areas.

It is a protocol, not a complete product. Host discovery, authentication, storage, isolation, billing, and user interfaces remain implementation work. The protocol can provide a common wire model, but it cannot make a cloud deployment secure by itself.

Reducers make state reproducible. Rejection and replay are easier to reason about when state mutations are pure. The cost is modeling more of the system in explicit actions instead of letting clients call imperative APIs.

Server-wins is predictable. It keeps the host authoritative, but a team must explain when pending work will be reverted. Concurrent approvals and cancellation need clear UI feedback.

Replay and snapshots are operational choices. Replaying every action forever is expensive, while very short replay buffers cause frequent snapshot transfers. Capacity limits, sequence retention, and snapshot size belong in the host design.

Optional channels add value without universal requirements. Terminal, telemetry, MCP, and automation features can make a host useful, but each introduces separate security and lifecycle decisions. Capability negotiation should prevent a basic client from crashing because a host offers a feature it does not understand.

Where AHP fits

AHP fits best when the core problem is a shared, long-running session across multiple implementations. A team building one editor plus a phone approval view has a clear need. So does a terminal host that wants third-party clients or a cloud service that needs to resume work on different surfaces.

It is not necessary for every chat wrapper. A single application that owns one short-lived conversation can often use a simpler API. A model-specific library may also be more appropriate when it is intentionally tied to one agent runtime and UI.

The protocol should be evaluated for what it adds: the same session state, ordered actions, reconnection and reconciliation, optional capabilities, and independent client/host implementations. Those qualities matter even outside coding. They can also support internal operational tools, approval workflows, or customer support systems—anything where human interaction and remote state need to remain synchronized.

For QZ-L readers, the takeaway is architectural rather than speculative: do not design cross-device agent continuity by copying chat payloads from editor to mobile app. Define a small host-authoritative state model, make mutations replayable, negotiate capabilities explicitly, and keep authorization outside the UI. Those choices make a session a durable resource instead of a property of a browser tab or editor window.

References

Related Posts

Git's November 2026 Security Release: A Practical Update Checklist

Map Git's six November 2026 vulnerabilities to real repository operations and update safely across workstations, CI, and hosting services.

A Practical Guide to OpenTelemetry Instrumentation in Next.js

Learn where Next.js initializes OpenTelemetry, how to separate runtime-specific setup, and what it takes to export useful traces.

How to Spot a Fraud Email Link Before You Click

A practical guide to identifying phishing emails, suspicious links, and fake payment pages before they can steal your money or account access.