EventLog: expose sync status per remote (connected, retrying, last error, pending uploads)

未关闭
#10,992 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
typescript

调研方向

Start with packages/effect/src/eventlog/EventLog.ts and EventJournal.ts, especially the remote loop, withRemoteUncommited, and writeRemoteAcks references in the issue. Trace how the remote loop records connection, retry, and acknowledgement events, and how the service exposes read-only state. Done means the status is available per remote with the fields and transitions described in the proposal, including an empty map when no remote is registered.

由索引模型根据 Issue 内容生成。

描述

Clanked by Opus 5.5

What is the problem this feature would solve?

The EventLog module of the week shows how a device writes events offline and syncs them later. A UI built on that needs to tell the user what is going on: "3 changes wait to sync", "Sync failed: forbidden", "Synced". EventLog gives no way to know.

  • The EventLog service has write, writeMany, entries, destroy and compact (EventLog.ts#L110-L166). Nothing reports per-remote state or the number of entries not yet acknowledged.
  • The remote loop retries every failure forever with remoteRetrySchedule and only logs it: Effect.tapCause(Effect.logDebug) for uploads and Effect.catchCause(Effect.logError) for the change stream (EventLog.ts#L1489-L1490, #L1517-L1534). A Forbidden from the server looks the same to the app as a short network drop.
  • navigator.onLine is not a substitute. The browser can be online while the sync server is down or refuses the identity.

The data exists inside the runtime: the journal knows the uncommitted entries per remote (withRemoteUncommited, writeRemoteAcks, nextRemoteSequence, EventJournal.ts#L139-L157), and the loop knows when it connects, fails and retries.

What is the feature you are proposing to solve the problem?

A read-only status per remote on the EventLog service, as a Subscribable (or a Stream plus a current value):

interface RemoteStatus {
  readonly remoteId: RemoteId
  readonly state: "connecting" | "connected" | "retrying"
  readonly pendingUploads: number          // local entries the remote has not acknowledged
  readonly lastError: EventLogRemoteError | undefined
  readonly nextRetryAt: number | undefined // epoch millis while "retrying"
  readonly lastSyncedAt: number | undefined
}

class EventLog extends Context.Service<EventLog, {
  // ...existing members
  readonly status: Subscribable.Subscribable<ReadonlyMap<RemoteId, RemoteStatus>>
}>() {}

// A UI reads it as any other stream:
const banner = Stream.map((yield* EventLog).status.changes, (all) =>
  [...all.values()].some((s) => s.state === "retrying") ? "Offline, changes are saved on this device" : "Synced")
  • pendingUploads changes after each local write and each writeRemoteAcks.
  • state moves to retrying with lastError when an upload or the change stream fails, and back to connected after a successful authenticate.
  • With no remote registered, the map is empty.
What alternatives have you considered?
  • Wrap EventLogRemote in the app and track calls to write and changes. This works for the connection state, but the pending count needs journal internals, and the wrapper must copy the retry logic to know when a retry happens.
  • Read EventLog.entries and compare with the remote sequence. This reads the whole journal on every change, and the remote sequence is not exposed on EventLog.
  • Parse the debug logs. Fragile and not typed.
主要语言
TypeScript
星标
16.7k
派生
808
平均合并
21 小时 22 分钟
30 天内合并 PR
486

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Effect-TS/effect 的其他 Issue

查看 Effect-TS/effect 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。