Skip to content

docs(rfc): draft RFC-0004 — adopt Tokio as the Phase 1 async runtime - #61

Merged
gonzafg2 merged 4 commits into
mainfrom
rfc/0004-async-runtime-tokio
Jun 12, 2026
Merged

gonzafg2 merged 4 commits into
mainfrom
rfc/0004-async-runtime-tokio

Conversation

@gonzafg2

Copy link
Copy Markdown
Owner

Summary

Short RFC deciding the adoption of Tokio as the Phase 1 async runtime. The operative detail (version pin, six-feature allowlist, threading model, accept-loop shape) stays in ADR-0022 (#47), which becomes subsidiary to this RFC.

Motivation

A review finding on #47 (correct against the letter of the process) flagged that docs/rfcs/README.md routes "a new dependency that materially expands the trust base (anything in the crypto, networking, or process-spawning paths)" to the RFC lane — and the runtime is the networking path the entire pre-authentication surface flows through. RFC-0003 deliberately scoped only the cryptographic primitives. Rather than record the project's first silent exception to its own process, the adoption gets its RFC.

Comment period

The process sets a 14-day floor for non-trivial RFCs, shortenable when "the bar to do so [is] high and stated explicitly on the PR". Proposed grounds for shortening, for the maintainer to ratify or reject: the decision space is degenerate — Tokio is the de-facto standard runtime, the alternatives are in maintenance mode or over-specialised (analysed in the RFC), no community exists yet to consult (pre-alpha, single maintainer), and the decision blocks the first Phase 1 crate (#9). If ratified, please state the shortened period in a comment before merging.

Merge order

This PR → #47 (ADR-0022, re-anchored to this RFC) → #49 → #50, then Phase 1 implementation starts.

Type of change

  • Documentation only (RFC)

Checklist

  • Commits signed off under the DCO (git commit -s).
  • Conventional Commits.

Security considerations

The RFC's reference-level section records the trust-base impact (tokio + mio under the pre-auth path, internal unsafe permitted by ADR-0018's dependency carve-out) and the standing mitigations (cargo deny/audit in CI, feature allowlist, LTS pin with deliberate bumps).

The RFC process routes 'a new dependency that materially expands the
trust base (anything in the crypto, networking, or process-spawning
paths)' to the RFC lane, and the async runtime is the networking path
the entire pre-auth surface flows through. RFC-0003 is silent on it.
This short RFC decides the adoption; ADR-0022 (PR #47) remains the
subsidiary operative decision (version pin, feature allowlist,
threading model) and will cite it.

Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Jun 12, 2026
…C-0004

Review findings from #47, applied:

- The Send bound is imposed by tokio::spawn (identical on both
  schedulers), not by the runtime choice; what relaxes it is
  spawn_local/LocalSet and what skips it is not spawning at all. The
  accept loop becomes spawn-and-join (tokio::spawn(handle(..)).await):
  effective concurrency one, Send enforced from line one, and panic
  isolation per connection for free. Phase 2 removes the join.
- quantumssh-core's feature list gains rt: spawn_blocking and
  tokio::spawn are gated behind it; the previous list could not
  compile the exec model the ADR commits to.
- LTS wording aligned with Tokio's published policy (per-line
  end-of-support dates, at least a year of backports; README lists
  1.51.x until March 2027 — the date claim was correct).
- Sequential-loop slowloris window acknowledged in Negative: the
  timeout bounds one connection's hold, not a serialising adversary;
  accepted per threat model 8.3 until Phase 2's concurrent accept.
- Adoption re-anchored as subsidiary to RFC-0004 (#61); future-file
  references marked TBD.

Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Jun 12, 2026
…c audit boundary

Review findings from #49, applied:

- A second exec on the same channel (child running or exited) gets
  SSH_MSG_CHANNEL_FAILURE — the channel's single exec is consumed by
  the first accepted request; previously only 'other request types'
  were specified.
- One channel per CONNECTION LIFETIME: a CHANNEL_OPEN after the first
  channel's close handshake also gets OPEN_FAILURE, preserving the
  'exactly one exec per connection' invariant end to end; previously
  the rule was scoped to 'while a session channel is live'.
- The exec acceptance point is now explicitly the audit boundary,
  binding exec.started/exec.finished with authenticated_identity and
  executing_uid as separate structured fields and command never
  interpolated (ADR-0024, TBD in review; CLAUDE.md hard rule).

The ADR-0021 links resolve on this branch (merged to main); the
ADR-0022 links resolve once #47 merges first (merge order:

Signed-off-by: Gonzalo Fleming <[email protected]>
#61 RFC-0004 -> #47 -> this PR -> #50).
A new pin is 'now we decide Y' — ADR-0015 routes decision changes to
supersession; errata are only for factual corrections. Review finding
on #61, also applied to ADR-0022's matching sentence in #47.

Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Jun 12, 2026
Same ADR-0015 boundary fix as RFC-0004 (#61): a new pin is a decision
change, routed to supersession; errata are for factual corrections
only.

Signed-off-by: Gonzalo Fleming <[email protected]>
Review finding on #61: threat-model 3.2.4, 5.1.2 and 6.2 stated 'no
unsafe in the pre-authentication path' without the first-party
qualifier that ADR-0018 defines — a literal guarantee any dependency
with internal unsafe on that path (the RFC-0003 primitives included,
not just Tokio) would already read as violating, and 5.1.2 is framed
as an auditor test handle. The three passages now state the
first-party rule, name ADR-0018's forbid as the enforced mechanism,
and route dependency-internal unsafe through the RFC lane explicitly.
The RFC's trust-base section records that it carries this companion
qualification — the RFC PR being precisely the lane the threat
model's maintenance header requires for substantive edits.

Signed-off-by: Gonzalo Fleming <[email protected]>
Two review findings on #61: the server module and ADR-0022's feature
allowlist were described in present tense as existing artefacts; both
now use future tense with TBD/in-review markers per the CLAUDE.md
rule.

Signed-off-by: Gonzalo Fleming <[email protected]>
@claude

claude Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@gonzafg2
gonzafg2 merged commit f3e2e64 into main Jun 12, 2026
11 checks passed
gonzafg2 added a commit that referenced this pull request Jun 12, 2026
…#47)

* docs(adr): draft ADR-0022 — multi-threaded Tokio, minimal feature set

Fixes the Phase 1 async runtime: multi-threaded Tokio from the first
commit (chosen for its compile-time Send bound on transport futures,
not for parallelism), with a sequential accept loop and no spawn until
Phase 2. Pins tokio 1.51 (active LTS, backports through March 2027,
MSRV-1.92 compatible) with default-features = false and an explicit
six-feature allowlist: net, io-util, rt-multi-thread, macros, time,
sync. Excludes fs, process, and signal with rationale.

The Send-bound argument is the crux: a current_thread runtime would let
non-Send state into the type-state machine undetected and surface only
as a Phase 2 refactor. rt-multi-thread makes that a line-1 compile
error instead.

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): fix the Send-bound mechanism, add rt feature, anchor to RFC-0004

Review findings from #47, applied:

- The Send bound is imposed by tokio::spawn (identical on both
  schedulers), not by the runtime choice; what relaxes it is
  spawn_local/LocalSet and what skips it is not spawning at all. The
  accept loop becomes spawn-and-join (tokio::spawn(handle(..)).await):
  effective concurrency one, Send enforced from line one, and panic
  isolation per connection for free. Phase 2 removes the join.
- quantumssh-core's feature list gains rt: spawn_blocking and
  tokio::spawn are gated behind it; the previous list could not
  compile the exec model the ADR commits to.
- LTS wording aligned with Tokio's published policy (per-line
  end-of-support dates, at least a year of backports; README lists
  1.51.x until March 2027 — the date claim was correct).
- Sequential-loop slowloris window acknowledged in Negative: the
  timeout bounds one connection's hold, not a serialising adversary;
  accepted per threat model 8.3 until Phase 2's concurrent accept.
- Adoption re-anchored as subsidiary to RFC-0004 (#61); future-file
  references marked TBD.

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): version bumps supersede this ADR, they are not errata

Same ADR-0015 boundary fix as RFC-0004 (#61): a new pin is a decision
change, routed to supersession; errata are for factual corrections
only.

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): capture the JoinError instead of discarding it; fix the 5.1.3 deadline gap

Two review findings from #47, applied:

- The accept-loop snippet used 'let _ =', silently discarding the
  very JoinError the same sentence claimed gets logged. The loop now
  reads 'if let Err(join_err) = ... { emit connection.closed }' and
  the text makes capture-and-log a binding requirement.
- Threat model 5.1.3 requires configurable handshake deadlines with
  documented defaults; the ADR cited the section but specified
  neither. New binding detail: 30 seconds from accept to userauth
  completion, --handshake-timeout flag, default in --help; rate
  limits and half-open caps land with Phase 2's concurrent accept
  (sequential loop = effective cap of one).

Signed-off-by: Gonzalo Fleming <[email protected]>

---------

Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Jun 12, 2026
…#49)

* docs(adr): draft ADR-0023 — Phase 1 channel layer scope (single-exec)

Fulfils RFC-0003's deferred "ADR-TBD (scope of single-command
execution)". Phase 1 implements exactly one `session` channel per
connection carrying one `exec` request: eleven channel messages
(OPEN..FAILURE), exec-only requests, exit-status sent, and explicit
SSH_MSG_CHANNEL_FAILURE for pty-req/shell/subsystem/env/signal.

