Skip to content

Latest commit

 

History

History
51 lines (26 loc) · 12 KB

message-wait.md

File metadata and controls

51 lines (26 loc) · 12 KB

Quiet Agent Message Wait

Implementation status

This slice adds a bounded CLI/MCP wait over the existing persistent incoming-message SSE transport. The typed client and CLI/MCP adapters implement this contract. Focused normal/race typed-client, public-handler, CLI and official-SDK adapter tests pass. Full combined validation and actual packaged proof pass at the source checkpoint below. The server's existing snapshot, replay, authorization and capacity rules remain owned by incoming message events.

Selection and result

fc inbox wait --cursor CURSOR [--limit N] [--wait-seconds N] and the read-only MCP tool wait_for_messages select the profile-bound worker's incoming feed. Cursor is required. Limit defaults to 20 and accepts 1–100. Wait defaults to 25 seconds; CLI and typed-client waits accept 1–60, while MCP accepts 1–50. The MCP cap leaves five seconds shared by identity bootstrap and establishment, and at least five more under a 60-second host tool deadline; choose a shorter wait if the configured host deadline requires it. Explicit zero, null, unknown, duplicate or malformed fields are refused before credentials/network work. The typed client is WaitForMessages(ctx, cursor, limit, waitSeconds) (MessageEventPage, error); typed zero limit/wait selects these defaults.

Relevance means new message.sent events after the supplied cursor, including messages another connection may already have seen. It is an event notification, not an unread/unacknowledged inbox query or a complete resume packet. Pending inbox reads and job context remain explicit. Results contain bounded event metadata and conversation IDs; full bodies require a selected conversation read.

One call returns the first valid event page containing new incoming messages, filtered to message.sent, with its cursor, has_more and timed_out:false. It does not wait to fill the limit or load additional pages once a relevant page is available. has_more conservatively retains the server page's backlog indicator, which may include handling events. Replay with the returned cursor preserves the ordinary at-least-once contract; the caller deduplicates instance/sequence. The initial readiness page can itself contain relevant events.

Empty readiness pages, transport comments and pages containing only seen/acknowledged events remain inside the adapter. Their validated cursors advance only this call's local read position. At the selected wait's expiry, return one compact {items:[],cursor,has_more:false,timed_out:true} using the last validated cursor. No heartbeat or intermediate progress becomes a tool result. A timeout result requires successful stream readiness; connection establishment failure or a caller deadline remains an error. Reads never mark messages seen/acknowledged, consume notes, change focus/pause/jobs, dispatch providers or write durable client state.

Lifetime and bounds

The adapter owns one bounded subscription and closes its connection on result, cancellation, error or expiry. Temporary transport closures and 502/503/504 gateway interruptions reconnect quietly from the last validated cursor with bounded backoff inside the original call. Reconnection does not reset the selected timer, aggregate wire budget or sequence validation. It does not share a global subscription, persist a cursor or resnapshot. Subsequent waits are explicit calls. An expired cursor returns resync_required; the caller obtains a fresh scoped snapshot and retains its pending inbox pages. Lost transport/error results leave the original caller cursor available for safe replay; successful socket writes never acknowledge handling.

The client bootstrap contract allows a bounded ten-second identity check while ordinary reads retain five-second limits. The wait itself has an outer total budget of selected wait plus five seconds; CLI/MCP enclose identity and waiting in the greater of that budget and fifteen seconds. Identity recovery consumes this same budget; after bootstrap takes B seconds, at most max(selected wait + five seconds, fifteen seconds) minus B remains for readiness and waiting, further limited by any earlier caller deadline. A quiet interval requires readiness plus the selected wait to fit within that remainder. For selected waits of ten seconds or longer, bootstrap and readiness share five seconds: bootstrap longer than five seconds minus readiness time causes a deadline error before the interval completes. For shorter waits, the fifteen-second floor allows more bootstrap time. The caller can retry with the original cursor. Stream headers and initial readiness have a five-second establishment bound, further constrained by the outer caller deadline. If establishment expires after reconnectable failures, return the last safe interruption and its saved-cursor recovery guidance; caller cancellation or the outer deadline takes precedence. Establishment expiry without a prior interruption remains a deadline error. After the first readiness page, one selected wait timer bounds all connections and reconnect delays; an earlier caller cancellation/deadline returns the existing safe read error. A shorter caller deadline does not reserve a complete quiet-wait interval: incoming messages may still return before it, and expiry remains a deadline error. A per-call HTTP override must not change another concurrent call's client timeout or transport. Cancellation closes the forwarded stream promptly without acknowledging messages.

Validate content type, initial readiness, SSE frame shape and cursor identity, exact event fields, bound project/recipient, strictly increasing sequences across pages and consistent page state before returning or advancing the local cursor. Each frame is at most 1 MiB and total consumed wire data is at most the existing 4 MiB client response budget, including ignored comments/pages. Oversize, malformed, duplicate/unknown fields, unsupported events fail safely without a partial success. Premature EOF reconnects only within the original budget; an unrecovered outage returns an error, never a successful quiet timeout. The stream's explicit safe error event retains scoped service error meanings. Do not echo untrusted raw transport or error content. Persistent transport is not permission to keep unbounded buffers or threads.

