Skip to content

Bound host downlink backlog and propagate capacity rejection to callers #364

Closed

Description

@coderabbitai

Summary

Add a per-host-link bound on the combined queued and unacknowledged downlink bytes. Reject a command before accepting it when that command would exceed the bound, and propagate the rejection to its caller.

This gap predates the current change stack. It is a separate follow-up, not a regression introduced by PR #362.

Requested by @andrebrait.

Rationale

sendDown in lib/hosts/hub.ts currently queues messages through link.sender.push. It records the bytes ahead as link.outboxBytes + link.sender.queuedBytes, but does not enforce a bound on that combined backlog.

Socket backpressure and the unacknowledged send window pace delivery. They do not bound the total retained backlog for a connected, slow daemon. The peer is the application's own daemon authenticated with a bearer token, but that does not limit accumulated downlink memory.

Required changes

  • Define and enforce a per-link byte cap that covers both queued and unacknowledged downlink data.
  • Check capacity before accepting a new command. If the command would exceed the cap, reject it without partially enqueueing or sending it.
  • Propagate capacity rejection through the command path to the original caller. Do not silently drop the command, report success, or make the caller wait for a timeout.
  • Keep byte accounting correct across queue-to-outbox transfers, acknowledgments, reconnect/resend, and message removal.
  • Update D6, “Limits and backpressure,” in docs/specs/2026-10-31-websocket-link-design.md. Document the cap, the accounting scope, and the caller-visible rejection behavior. Distinguish the total backlog cap from socket pacing and the unacknowledged send window.

Affected areas

  • lib/hosts/hub.ts: sendDown, downlink byte accounting, RemoteRpcTransport.write, and host-operation rejection handling.
  • lib/hosts/hub.test.mjs: backlog and rejection coverage.
  • docs/specs/2026-10-31-websocket-link-design.md: D6.

Acceptance criteria

  • Each host link enforces a documented bound on queued plus unacknowledged bytes.
  • Tests cover the capacity boundary and a command that would exceed it, including a backlog split between queued and unacknowledged data.
  • An over-capacity command reaches its caller as an explicit rejection and is not later delivered after capacity becomes available.
  • Rejection does not leave partial queue entries or pending operations waiting for a timeout.
  • Acknowledgments release capacity so later commands can be accepted.
  • Reconnect/resend does not double-count retained bytes or bypass the cap.
  • Tests verify that capacity is independent for each host link.
  • D6 matches the implemented limit and rejection behavior.

Context

Activity

  1. added 2 commits that reference this issue on Nov 23, 2026
    17e055e
    c2c1329
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions