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
[Copilot] Define a structured streaming event protocol with cancel and reconnect #27
I'm an AI application developer focused on Agent engineering. I've built an AgentEvent streaming protocol used across Electron and Web clients (unified model backend, event bus, per-session context), and a multi-channel Agent platform, so this issue maps directly onto what I've already done: structured event envelopes, monotonic sequencing, cancel propagation all the way down to the runtime, and reconnect/resume semantics.
My plan:
Propose a versioned event envelope schema (protocol version, run/message id, monotonic sequence id, event type, timestamp, typed payload) as a short ADR for community review.
Draft the event types from the issue list as TypeScript types plus runtime validation.
Implement cancel propagation (renderer -> actual Agent/model/tool runtime) and run-id/sequence-based reconnect/resume.
Add idempotency handling so replayed events never duplicate text, tool cards, or citations.
I'll also keep the constraints of #17/#18/#19 in mind: redaction before tool payloads reach the UI, and a single final state shared between stream completion and persistence. Happy to hear feedback before I start the implementation.
Thanks for scoping this out. I did a quick read of the current code before drafting, so this is grounded in the existing AgentEvent layer rather than a rewrite:
run-manager already owns the single final state (run.status / run.answer → runs.json), and cancelRun already propagates to the runtime.
What's missing vs. the issue's requirements: a protocol version, a monotonic sequence, typed payload contracts, independent cancelled / tool_progress / citation_added / status events, and reconnect/resume semantics.
Here is the proposal for review before I start implementing.
1. Event envelope
exportinterfaceStreamEventEnvelope{protocolVersion: 1;// versioned for forward compatrunId: string;// identifies one runmessageId: string;// equals runId in v1, split out later if neededsequence: number;// monotonic per run; idempotency key = runId + sequencetype: StreamEventType;timestamp: string;// ISO 8601 UTC; display only, never identitypayload: StreamEventPayload;// discriminated by type}
status exposes only task phases/activity, never hidden chain-of-thought.
Tool payloads go through redaction before reaching the UI.
The renderer never executes model-returned code.
5. Migration path
Envelope + types land in packages/shared/src/kernel/events.ts first (pure types, zero runtime change) — this could be its own tiny PR.
Runtime event loop (run-manager) emits the new typed events.
Transport upgrade (kernelHost + preload), renderer consumes the new protocol.
Compat window: keep message_delta as a "resume snapshot backfill" event — transport emits a full snapshot once on reconnect, then only text_delta increments.
Open questions for reviewers
Resume data source: today only the final answer is persisted (runs.json), there is no event log. For v1 I propose the runtime keeps in-memory events for the lifetime of a run, and persisting an event log is deferred (ties into [Reproducibility] Persist immutable run manifests for Agent / Deep Research #21 immutable run manifests). OK?
status.phase enum: is thinking / searching / working sufficient, or should it be derived from actual Copilot steps?
messageId vs runId: merge them in v1 and split only when a single message can span multiple runs?
Happy to adjust per your feedback before I write code.
Activity
shi-felix commentedon Sep 11, 2026
Hi, I'd like to take this one.
I'm an AI application developer focused on Agent engineering. I've built an AgentEvent streaming protocol used across Electron and Web clients (unified model backend, event bus, per-session context), and a multi-channel Agent platform, so this issue maps directly onto what I've already done: structured event envelopes, monotonic sequencing, cancel propagation all the way down to the runtime, and reconnect/resume semantics.
My plan:
I'll also keep the constraints of #17/#18/#19 in mind: redaction before tool payloads reach the UI, and a single final state shared between stream completion and persistence. Happy to hear feedback before I start the implementation.
shi-felix commentedon Sep 11, 2026
Proposal: Stream Event Protocol v1 (ADR draft)
Thanks for scoping this out. I did a quick read of the current code before drafting, so this is grounded in the existing
AgentEventlayer rather than a rewrite:kernel -> kernelHost -> webContents.send('agent:event', ...) -> preload -> renderer atoms(IPC channel is there).run-manageralready owns the single final state (run.status/run.answer→runs.json), andcancelRunalready propagates to the runtime.sequence, typed payload contracts, independentcancelled/tool_progress/citation_added/statusevents, and reconnect/resume semantics.Here is the proposal for review before I start implementing.
1. Event envelope
2. Event types and payloads (12 events)
Note: today's
message_deltacarries a fullanswersnapshot; the new protocol moves totext_deltaincrements. See the compat window in §5.3. Idempotency · cancel · reconnect
runId + sequence; replayed events never re-insert text, tool cards, or citationscancelRun-> runtime propagates -> runtime explicitly emitscancelled(no more inferring fromrun_failed); partial answer is preservedlastSequence; gap range is replayed (resume), already-consumed events are not re-appliedstopReasonand persistedrun.statuscome from the same single final state in run-manager (aligns with #18)4. Security (aligns with #19)
statusexposes only task phases/activity, never hidden chain-of-thought.5. Migration path
packages/shared/src/kernel/events.tsfirst (pure types, zero runtime change) — this could be its own tiny PR.run-manager) emits the new typed events.kernelHost+preload), renderer consumes the new protocol.message_deltaas a "resume snapshot backfill" event — transport emits a full snapshot once on reconnect, then onlytext_deltaincrements.Open questions for reviewers
answeris persisted (runs.json), there is no event log. For v1 I propose the runtime keeps in-memory events for the lifetime of a run, and persisting an event log is deferred (ties into [Reproducibility] Persist immutable run manifests for Agent / Deep Research #21 immutable run manifests). OK?status.phaseenum: isthinking / searching / workingsufficient, or should it be derived from actual Copilot steps?messageIdvsrunId: merge them in v1 and split only when a single message can span multiple runs?Happy to adjust per your feedback before I write code.
feat(core): add Stream Event Protocol v1 types (ADR 0001)
feat(ui): consume Stream Event v1 channel (idempotent log)
feat(core): add Stream Event Protocol v1 types (ADR 0001)
feat(shared): add parallel Stream Event v1 channel to RunManager
feat(electron): forward Stream Event v1 channel to renderer
feat(ui): consume Stream Event v1 channel (idempotent log)
feat(shared): add parallel Stream Event v1 channel to RunManager
feat(electron): forward Stream Event v1 channel to renderer
feat(ui): consume Stream Event v1 channel (idempotent log)
feat(core): add Stream Event Protocol v1 types (ADR 0001)
feat(shared): add parallel Stream Event v1 channel to RunManager
9 remaining items
feat(ui): consume Stream Event v1 channel (idempotent log)
Merge Stream Event v1 and persistence stack (#76)
github-actions commentedon Sep 21, 2026
@sjr666666 这个 Issue 已认领超过 7 天,目前没有发现关联的 open PR,也没有看到最近 7 天的进度更新。
如果仍在推进,请在 3 天内 留一条简短进度说明(包括正在等待的前置依赖也可以);如果已经有 PR,请贴出链接。若 3 天内没有回应,认领会自动释放,方便其他贡献者接手。
github-actions commentedon Sep 25, 2026
@sjr666666 在提醒后 3 天内没有进度回应,且仍未发现关联的 open PR;本次认领已自动释放。Issue 保持开放,可以重新认领。
wenyuxuan19-stack commentedon Oct 18, 2026
/claim
我来处理持久化重放日志的 run 保留策略修复,已提交 PR #342:https://github.com/helsome/folio/pull/342。
本次范围:按最近一次有效事件保留 run,与内存历史的 LRU 语义一致,避免裁剪时丢失近期活跃 run 的重放历史;补充交错事件、重复/倒退序号、磁盘重载与游标重放测试。28 项聚焦测试及全部工作区类型检查通过。
此 PR 对应 #27 的一个独立子范围,其他 streaming 协议验收仍需后续推进。
github-actions commentedon Oct 18, 2026
@wenyuxuan19-stack 已认领该 Issue,并已自动设为 Assignee。提交 PR 时请在描述中写
Closes #27。fix: 按最近有效事件保留流式重放日志 (#342)
github-actions commentedon Oct 26, 2026
@wenyuxuan19-stack 这个 Issue 已认领超过 7 天,目前没有发现关联的 open PR,也没有看到最近 7 天的进度更新。
如果仍在推进,请在 3 天内 留一条简短进度说明(包括正在等待的前置依赖也可以);如果已经有 PR,请贴出链接。若 3 天内没有回应,认领会自动释放,方便其他贡献者接手。
github-actions commentedon Oct 29, 2026
@wenyuxuan19-stack 在提醒后 3 天内没有进度回应,且仍未发现关联的 open PR;本次认领已自动释放。Issue 保持开放,可以重新认领。