MCP discovery adds one read tool, bringing the total to 64 tools: 42 reads and 22 mutations. No protocol notifications or task extensions are required. Another tool on the same SDK session must remain usable while the wait is pending. CLI emits one final structured result; stderr contains only safe diagnostics.

Host capability and proof

A pending call can be placed in the background only when the actual host supports that execution mode. This implementation establishes neither unrelated model sampling during a pending MCP call, result delivery across turns nor idle-chat wakeup. Quiet service/SDK transport is useful independently of those capabilities; explicit inbox reads remain available. The adapter never claims a host capability from protocol support alone.

Focused proof covers initial/backlogged and later delivery, filtered handling-only pages, exact timeout cursor, no intermediate output, cancellation/release, revocation/isolation/instance checks, expiry, malformed/oversize/error/EOF streams, default/explicit bounds and invalid local arguments before credential/network access. Verify same-session concurrent MCP reads, bounded reconnects without repeated idle replay/provider work, normal-read deadlines unchanged and zero durable message effects. Actual packaged CLI/service/official-SDK proof is required before provider review, including a wait longer than the former four-second boundary, message delivery and cleanup. Model-host behavior and fleet throughput require separate evidence.

Executed proof

Clean source 9b8451d967bc9f83b252575d4a606ca5a39eaa33 passed full make check build with serial package scheduling (GOFLAGS=-p=1): 189 browser tests, all Go race tests and vet, formatting, documentation and 19 link tests, embedded assets and three release binaries. An initial parallel run timed out during setup of the existing source-refresh write-deadline test, before its handler ran. That unchanged case passed in isolation in 1.222 seconds, and the serial full rerun passed without changing product code, assertions or deadlines; the initial failure's cause remains unproven. The failed log is retained privately. Two independent bounded source inspections of client and adapter boundaries found no further actionable defect; they do not replace executable proof.

Four actual packaged CLI/service/official Go SDK groups passed first-run in 18.873 seconds. A selected 17-second CLI wait forwarded one real production keepalive while stdout/stderr stayed empty, then returned one 443-byte timeout result at 17005.493 ms with the exact last validated handling-event cursor. Backlogged and later messages, including a message already seen by another connection, returned compact new-message metadata without bodies or automatic continuation. The same MCP session completed a concurrent worker read in 47.648 ms, accepted cancellation and remained reusable; the forwarded stream closed within the asserted one-second bound. The SDK cancellation-return measurement is not an exact server-release latency claim.

Invalid local CLI/raw MCP calls with missing credentials made zero HTTP requests. Revocation, scoped/instance failures, explicit restart and original-cursor replay, retention expiry and explicit fresh-snapshot recovery passed with no read-owned durable effects or acknowledgments. Eleven stream requests closed; provider/Git/review executable traps stayed at zero. All three independent packaged binaries match the full-build artifacts, and all 504 tracked source/assets remained identical throughout proof. Owned processes, listeners and fixture state were removed.

These are local Linux transport/SDK observations. The intentional 17-second lifetime is separate from ordinary command latency; the slowest ordinary logged packaged subprocess was 55.914 ms on this developer machine. Default 25-second idle lifetime and adversarial malformed/oversize streams have focused proof. Installed model-host sampling, cross-turn delivery, idle wakeup, native platforms, fleet throughput, installed QA and operational cutover remain separate boundaries.

Shared input and budget proof

The typed client, CLI and MCP share input validation and budget calculation; MCP additionally caps explicit waits at 50 seconds before credentials or network access. External explicit zero values remain invalid; typed-client zero values still select the documented defaults. Focused normal/race checks pass across all three layers, including exact 4096-byte UTF-8 cursor acceptance, oversized-cursor refusal before credentials or HTTP, maximum 100/60 selection, quiet delivery and cancellation. Clean checkpoint f9cdc529925a0249401f784cf56c9caaf4978787 also passed canonical builds and the actual packaged daemon/CLI/MCP smoke in 0.201 seconds. This extraction does not change the host scheduling boundary.

MCP host-budget regression proof

The model-facing adapter now caps message waits and source/checkpoint result waits at 50 seconds while preserving CLI and typed-client limits. A boundary regression first failed for all four MCP tools accepting 51 seconds, then passed with matching discovery/parser bounds and a total service budget at most 55 seconds. Official-SDK checks refuse 51/60 before credentials or HTTP and accept/cancel the selected 50-second maximum. Focused race checks passed across adapter/client/CLI packages; normal source validation and ordinary reads retain their existing budgets.

Clean application source e93a760b73017093ec9fc358cefec932c3fc2e1c built all three packaged binaries offline. The actual packaged service/CLI/official-SDK smoke passed in 0.223 seconds, selecting the 50-second MCP maximum, completing a concurrent job read, and cancelling/releasing the pending stream. It does not measure a full 50-second quiet timeout or establish an installed host deadline.