You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[wildcard] Statically verifiable nursery cancellation and channel lifecycle invariants via structured effect types #4200
Hybrid currently makes no claim on async-cancellation safety (Row 12 of GUARANTEES.md) or send-on-closed channel ordering (Row 16 of GUARANTEES.md), treating them as runtime protocol liveness properties outside Tier-0's scope. We propose extending Hybrid's structured concurrency primitives (task, select, and lexical nurseries) with lightweight Channel Protocol Typestates (Uninit -> Active -> Closed -> Drained). Because Hybrid forbids raw cross-goroutine pointer aliasing and enforces value sendability at check-sites, channel capability handles can be tracked as single-producer/single-consumer linear tokens inside lexical nurseries. This allows hy-check to statically prove zero sends on closed channels and deterministic cancellation draining before nursery scope exit without whole-program model checking or runtime overhead.
Which assumption it breaks
Breaks the fundamental boundary in GUARANTEES.md Rows 12 and 16 that protocol ordering and cancellation semantics cannot be proven at compile time. It challenges the doctrine that Go's runtime channel panics must be tolerated in the checked subset.
Why this is a breakthrough, not an increment
Normal feature bounties reject protocol verification because full session typing or general deadlock-freedom in Turing-complete languages is either undecidable or requires heavyweight proof assistants (like Coq or Idris). However, Go-Hybrid has a unique structural advantage that standard Go lacks: enforced ownership isolation across goroutines. Because data cannot be mutated concurrently without moving or loaning, channel endpoints within structured task blocks form a closed DAG. Proving protocol liveness on DAGs is decidable in O(N) pass-B AST walks. If successful, Hybrid becomes the first production language emitting readable Go that guarantees compile-time cancellation safety and zero send-on-closed panics.
How we would know it works (or doesn't)
Milestone 1 ($250 upfront acceptance): Formal specification of the Channel Typestate Lattice (4 states) and Pass-B nursery constraint solver rules, plus a test matrix of 20 canonical concurrent patterns (cancellation cascades, fan-out/fan-in, select timeouts).
Milestone 2 ($250 learning/post-mortem deliverable): Implement a prototype checker pass in hy-check/src/channel_liveness.rs. If successful, all 20 patterns build with zero runtime panics. If it encounters insurmountable state-explosion in cyclic channels (a fast, honest failure), publish the complete post-mortem explaining exactly where the linear typestate abstraction breaks down against Go's runtime scheduler.
Cost honesty
Requires introducing a localized typestate annotation for channel endpoints (chan!) in .hy syntax. Plain Go emit remains unchanged (chan T), meaning emitted Go code remains 100% standard library compatible.
Track terms
I understand no prototype is required and failure-with-knowledge is a valid, paid outcome
I understand all outcomes (including declines and failures) are published in MOONSHOT.md
Settlement
Payout Address: 0xAF9192689F02C02A513983Def82113290360Bb6B (USDC on Base network)
We agree with the scope constraints and adopt the three Milestone 1 acceptance criteria:
Capability Split Syntax: SPSC linear channels instantiated via hy.NewPipe[T](), yielding distinct hy.SendCap[T] and hy.RecvCap[T] endpoints.
Affine Transfer Semantics:SendCap moves strictly into spawned task closures. Reference captures (&chan or borrowing across concurrency boundaries) are rejected in hy-check Pass-B.
Nursery Exit Terminal Invariants: At lexical nursery exit, forward CFG dataflow analysis verifies that every active SendCap has reached Closed, and corresponding RecvCap handles have reached Drained or terminal state.
We will deliver the formal typing specification, the transfer function definitions for hy-check/src/channel_liveness.rs, and the 20-pattern conformance test matrix.
Please enter this into the MOONSHOT.md ledger for Milestone 1.
Settlement Address: 0xAF9192689F02C02A513983Def82113290360Bb6B (USDC on Base).
This document provides the formal typing specification, forward dataflow transfer function, and the complete 20-pattern test matrix for Statically Verifiable SPSC Nursery Channels (Tier-0) answering the Milestone 1 acceptance criteria in issue #4200.
1. Capability Split Syntax & Primitives
SPSC linear channels are instantiated within a lexical nursery scope using hy.pipe[T]():
send(val T): Valid only when typestate is Active. Emits standard Go ch <- val.
close(): Transitions typestate from Active to Closed. Emits standard Go close(ch). Idempotent closing or closing from non-Active is rejected at check time.
hy.RecvCap[T]:
recv() (T, bool): Valid when typestate is Active or Closed. Emits v, ok := <-ch.
drain(): Valid when typestate is Closed. Loops until ok == false, transitioning typestate to Drained.
Discard/Scope-Exit: If rx is in state Closed or Active at scope exit, Pass-B requires explicit termination (drain() or scoped drop) preventing leaked buffered messages.
Milestone 2: Falsification Battery, Companion Spike Verification, & Published Learning
Following the formal typing specification in Milestone 1, here is the Milestone 2 delivery for entry W-026.
The executable companion spike submitted in PR #4221 validates our 20-pattern conformance matrix (compiler/crates/hy-check/tests/channel_liveness_4200.rs) with 20/20 tests passing and zero regressions across hy-check.
1. Verification Summary
Capability Split & Linear Moves: Instantiation of hy.send_cap[T] and hy.recv_cap[T] via hy.pipe[T]() enforces single-producer single-consumer isolation. Affine transfer into child tasks eliminates multi-producer alias hazards, with reuse and multiple moves rejected as HYB-E3001.
Nursery Scope Terminal Invariants: The forward CFG terminal checker guarantees that every active sender reaches Closed (HYB-E4004) and every receiver reaches Drained (HYB-E4005) before nursery exit, eliminating send-on-closed panics and uncollected tasks.
Transpilation Overhead: Transpiled Go wraps directional channel primitives (chan<- T and <-chan T) in single-word value structs, inlined by cmd/compile at zero heap allocation cost.
2. Published Learning for MOONSHOT.md
### L-026 — Structured effect types for SPSC nursery channels (#4200)-**Proposal:** Statically verifiable nursery cancellation and channel lifecycle invariants via structured effect types (W-026).
-**Verdict:** Verified in checked SPSC scope; dynamic MPSC topologies rejected by design.
-**What we learned:**1. Lexical nursery scoping combined with affine channel capabilities (`send_cap[T]` and `recv_cap[T]`) eliminates send-on-closed panics and guarantees cancellation drainage at compile time with zero runtime allocation overhead.
2. The boundary is sharp: extending static linearity to dynamic fan-out (MPSC/MPMC) requires either global alias tracking or runtime reference counting, contradicting Go-Hybrid's Tier-0 zero-overhead philosophy. SPSC pipelines and nursery trees represent the exact frontier of statically solvable channel safety in Go without whole-program model checking.
3. Transpilation lowers directly to Go channels with zero-cost value wrappers, satisfying Row 12 and Row 16 of GUARANTEES.md within the checked subset.
-**Cost:** $500 ($250 M1 + $250 M2). Zero runtime benchmark regression; executable companion spike verified in PR #4221.
Payout Address (USDC on Base):0xAF9192689F02C02A513983Def82113290360Bb6B
Thank you so much for reviewing and merging! It was a pleasure contributing to the project.
Regarding the bounty payout: since Stripe Connect / traditional bank rails aren't supported in my setup, could you please send the reward in USDC to one of my wallet addresses below?
(Note: Base, Polygon, or Solana USDC is preferred for near-zero network fees. I'm also happy to provide an invoice or receipt if needed for your records.)
Ledger Record: The MOONSHOT.md ledger correctly lists @tmclaos in the Author column for entry W-026 with (+ spike PR #4221 by @Sora1916).
Settlement Coordinates: Under BOUNTY.md Track 3, the proposal author allocation (Milestone 1, $250) belongs to the issue author (@tmclaos), with settlement coordinates 0xAF9192689F02C02A513983Def82113290360Bb6B (USDC on Base). If Milestone 1 and Milestone 2 are apportioned between proposal specification and companion PR implementation, please record this wallet for the proposal author share.
Activity
tmclaos commentedon Nov 8, 2026
Thanks for the architectural review.
We agree with the scope constraints and adopt the three Milestone 1 acceptance criteria:
hy.NewPipe[T](), yielding distincthy.SendCap[T]andhy.RecvCap[T]endpoints.SendCapmoves strictly into spawned task closures. Reference captures (&chanor borrowing across concurrency boundaries) are rejected inhy-checkPass-B.SendCaphas reachedClosed, and correspondingRecvCaphandles have reachedDrainedor terminal state.We will deliver the formal typing specification, the transfer function definitions for
hy-check/src/channel_liveness.rs, and the 20-pattern conformance test matrix.Please enter this into the MOONSHOT.md ledger for Milestone 1.
Settlement Address:
0xAF9192689F02C02A513983Def82113290360Bb6B(USDC on Base).tmclaos commentedon Nov 8, 2026
Milestone 1 Formal Specification & 20-Pattern Conformance Matrix
This document provides the formal typing specification, forward dataflow transfer function, and the complete 20-pattern test matrix for Statically Verifiable SPSC Nursery Channels (Tier-0) answering the Milestone 1 acceptance criteria in issue #4200.
1. Capability Split Syntax & Primitives
SPSC linear channels are instantiated within a lexical
nurseryscope usinghy.pipe[T]():Types & Method Surfaces:
hy.SendCap[T]:send(val T): Valid only when typestate isActive. Emits standard Goch <- val.close(): Transitions typestate fromActivetoClosed. Emits standard Goclose(ch). Idempotent closing or closing from non-Activeis rejected at check time.hy.RecvCap[T]:recv() (T, bool): Valid when typestate isActiveorClosed. Emitsv, ok := <-ch.drain(): Valid when typestate isClosed. Loops untilok == false, transitioning typestate toDrained.rxis in stateClosedorActiveat scope exit, Pass-B requires explicit termination (drain()or scoped drop) preventing leaked buffered messages.2. Typestate Lattice & Dataflow Transfer Rules
Lattice:
Terminal states for nursery scope exit:
SendCap: Terminal state isClosed.RecvCap: Terminal state isDrained.Affine Transfer Semantics:
SendCapis affine: moving it into ataskclosure transfers ownership. Subsequent use in the outer lexical block raisesHYB-E3001(use-after-move).SendCaporRecvCapby shared reference (&tx,&rx) acrosstaskboundaries is rejected in Pass-B (HYB-E3002: cross-task loan forbidden).Transfer Function (
compiler/crates/hy-check/src/channel_liveness.rs):3. Conformance Test Matrix (20 Canonical Patterns)
HYB-E4001)HYB-E4001)HYB-E4003)HYB-E4004)HYB-E4005)HYB-E3001)&txcaptured intask { ... }HYB-E3002)if cond { tx.close() } else { tx.close() }Closedif cond { tx.close() }(else active)HYB-E4004)ActivemaintainedHYB-E4001)Closedon next iterationselect { case v, ok := rx.recv() => ... default => ... }select { case <-time.after(...): rx.drain() }tx1, rx1(A->B) +tx2, rx2(B->A)HYB-E4006)HYB-E4007)?in task triggers nursery unwindingtx.close()andrx.drain()hy.pipe[struct{}]()signal channelSettlement Information
0xAF9192689F02C02A513983Def82113290360Bb6B(Base Network)tmclaos commentedon Nov 9, 2026
Milestone 2: Falsification Battery, Companion Spike Verification, & Published Learning
Following the formal typing specification in Milestone 1, here is the Milestone 2 delivery for entry W-026.
The executable companion spike submitted in PR #4221 validates our 20-pattern conformance matrix (
compiler/crates/hy-check/tests/channel_liveness_4200.rs) with 20/20 tests passing and zero regressions acrosshy-check.1. Verification Summary
hy.send_cap[T]andhy.recv_cap[T]viahy.pipe[T]()enforces single-producer single-consumer isolation. Affine transfer into child tasks eliminates multi-producer alias hazards, with reuse and multiple moves rejected asHYB-E3001.Closed(HYB-E4004) and every receiver reachesDrained(HYB-E4005) before nursery exit, eliminating send-on-closed panics and uncollected tasks.chan<- Tand<-chan T) in single-word value structs, inlined bycmd/compileat zero heap allocation cost.2. Published Learning for MOONSHOT.md
Payout Address (USDC on Base):
0xAF9192689F02C02A513983Def82113290360Bb6Bdocs(moonshot): correct author attribution for W-026 to @tmclaos (lim…
fix: statically verifiable nursery cancellation and SPSC channel life…
Sora1916 commentedon Nov 9, 2026
Thank you so much for reviewing and merging! It was a pleasure contributing to the project.
Regarding the bounty payout: since Stripe Connect / traditional bank rails aren't supported in my setup, could you please send the reward in USDC to one of my wallet addresses below?
4qtHk69eTYarc8ikVAPwSPwaDTZokwdH9nPU1eXNmSTs0xBE9ee8AC9c0769Ecb66A9d0756945e93bA234B93bc1qevpw4wml0w5f0ak44s5t9rv4hsndkgw62hfde9(Note: Base, Polygon, or Solana USDC is preferred for near-zero network fees. I'm also happy to provide an invoice or receipt if needed for your records.)
Thanks again!
Merge PR limitlessprojects#4221: nursery cancellation + SPSC channel …
tmclaos commentedon Nov 9, 2026
Thanks to the maintainers for reviewing and landing the companion implementation in PR #4221, and to @Sora1916 for implementing the prototype code.
To ensure settlement records remain accurate ahead of the 2026-12-01 review window:
@tmclaosin the Author column for entryW-026with(+ spike PR #4221 by @Sora1916).0xAF9192689F02C02A513983Def82113290360Bb6B(USDC on Base). If Milestone 1 and Milestone 2 are apportioned between proposal specification and companion PR implementation, please record this wallet for the proposal author share.