Nerve and siphon¶
Signals travel to agent tentacles on the signal nerve. What a reflex does travels on the event nerve, and each channel draws what reaches it through its siphon. Feelers explains how a channel draws a run.
octomate.nerve ¶
The nerve: what a thread does, as it happens, for whoever is watching.
Publish and subscribe, keyed by channel, thread, user or habitat topics. The
nerve carries wire events, including habitat lifecycle observations. Local publishers and
subscribers use memory fibers by default; supplied fibers use the same lifecycle.
Wire events are the run's stream as a wire consumer sees it, and what the graph says around a
run — its start and end, a move, a failure, the reflex waking and falling
asleep, an authorization. Every way in and out is a stream end the nerve
hands over. A kick publishes on the send end of a stream opened on the thread
it was asked on, as impulses: an event and the address it happens at. The
nerve pumps the other end, delivering each impulse to the channel it happens
on and to the subscribers of its thread and of the asking thread, so a
console follows the kick wherever a move carries it. A channel holds one
subscription for all its threads and draws every run on them; it misses
nothing and holds nobody up, since what it has yet to read is kept for it. A
thread's subscriber — the console's live socket — reads the receive end of a
stream of its own, for as long as its block runs, and one that falls further
behind than its backlog reads what was held for it and is cut off, never
quietly skipped ahead. Each local stream is a fiber: a pair of buffered ends in
memory. Publishing is one way and knows nothing of who subscribed, and
nothing is kept for a reader that is not there: an event published to a
thread nobody subscribes to goes nowhere, and a console re-reads the thread
ledger when it opens. The one exception is asked for on both sides. A publisher
opened with retain has what it routes to the thread it was asked on kept, in
order, and that thread's subscriber opened with replay starts with what is
kept past the offset it names. The retaining publishers open on one thread keep
in one stream, which lasts until the last of them closes. The nerve does not
know what a block or an impulse stands for: whoever opens a block decides how
long what is said in it is worth keeping, and the reader counts its offset in
what is kept.
Nerve.deliver reaches every subscriber of exactly one topic. A publisher sends
user notifications by delivering separately to each authorized user's topic.
Nerve.publish owns channel and thread routing for kicks and native tails.
A nerve runs one way and carries one kind of envelope. Events run outbound, as
impulses, from whoever acted to whoever watches. Signals run inbound
to whoever is to act, on a nerve of their own over the same topics, so
a subscriber of one direction never reads the other. Kick routing belongs to
the outbound nerve alone: Nerve.publish takes impulses.
wire_impulse_adapter
module-attribute
¶
Impulse
dataclass
¶
Bases: Generic[EventT]
One event with an optional address and the routing metadata
used by Nerve.publish. Direct topic publication carries it unchanged.
Source code in octomate/nerve.py
ChannelTopic
dataclass
¶
ThreadTopic
dataclass
¶
UserTopic
dataclass
¶
HabitatTopic
dataclass
¶
InvocationTopic
dataclass
¶
AgentTopic
dataclass
¶
Nerve ¶
Bases: Generic[SentT]
Route one kind of payload, impulses or signals, through publishers and subscribers backed by any fiber.
Source code in octomate/nerve.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
subscribers
instance-attribute
¶
accept ¶
Have a fiber accept what is delivered to the topic, for the block.
The fiber stays its caller's to buffer and close; leaving only ends its deliveries.
Source code in octomate/nerve.py
deliver ¶
Fan out to every subscriber of one topic.
A slow local subscriber is cut off at its backlog. A full or broken peer fiber is disconnected independently; other subscribers keep receiving. Message handling belongs to receivers; unobserved publications are dropped.
Source code in octomate/nerve.py
dispatch ¶
Send to exactly one ready receiver, refusing missing or ambiguous delivery.
Source code in octomate/nerve.py
subscribe
async
¶
subscribe(
topic: Topic,
*,
backlog: float = math.inf,
fiber: Fiber[SentT] | None = None,
replay: int | None = None,
) -> AsyncGenerator[ObjectReceiveStream[SentT]]
The receive end of a stream of what the topic is sent, from now until
the block ends. Nothing is dropped: a reader that falls more than
backlog behind reads what was held for it, and then its stream ends.
With replay, the stream starts with what is retained for the topic
past that many impulses, before what arrives; 0 starts with all of it.
They are read one at a time and do not count against backlog. A
supplied fiber cannot replay.
ChannelTopic names a channel's addresses, ThreadTopic wraps one
ThreadKey, UserTopic wraps a registered user's UUID, and HabitatTopic
names the habitat lifecycle. Receivers select the events they handle.
Publishers choose authorized topics before publishing; the nerve does
not filter subscribers within a topic.
A supplied fiber receives the same as a local subscription. Its caller owns its buffering and closure; leaving only unsubscribes it.
Source code in octomate/nerve.py
publish
async
¶
publish(
origin: ChannelAddress | Topic | None,
*,
fiber: Fiber[Impulse[NerveEventT]] | None = None,
retain: bool = False,
) -> AsyncGenerator[ObjectSendStream[Impulse[NerveEventT]]]
A buffered publisher for kicks and native tails, open for the block.
A kick names the thread it was asked on as origin; a native tail names
its native thread and scopes the stream to its connection. The publisher
stamps that origin on each impulse and publishes separately to its channel,
its destination thread, and its origin thread unless private. Each distinct
topic receives one publication.
Sending may wait for the pump, never for a subscriber. Everything sent before the block ends is published; closing emits no lifecycle events of its own.
With retain, what an addressed publisher routes to the thread it was
asked on is kept for that thread's replaying subscribers. The retaining
publishers open on one thread keep in one stream, in the order the nerve
routed, and it is dropped when the last of them closes: what one kept
outlasts its block while another is still open there.
A topic publishes impulses unchanged to that topic. A supplied fiber is read for the block's lifetime and remains owned by its caller. Its incoming impulses are delivered to subscribers on the core-bound topic.
Source code in octomate/nerve.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
Nerves
dataclass
¶
The host's independent inbound signals and outbound event stream.
Source code in octomate/nerve.py
octomate.tentacles.siphon ¶
A channel's siphon: where what the nerve carries leaves for the platform.
An octopus pushes its ink out through its siphon. A channel's siphon pushes out what the nerve carries to it, through the channel's feelers — a run as a timeline when the channel streams, or its sends, batches and reply when it does not, and around runs a move's line, a failure, a send, an authorization. It holds the channel's subscription to its own addresses, and draws each thread in order in a lane of its own, so a slow thread holds up no other. A row the graph recorded comes with its id, and is marked with the platform id it was rendered as.
Siphon ¶
Draws what the nerve carries to one channel, thread by thread.
Source code in octomate/tentacles/siphon.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
subscription
instance-attribute
¶
read
async
¶
Hand each impulse to its thread's lane, opening one where none is.
Source code in octomate/tentacles/siphon.py
draw
async
¶
Draw one thread's impulses in order, and close the lane once nothing is left in it. A rendering that fails is logged and never ends the lane.
Source code in octomate/tentacles/siphon.py
feel
async
¶
Draw one impulse; a run's start draws the whole run, through its end.
Source code in octomate/tentacles/siphon.py
run
async
¶
Draw one agent run from the lane, up to its end: as a timeline when the channel streams, else quietly. What a failed rendering left unread is drained, so the lane resumes after the run.
Source code in octomate/tentacles/siphon.py
quietly
async
¶
A run on a channel that does not stream: its sends, batches and authorizations as they come, then its reply once. Answers the platform id the reply was posted as.
Source code in octomate/tentacles/siphon.py
mark
async
¶
Name the platform message a recorded row was rendered as.