Skip to content

Commit 020c34a

Browse files
committed
feat: define session transfer frames
1 parent f860a23 commit 020c34a

4 files changed

Lines changed: 868 additions & 9 deletions

File tree

docs/session-transfer.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
## Status
66

7-
This is the implementation decision for a future Session Transfer facility. It
8-
does not claim that Rin `0.6.0` already exposes these operations. Until the
9-
design is implemented, tested, and added to the contract, the existing 16 MiB
10-
inline Snapshot limit remains authoritative.
7+
This is the implementation decision for a future Session Transfer facility.
8+
Protocol frame types, structural validators, and checksum primitives now exist,
9+
but Rin does not yet expose export or import operations. Until the Store,
10+
Runtime, HTTP, contract, and SDK work is complete, the existing 16 MiB inline
11+
Snapshot limit remains authoritative.
1112

1213
## Problem
1314

@@ -42,6 +43,30 @@ The complete frame repeats the terminal revision, head, and event count and
4243
carries an ordered stream SHA-256. Import publishes nothing until it reads and
4344
verifies the complete frame.
4445

46+
#### Version 1 frame and hash profile
47+
48+
`rin.session-transfer/v1` is a complete-lineage format: `start_revision` is
49+
zero, `start_head_hash` is empty, `event_count` is greater than zero, and
50+
`terminal_revision` equals `event_count`. It uses only lowercase hexadecimal
51+
SHA-256 (`hash_algorithm: "sha256"`). Revisions, counts, and lineage generation
52+
must remain exact JSON integers no greater than `9007199254740991`.
53+
54+
Checksums use the compact UTF-8 JSON produced by the declared wire member order
55+
in the protocol structs, with no insignificant whitespace. `EventRecord.Data`
56+
retains its original compact JSON member order and value representation. The
57+
per-event checksum is SHA-256 over the compact `EventRecord` object. The stream
58+
checksum is SHA-256 over the compact manifest followed by LF, then each compact
59+
event frame followed by LF, in sequence order. It excludes the `complete`
60+
frame. Cross-language implementations must use the golden vectors in
61+
`protocol/transfer_test.go`; parsing into an unordered object and serializing it
62+
with implementation-default member order is not conformant.
63+
64+
Validators reject non-genesis starts, unsafe integers, invalid timestamps or
65+
JSON, checksum mismatches, sequence gaps, broken `prev_hash` continuity, extra
66+
events, and a terminal boundary that differs from the manifest or final event.
67+
The authoritative `EventRecord.Hash` chain is separately verified during
68+
Runtime replay; transport checksums do not replace it.
69+
4570
### 2. Keep every frame bounded
4671

4772
- HTTP reads and writes one frame at a time and never materializes the complete
@@ -142,7 +167,7 @@ the Snapshot endpoint media type.
142167

143168
## Implementation order
144169

145-
1. Define protocol frames, validators, and hash rules.
170+
1. Define protocol frames, validators, and hash rules. **Implemented.**
146171
2. Define `TransferStore` and implement File Store staging/atomic publication.
147172
3. Implement the immutable Runtime export boundary and post-import genesis
148173
verification.

docs/session-transfer.zh-CN.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
## 状态
66

7-
本文是下一版 Session Transfer 的实施决策,不表示 `0.6.0` 已经提供这些接口。
8-
当前版本仍只有 16 MiB inline Snapshot;在本设计完整实现、测试并进入契约前,
9-
调用方必须继续遵守现有限制
7+
本文是下一版 Session Transfer 的实施决策。Protocol frame 类型、结构校验器和
8+
checksum primitive 已实现,但 Rin 还没有开放 export/import operation。在 Store、
9+
Runtime、HTTP、契约与 SDK 全部完成前,现有 16 MiB inline Snapshot 上限仍然有效
1010

1111
## 问题
1212

@@ -35,6 +35,27 @@ Data、RecordedAt、Hash 或其他权威字段。
3535
Complete frame 重复终止 revision、head 和 event count,并携带按 frame 顺序计算
3636
的 stream SHA-256。导入只有完整读取并验证 complete 后才可发布 Session。
3737

38+
#### Version 1 frame 与 hash profile
39+
40+
`rin.session-transfer/v1` 只支持完整 lineage:`start_revision` 必须为零、
41+
`start_head_hash` 必须为空、`event_count` 必须大于零,并且
42+
`terminal_revision` 必须等于 `event_count`。算法只允许小写十六进制 SHA-256
43+
`hash_algorithm: "sha256"`)。Revision、count 和 lineage generation 必须是
44+
不超过 `9007199254740991` 的精确 JSON integer。
45+
46+
Checksum 输入是 protocol struct 所声明 wire member 顺序生成的 compact UTF-8
47+
JSON,不含无意义空白。`EventRecord.Data` 保持原 compact JSON 的 member 顺序和
48+
value 表示。单 event checksum 是 compact `EventRecord` Object 的 SHA-256。
49+
Stream checksum 按顺序覆盖 compact manifest 加 LF,以及每个 compact event
50+
frame 加 LF;不包含 `complete` frame。跨语言实现必须通过
51+
`protocol/transfer_test.go` 中的 golden vector;把 JSON 解析为无序 Object 后用
52+
语言默认顺序重新序列化不符合契约。
53+
54+
校验器会拒绝非 genesis 起点、不安全整数、非法时间或 JSON、checksum 不匹配、
55+
sequence gap、断裂的 `prev_hash`、多余 event,以及与 manifest 或最终 event
56+
不一致的终止边界。Runtime replay 还会单独验证权威 `EventRecord.Hash` chain;
57+
传输 checksum 不能替代它。
58+
3859
### 2. 每个 frame 保持有界
3960

4061
- HTTP 逐 frame 读写,不 materialize 完整 Transfer。
@@ -119,7 +140,7 @@ Snapshot endpoint 的媒体类型。
119140

120141
## 实施顺序
121142

122-
1. 定义 protocol frame、校验器和 hash 规则;
143+
1. 定义 protocol frame、校验器和 hash 规则;**已实现。**
123144
2. 定义 `TransferStore`,实现 File Store staging/atomic publish;
124145
3. 实现 Runtime immutable export boundary 和 import 后 genesis verify;
125146
4. 增加 HTTP stream;

0 commit comments

Comments
 (0)