-
Notifications
You must be signed in to change notification settings - Fork 57
Feat/events socket #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GeoffChurch
wants to merge
16
commits into
shell-pool:master
Choose a base branch
from
GeoffChurch:feat/events-socket
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/events socket #352
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5e302b6
feat(events): define push-event JSON schema
GeoffChurch bb71939
feat(events): add EventBus and sibling events socket listener
GeoffChurch fd40940
feat(events): publish deltas from session lifecycle mutations
GeoffChurch a8e11c0
feat(events): add `shpool events` subcommand
GeoffChurch cab78b5
test(events): integration tests for the events socket
GeoffChurch a336742
fix(events): de-duplicate lifecycle deltas; clean socket on signal exit
GeoffChurch 3f38bb7
refactor(events): trim event payloads to type fields only
GeoffChurch 0b99ca0
docs(events): add EVENTS.md describing the events protocol
GeoffChurch 47ac2d8
EVENTS.md: fix main socket description and remove "Ordering" section
GeoffChurch aff5279
events: polish error contexts, naming, and module boundary
GeoffChurch 4865abd
events: add tests for bus isolation, latency, and lock ordering
GeoffChurch 8f5e08c
events: replace thread-per-subscriber writers with a single-sink poll…
GeoffChurch 46e6047
tests(events): use daemon::Proc methods; rephrase invariant docstring
GeoffChurch 3647032
events: rename subscribe_to_stdout to run
GeoffChurch 8237a4d
events: polish docs, tests, and sink-loop buffer reuse
GeoffChurch 9047e3b
events: drop snapshot help; simplify stdout/wake/collect usage
GeoffChurch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Events | ||
|
|
||
| `shpool` exposes an event stream so that external programs can react to changes | ||
| without polling. This way, a program (e.g. a TUI) can call `shpool list` (or the | ||
| equivalent `ConnectHeader::List` request over the main socket; see the | ||
| [`shpool-protocol`](./shpool-protocol) crate) after each event so that its model | ||
| is always consistent with shpool's state. | ||
|
|
||
| ## The events socket | ||
|
|
||
| The daemon binds a sibling Unix socket next to the main shpool socket: | ||
|
|
||
| ```bash | ||
| <runtime_dir>/shpool/shpool.socket # main socket | ||
| <runtime_dir>/shpool/events.socket # events socket (this protocol) | ||
| ``` | ||
|
|
||
| A subscriber connects to `events.socket` and reads events. The daemon ignores anything written to the events socket, so for subscribers it's effectively read-only. | ||
|
|
||
| ## Event types | ||
|
|
||
| | `type` | Meaning | | ||
| | ------------------ | -------------------------------------------------------- | | ||
| | `session.created` | A new session was added to the table. | | ||
| | `session.attached` | A client attached or reattached to a session. | | ||
| | `session.detached` | A client disconnected from a still-running session. | | ||
| | `session.removed` | A session was removed (shell exited, killed, or reaped). | | ||
|
|
||
| Subscribers should ignore unknown `type` values so that future event types do | ||
| not break older consumers. | ||
|
|
||
| ## Wire format | ||
|
|
||
| The daemon writes one JSON object per line (JSONL). Each event looks like: | ||
|
|
||
| ```json | ||
| {"type":"<event-type>"} | ||
| ``` | ||
|
|
||
| There are no other fields. To learn what the event refers to (which session, | ||
| when, etc.), call `shpool list` (or use `ConnectHeader::List`). | ||
|
|
||
| The format is robust: literal newline characters only appear as delimiters | ||
| between events. Any newlines within JSON string values are automatically | ||
| escaped (as `\n`) by the daemon. | ||
|
|
||
| ## Subscribing | ||
|
|
||
| For ad-hoc use, `shpool events` connects to the events socket and prints each | ||
| event line to stdout, flushing after each line: | ||
|
|
||
| ```bash | ||
| shpool events | while read -r ev; do | ||
| echo "got: $ev" | ||
| shpool list | ||
| done | ||
|
|
||
| shpool events | jq . | ||
| ``` | ||
|
|
||
| ## Slow subscribers | ||
|
|
||
| Each subscriber has a bounded outbound queue. A subscriber that falls too far | ||
| behind is dropped by the daemon (in which case the subscriber can always reconnect). | ||
| There is no replay, so events that fired while a subscriber was disconnected are | ||
| lost. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.