Settles the non-obvious bits the ADR-0020 interop gate needs: stdin
accepted, exit-status emitted before CLOSE, and real flow control
(2 MiB initial window / 32 KiB max packet, matching OpenSSH's
channels.h defaults so the interop client's assumptions hold). One
channel per connection; global requests refused; exit-signal and env
deferred to Phase 2. Child runs as the service-account UID per §8.12.

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): close the second-exec and channel-reuse gaps; bind the exec audit boundary

Review findings from #49, applied:

- A second exec on the same channel (child running or exited) gets
  SSH_MSG_CHANNEL_FAILURE — the channel's single exec is consumed by
  the first accepted request; previously only 'other request types'
  were specified.
- One channel per CONNECTION LIFETIME: a CHANNEL_OPEN after the first
  channel's close handshake also gets OPEN_FAILURE, preserving the
  'exactly one exec per connection' invariant end to end; previously
  the rule was scoped to 'while a session channel is live'.
- The exec acceptance point is now explicitly the audit boundary,
  binding exec.started/exec.finished with authenticated_identity and
  executing_uid as separate structured fields and command never
  interpolated (ADR-0024, TBD in review; CLAUDE.md hard rule).

The ADR-0021 links resolve on this branch (merged to main); the
ADR-0022 links resolve once #47 merges first (merge order:

