Repository navigation
feat(schedule): fire-result delivery — a scheduled fire reports back into the originating chat, live in mecatui - #311
Merged
Merged
Conversation
A scheduled fire reports its result back into the originating conversation, rendered live in the operator's mecatui. 3 waves: engine/store surface, embedded TUI live card, remote wire subscription. Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
A pure renderer sibling to renderCarriedContext that wraps a fire's terminal EvResult (schedule name, fire id, stop reason, final text) in a FENCED-UNTRUSTED harness note using the exact agent.FenceUntrusted + agent.NeutraliseFraming discipline. - Provenance header names the schedule + fire id; the WHOLE header (incl. the model-authored schedule name) is passed through NeutraliseFraming and placed INSIDE the FenceUntrusted block. - Fire's final text is rune-clamped to fireDeliveryMaxRunes (10k). - Empty-terminal fire still renders a note carrying the stop reason. - Forged <<<UNTRUSTED markers / harness section headers in the fire's text or schedule name are neutralised. Pinned by 5 scenario tests: - TestFireDelivery_Scenario2_RenderFencesOutcome - TestFireDelivery_Scenario2_NeutralisesForgedFraming - TestFireDelivery_Scenario2_ClampsToRuneBudget - TestFireDelivery_Scenario2_EmptyTerminalStatesStopReason - TestFireDelivery_Scenario2_ProvenanceHeaderNeutralised Co-Authored-By: Jaos Hantor <[email protected]>
…m validation Add OriginSessionID session.SessionID to port.ScheduleSpec with field-by-field contract doc (empty = no delivery; metadata-only, never rendered into a prompt). Wire create-seam validation in validateScheduleSpec: a non-empty OriginSessionID that names a non-existent session is rejected fail-closed with ErrInvalidArgument. - AC1.2: out-of-band creates persist empty OriginSessionID, unchanged. - AC1.3: unknown origin rejected fail-closed at the create seam. Port field cyclomatic complexity is kept below 20 by extracting the validation into validateScheduleOrigin. Co-Authored-By: Claude <[email protected]>
…/ ADR 0027 List 1+2) The pending-delivery queue is a new DURABLE per-session structure keyed on the ORIGIN session id (not a per-Run registry): a note queued during one run drains on the origin's next run-entry if the current run ends first — the exactly-once ledger is session-scoped. It holds the opaque rendered note text (produced by the delivery renderer, task 03) plus a monotonic per-session sequence that is the exactly-once ledger key. It does NOT call the renderer. - engine/port/delivery_queue.go: a narrow `port.DeliveryQueue` port (Enqueue, Pending, MarkDelivered) + the `DeliveryNote` value type + `NopDeliveryQueue` (the byte-identical no-delivery default). The loop stays storage-agnostic: the fire path ENQUEUEs, the turn-boundary drain + run-entry funnel DEQUEUE. - internal/app/delivery_queue.go: the in-memory reference (`InMemoryDeliveryQueue`, the memstore-tier default — honest degradation to empty across a restart) + the DURABLE file-backed adapter (`FileDeliveryQueue`, the jsonlstore `.events.jsonl` precedent applied to pending delivery: a per-session `.delivery.jsonl` append-only enqueue log + a `.delivery.ledger.json` delivered-seq ledger; Pending = log − ledger; the seq is DERIVED from the durable log so a restart does not re-mint seq 1). A bounded backlog cap drops the OLDEST pending note with a WARN via the injected port.Diagnostics. - engine/api/port.txt + engine/CHANGELOG.md: the Added (minor) engine-API surface (a new interface + value type + no-op default), regenerated via `task api:update`. - docs/adr/0027-cloud-native.md: List 1 row 34 (resource inventory) + List 2 row 23 (persist-in-snapshot rehydrate-fidelity decision), per the inventory discipline. AC4.2 ledger half / AC4.3 backlog half / AC4.5 pinned by the named scenario tests (mutation-verified per leg). Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…-time) Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…e-result-delivery Adds SessionOriginScheduleManager (a port.ScheduleManager wrapper) that holds the current origin session id via sync/atomic.Pointer and stamps every CreateSchedule call's OriginSessionID from the bound id before delegating. The OriginBinder interface on Deps is called in startRun so the executing session id is captured at run boundary. - engine/agent/sessionorigin.go — wrapper + OriginBinder interface - engine/agent/loop.go — Deps.OriginBinder field + startRun binding - internal/app/catalog.go — wrap manager, register as OriginBinder - AC1.1: TestFireDelivery_Scenario1_CreateCapturesOriginSession - AC1.4: TestFireDelivery_Scenario1_OriginNotModelForgeable - AC1.5: TestFireDelivery_Scenario1_OriginIDNotModelVisible Co-Authored-By: AI assistant
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…ain (task 05) ADR 0075 Scenario 3+4: after a fire with a non-empty OriginSessionID reaches terminal + RecordFire, render the outcome as a fenced-untrusted note, enqueue it to the durable DeliveryQueue, and drive delivery into the origin (StartRunContent/loadAndReopen for idle/terminal; the loop's Step 2a drain for busy/awaiting). Decoupled from the fire's success. Co-Authored-By: mecatl <[email protected]>
… flake deliverFireResult drained run.Events() only to first EvResult then called FinishRun. The terminal session snapshot is persisted by save() AFTER emitResult in terminateComplete (engine/agent/loop.go:2202-2203), and the run goroutine's deferred close(r.events) fires only after body() returns (loop.go:958). Breaking at EvResult races the save() — a caller's immediate GetSession could see the pre-persist snapshot. Fix: drain to channel-close (for range run.Events()) so the drain blocks until save() has settled. This matches the FireFunc contract at scheduler_fire.go:144 and the test helpers' drainDeliveryRun discipline. Also fix pre-existing lint: remove unnecessary session.SessionID conversion, rename unused errQueue receiver, format ServerConfig literal. Co-Authored-By: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…Scenario 5) The Service exposes Subscribe/PublishSessionEvent — a per-session merged live event stream a connected embedded mecatui holds open. The delivery driver publishes each delivery-run event onto the origin's subscription so the TUI renders the delivery card live. Non-blocking drain-to-discard; idempotent unsub; ADR 0027 List 1 row 35. Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…layer) DeliveryNoteMsg projected from a delivery EvUserPrompt (the [scheduled task <name> (fire <id>)] header renderFireDelivery emits), rendered as a distinct card (scheduled-task affordance + schedule name) separate from user prompts and model text. Live + replay paths both render it. AC5.2/AC5.4 pin the distinct provenance + reconnect replay. Co-Authored-By: mecatl <[email protected]>
The embedded TUI dials its server over gRPC, so the in-process subscription (06) is unreachable without a wire bridge. 07b unifies the embedded + remote live card over one StreamSessionLive RPC. Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…sk 07b part 1) A server-streaming per-session live event subscription on HarnessService, backed by Service.Subscribe/PublishSessionEvent (task 06). The live-wire log-only skip is amended for the delivery case only (the delivery's EvUserPrompt relays the note; EvApproval/EvCompactionArchive stay skipped). Composition wires SetDeliverFireResult + the durable DeliveryQueue into the engine Deps so fires deliver and the busy/awaiting drain works. Co-Authored-By: mecatl <[email protected]>
A third parallel fan-in seam (liveMsg/waitLiveCmd/updateLiveMsg, gen-guarded) mirrors the replay seam: the TUI arms a StreamSessionLive feed for the active session and renders delivery events (DeliveryNoteMsg → addDelivery) live, with no operator input. LiveStreamer deps interface; arm on session-ready/endRun, disarm on session switch/reset. Co-Authored-By: mecatl <[email protected]>
…sport parity - TestFireDelivery_Scenario5_ConnectedTUIRendersDeliveryLive pushes a delivery EvUserPrompt through the live subscription bridge (updateLiveMsg) and asserts a blockDelivery card lands in the conversation with no operator input. - TestFireDelivery_Scenario6_TransportProjectionParity proves the SAME delivery event produces the SAME delivery-card block via the live path (updateLiveMsg) and the replay path (applyReplayEvent). Co-Authored-By: mecatl
Co-Authored-By: mecatl <[email protected]>
…ied embedded+remote) Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
…ouble-record TOCTOU, stale doc - ADR 0070 ship-blocker: the Schedule tool's Spec().Description + the schedulePostureNote now tell the model a created schedule reports its fire's result back into THIS conversation; TestFireDelivery_ScheduleToolNoteLands pins it lands via the real factory path (DoD #7). - Security material: mark the delivery note delivered AFTER a successful drive, not before — closes the double-record TOCTOU where a concurrent user run's Step 2a drain and the delivery drive could both record the note. - Standards material: docs/architecture.md was stale (still said pull-only / future phase); replaced with the fire-result-delivery section. Co-Authored-By: mecatl <[email protected]>
…note detection TestFireDelivery_EmbeddedEndToEnd in cmd/mecatui/embed/embed_test.go is the DoD #8 ship-gate: a schedule whose fire reports back into its ORIGINATING session's LIVE StreamSessionLive subscription, end-to-end through the REAL embedded composition (app.Build + the in-process scheduler + deliverFireResult + PublishSessionEvent), over a REAL gRPC UNIX socket with a REAL client. Fully offline (UseMock). Bounded-poll (~15s), short tick; goleak.VerifyNone. A planted break (SetDeliverFireResult disabled) drives it RED (no note arrives), restored it goes GREEN. The e2e EXPOSED A GENUINE INTEGRATION BUG across two layers: renderFireDelivery wraps the delivery note in agent.FenceUntrusted, so the recorded EvUserPrompt text starts with "<<<UNTRUSTED\n" — but the live-wire relay (relayLiveEvent) and the TUI client (deliverNoteFrom) detected the note via a bare HasPrefix("[scheduled task ") that NEVER matched the real fenced note. The wire-side live-subscription tests bypassed renderFireDelivery and fed UN-fenced notes, so they never caught it: the live wire silently DROPPED every real delivery note, and the TUI never rendered the delivery card. Fix: detect the FENCED form ("<<<UNTRUSTED\n[scheduled task …") in both relayLiveEvent (internal/adapter/server/grpc.go, new isDeliveryNoteText) and deliverNoteFrom (cmd/mecatui/client/msgs.go). A bare un-fenced "[scheduled task" a user typed is NOT mis-detected (the fence is the discriminator). Updated the affected tests (client/delivery_test.go, ui/delivery_live_test.go, internal/adapter/server/live_subscription_test.go) to feed + assert the real fenced form renderFireDelivery produces. OriginSessionID note: the v1 CreateScheduleRequest.ScheduleSpec proto carries NO origin_session_id (by design — engine/CHANGELOG.md); it is stamped ONLY by the in-loop Schedule tool via SessionOriginScheduleManager. The canned UseMock provider cannot drive a Schedule tool call, so the e2e reaches the just-built *app.Built.Service directly to create the schedule with OriginSessionID set — the ONE in-process step in an otherwise real-wire e2e. The fire, delivery, and live subscription all run through the REAL composition path. Co-Authored-By: mecatl
govulncheck flags a reachable vuln in grpc internal/transport ClientStream.Read, fixed in 1.82.1. This branch leans on grpc server streaming (StreamSessionLive), so bump rather than allowlist. Co-Authored-By: mecatl <[email protected]>
5 tasks
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.
What
Closes the "ping me when X" gap in scheduled tasks: a scheduled fire now reports its result back into the conversation that created it, rendered live in the operator's mecatui — instead of stranding the outcome in a hard-to-find
sched--session. The motivating UX works end-to-end: "monitor this PR every 30m" → the model callsSchedule create→ the scheduler fires unattended → the result appears in your live chat as a delivery card, no input required.Plan:
docs/acceptance/fire-result-delivery.md(31 ACs, landed). ADR:docs/adr/0075-fire-result-delivery.md(supersedes ADR 0059 decision #8's pull-only posture).How (3 waves)
ScheduleSpec.OriginSessionIDcaptured at create-time (server-bound viaSessionOriginScheduleManager+Deps.OriginBinderper-run binding — never a model arg); the outcome rendered as a fenced-untrusted note (renderFireDelivery, the carried-context discipline — never a live instruction); a durable per-sessionport.DeliveryQueue(sidecar-backed, session-scoped exactly-once ledger, survives restart); delivery driven via the existingStartRunContent→loadAndReopenfunnel for idle/terminal origins and the loop's Step-2adrainPendingDeliveryfor busy/awaiting origins. Delivery is decoupled from the fire's success (a delivery error WARNs, never fails the fire; pull-only stays the floor for out-of-band schedules).Service.Subscribe/PublishSessionEvent) + the delivery run publishing onto it; the TUI renders a distinct delivery card (scheduled-task affordance + schedule name) via a third gen-guarded fan-in seam mirroring the replay path.StreamSessionLiveRPC unifies embedded + remote over one projection; the live-wire log-only skip is amended for the delivery case only (the delivery'sEvUserPromptrelays the note; the other two log-only kinds stay skipped).Verification
task lint✅ ·task test✅ (both modules,-race, engine-standalone) ·task api:check✅ ·task docs✅ (matlatl--strict) ·task ac-trace-strict✅ (31 ACs · 0 failures) ·go run ./cmd/mecademo✅.TestFireDelivery_ScheduleToolNoteLands, DoD ACP: accept client-provided streaming-HTTP MCP servers #7); a double-record TOCTOU fix (mark-delivered after a successful drive); the staledocs/architecture.mdpull-only line replaced. Security axis confirmed the trust boundary holds end-to-end (fenced note, unforgeable origin, session-scoped subscription, terminal-injection + path-traversal sanitised, no secrets in logs).Notes / API changes
engine/CHANGELOG.md):port.ScheduleSpec.OriginSessionID,port.DeliveryQueue/DeliveryNote/NopDeliveryQueue,agent.SessionOriginScheduleManager/OriginBinder,Deps.OriginBinder/Deps.DeliveryQueue.task api:updaterun;api:checkgreen.task generate):StreamSessionLiveserver-streaming RPC +StreamSessionLiveRequest.TestFireDelivery_EmbeddedEndToEnddrives a REAL embedded server + REAL gRPC client + a fired one-shot schedule and asserts the delivered note arrives LIVE on the origin'sStreamSessionLivesubscription. Writing it exposed a genuine integration bug — the live-wire relay + TUI detected the note by a bare[scheduled taskprefix, butrenderFireDeliveryfences it (<<<UNTRUSTED\n` first), so every real delivery note was being silently dropped; fixed to detect the fenced form. mecademo does not fire a schedule. Mid-TURN interruption is out of scope by design.Relates to #189 (scheduled tasks follow-up). Closes the deferred item from #307.