Repository navigation
feat(triggers): receiver notices, 25h dedup, hello topics, ack outbox, and receiver module (RFC 0004 Slice 4) - #382
Merged
Merged
Conversation
`trigger add` writes the name into a rule and the daemon will match a notice's receiver and say each receiver's topics in its hello by it: one function, so the two can never disagree. `hostOf` in the CLI's triggers.ts is gone, its callers moved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
- control/notices.ts: `takeNotice`, the id, the switch, the shape, the expiry, the 25-hour dedup and the match in that order; `NoticeSeen`, ids per receiver appended and synced before anything runs, compacted at start and daily, at most NOTICE_SEEN_MAX live per receiver; `NoticeAckOutbox`, one ack waiting per notice (a final replaces `taken`, a `duplicate` never goes out ahead of what waits), dropped past 25 hours. - The engine saves a waiting or queued run before it says `taken`: a crash between the two can no longer leave a `taken` with no run to give the final ack. - The conformance scenarios run through `takeNotice`; the test's own copy of steps 1 to 6 is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
packages/receiver/src/notices.ts keeps one machine's notices: what its last hello allows (`onHello`), a notice offered on a listed topic, one per topic and subject, 200 at most (`offer`), the 50 oldest for a poll (`forPoll`), and the machine's acks, read against the closed ack shape (`onAcks`): `taken` pauses delivery until expiry, a final ends it, and `duplicate` never replaces an outcome already recorded. Pure; a file pair writes the state whole, 0600. The receiver's `@sessionpipe/core/schema` path now points at the built declarations, as the CLI's does: nothing imported it before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…s hello
- Every hello carries `triggers` (ControlHello field 18): the engine's word
for the pairing's name when this daemon holds the rules' claim and the
name is that pairing's alone, off otherwise. Sent at once when the engine
says it changed, or a pairing's name changes on reload; hellos go one
round at a time (single flight with a dirty bit), so on, off, on ends on.
- A poll answer's notices, after its messages: `takeNotice` for each of the
first 50, `fire` into the engine, every outcome kept in the notice-ack
outbox and sent to `POST {control}/notices/ack` 50 at a time. A poll that
carried notices waits for its acks (3 s at most) and then 1 s more.
- Before taking notices, the rules file's stat is compared with the one last
read (`rulesStamp`): `trigger off` holds before the 5-second watcher looks.
- A daemon without the claim takes no notice, acks none and writes neither
notice file. Two pairings on one host name neither triggers a rule.
- FakeReceiver keeps notices through the reference receiver's own module;
`notify`, `rawNotices` and `noticeAckStatus` drive the live tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
The `?? ""` of the ask chain and the case with no `from` were reached by no test (handlers.ts:247, 252 on 1a5e5f8 too), which left branch coverage at 98.69% for that file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
trigger-notices.md no longer says nothing runs on a notice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…pairing) - A notice sent again while its run is still looking (a slow sign-in check before `taken`) is held, not acked `duplicate`: the engine says which notices it has in hand with nothing said yet (`inHand`), and `takeNotice` holds those. A live test with a 1.5 s sign-in look fails without it. - NoticeAckOutbox: indexed by receiver and id (a new ack is one append and one map entry), at most NOTICE_ACK_MAX (2 000) per receiver, the oldest neither `ran` nor `taken` giving way first; every change on disk before it is made in memory, rewritten through core's writeWhole; one ack per notice again when the file is read back. - A flush whose outbox write fails is said in the log and tried again in 5 s; it never rejects into nothing. - NoticeSeen's compaction writes a synced file beside the old one and renames it, so a power cut can't leave it empty. - A notice's acks go back to the pairing it came from, kept from the poll until its final ack, even when a second pairing joins its host. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
`receiverName("file:///etc/passwd")` was "", now null.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
A second, different final after `ran` is not believed: the session it ran in stays. writeMachineNotices makes the file's folder (0700) before writing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
…fixes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: kombuchapunk <35040017+kombuchapunk@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Completes Triggers (RFC 0004) Slice 4 by wiring receiver notices end-to-end across
packages/core,packages/cli(ControlDaemon+TriggerEngine), andpackages/receiver.Closes #339
Key Changes
packages/core/src/triggers/receiver.ts):receiverName(url)shared bytrigger addandControlDaemon(rejecting authority-less URIs and IPv6 brackets cleanly).packages/cli/src/control/notices.ts,daemon.ts,triggers.ts):takeNotice()followingCONTROL.md§14.7 steps 1–6 in exact order, replacing the test-only conformance shim so all 15conformance/triggers/*.jsonscenarios run through production code.NoticeSeen(25-hour ULID dedup store in<state>/control/notices-seen.jsonl,fsyncSyncon append and compaction,NOTICE_SEEN_MAX = 20_000per receiver, torn-line tolerance).NoticeAckOutbox(chunks of 50, 25-hour pruning,NOTICE_ACK_MAX = 2_000per receiver with O(1) lookup preservingran/takenunder hostile floods,writeWhole()Windows-safe atomic writes committed before in-memory mutation, safe retry on failed flush without unhandled rejections).inHand) before its first ack so slow sign-in lookups can never emitduplicateahead oftaken/ran.taken, and routes final acks back to the exact originating pairing even if a second pairing is added on the same host.helloNow()with dirty bit sendingControlHello.triggers(field 18, per-receiver topics only),stat-basedtriggers.jsonreload before each poll's notices (closing the 5swatchFilegap),pollLoopnotice ingestion (≤50/poll, messages handled first),POST {control}/notices/ackflushing, and strict no-op behavior for non-claim daemons.packages/receiver/src/notices.ts) +FakeReceiver:onHello,offer,forPoll,onAcks, plus0600writeMachineNotices(creating parent dir0700+writeWhole()), enforcing topic allowlist, latest-per-(topic, subject)200-cap queue, andranoutcome preservation.FakeReceiverto productionpackages/receiver/src/notices.tswith live HTTP integration tests covering all adversarial scenarios..changeset/triggers.md(sessionpipe,sessionpipe-core,sessionpipe-receiver).Verification
xhigh), built by Opus 5.5, and adversarially stress-tested (14/14 live SIGKILL/HTTP/WebAuthn probes) by Gemini 4 Neon.npm run lint(0 errors, 0 new warnings),npm run typecheck,npm run build,npm run schemas -- --check(31 files),npm run conformance(510 ok),npm run fixture-scan(421 clean), and full monoreponpm run test:coverage(5,419 tests, 100% Stmts / Branch / Funcs / Lines).