Signed-off-by: Gonzalo Fleming <[email protected]>
#61 RFC-0004 -> #47 -> this PR -> #50).

* docs(adr): specify the inbound window discipline — bound, overrun disconnect, backpressure

Review finding from #49: 'flow control is real' covered outbound
correctness but not the receiver-side policy, which is the
security-relevant half. Now binding: per-channel buffered memory is
bounded by the advertised inbound window; a peer exceeding it
violates RFC 4254 5.2 and gets SSH_MSG_DISCONNECT
(SSH_DISCONNECT_PROTOCOL_ERROR) rather than over-buffering; inbound
WINDOW_ADJUST is granted only as the child's stdin consumes data, so
a stalled child backpressures the wire instead of growing a queue.

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): define hostile/out-of-order channel traffic and the stdin-stall semantics

Four review findings from #49, applied:

- Inbound EXTENDED_DATA rejected: RFC 4254 defines no client-to-server
  extended-data type, so message 95 inbound terminates the connection
  (PROTOCOL_ERROR) — no accept-and-branch path.
- Inbound DATA before exec is buffered within the window (legitimate
  stdin pipelining) and delivered when the child starts; discarded if
  the channel closes without an exec.
- DATA after the client's EOF violates RFC 4254 5.3 -> disconnect;
  client CLOSE with a live child (no prior EOF, RFC-permitted) closes
  stdin, terminates the child, replies CLOSE, frees the channel,
  omits exit-status — no orphaned child survives its channel.
- The stdin-ignoring-child window stall is documented as intentional
  backpressure (draining unread stdin would silently discard data and
  unbound the memory the window bounds); messages for unknown channel
  numbers fail closed with PROTOCOL_ERROR.

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): define the server-initiated half-close window

Review finding from #49: RFC 4254 5.3 lets the two CHANNEL_CLOSEs
cross in flight, so frames arriving after the server's CLOSE but
before the client's are legitimate — yet the child has exited and
there is no sink. Decision: accept and silently discard channel
messages during that window; free the channel on the client's CLOSE;
messages addressed to the freed channel number after that fall under
the unknown-channel rule and terminate the connection.

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): correct OPEN_FAILURE reason codes; audit record survives early close

Three review findings from #49, applied:

- RFC 4254 5.1 distinguishes the codes: non-session types (no Phase 1
  handler) get SSH_OPEN_UNKNOWN_CHANNEL_TYPE (3); a second session —
  understood but policy-refused — keeps ADMINISTRATIVELY_PROHIBITED
  (1). One code for both cases was a conformance bug.
- exec.finished is emitted on every path that produced exec.started,
  including client-initiated early close (with the terminated child's
  conventional non-zero exit status) — omitting the wire exit-status
  never skips the audit record.
- The audit-boundary sentence no longer cites TBD ADR-0024 as the
  normative authority ('per'): the binding authority is CLAUDE.md's
  hard rule; ADR-0024 (in review) fixes the full schema.

Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(adr): mark the ADR-0024 reference TBD per convention

Signed-off-by: Gonzalo Fleming <[email protected]>

---------

Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Jul 18, 2026
RFC-0004 merged as a draft in #61 while its subsidiary ADR-0022 was
still in review. ADR-0022 was accepted in the #86 governance sweep and
the Phase-1 implementation (Tokio runtime, M1-M6) has landed, so the
adoption decision is settled. Flip the Status field to Accepted,
matching the convention of RFCs 0005-0008.

Claude-Session: https://claude.ai/code/session_01J2SZwLuDm1KjfYyPM8npTa
Signed-off-by: Gonzalo Fleming <[email protected]>
gonzafg2 added a commit that referenced this pull request Jul 18, 2026
* docs(rfc): mark RFC-0010 as Accepted

RFC-0010 merged in #112; per the RFC process, merge is acceptance.
Flip the Status field to Accepted with the merge date, matching the
convention of RFCs 0005-0008.

Claude-Session: https://claude.ai/code/session_01J2SZwLuDm1KjfYyPM8npTa
Signed-off-by: Gonzalo Fleming <[email protected]>

* docs(rfc): mark RFC-0004 as Accepted

RFC-0004 merged as a draft in #61 while its subsidiary ADR-0022 was
still in review. ADR-0022 was accepted in the #86 governance sweep and
the Phase-1 implementation (Tokio runtime, M1-M6) has landed, so the
adoption decision is settled. Flip the Status field to Accepted,
matching the convention of RFCs 0005-0008.

Claude-Session: https://claude.ai/code/session_01J2SZwLuDm1KjfYyPM8npTa
Signed-off-by: Gonzalo Fleming <[email protected]>

---------

Signed-off-by: Gonzalo Fleming <[email protected]>
@gonzafg2
gonzafg2 deleted the rfc/0004-async-runtime-tokio branch July 18, 2026 04:15
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