MatterLoop Redis 队列、运行状态与事件集成
Project description
matterloop-integration-redis
这个包把 Redis 接到 MatterLoop 的队列、运行记录和事件流。它不把 Redis 变成“万能后端”:长期 记忆、Loop checkpoint 和 Worker 都不在这里。
pip install matterloop-integration-redis
三个适配器,三份职责
| 适配器 | 保存什么 | 关键保证 |
|---|---|---|
RedisQueueBackend |
待处理任务、延迟任务、租约和取消标记 | Lua 内的单节点原子状态转换;至少一次投递 |
RedisRunRepository |
RunRecord 与创建时间索引 |
version CAS,防止并发覆盖 |
RedisEventPublisher |
每个 run 的 Core 事件 Stream | 有序游标读取;近似长度裁剪 |
RedisRunRepository 不是 CheckpointStore。精确恢复所需的计划、当前步骤、人工反馈和 revision
必须保存到另一个持久化实现。
装配
from matterloop_integration_redis import (
RedisConfig,
RedisEventPublisher,
RedisQueueBackend,
RedisRunRepository,
)
config = RedisConfig(prefix="matterloop:{prod}", lease_seconds=300)
queue = RedisQueueBackend(client=redis_client, config=config, codec=None)
runs = RedisRunRepository(client=redis_client, config=config, codec=None)
events = RedisEventPublisher(
client=redis_client,
config=config,
checkpoint_codec=None,
)
redis_client 由应用创建并配置 TLS、认证、超时和连接池。三个适配器可以共享它,但都不会关闭它。
RedisConfig(prefix, lease_seconds, event_max_length) 只保存非敏感行为配置:默认值分别为
"matterloop"、60.0 秒和 10_000 条近似事件。连接 URL、用户名和密码不应进入配置对象。
队列不是“恰好一次”
Worker 调用 lease() 取得任务,成功后 acknowledge(),可重试失败则 release()。租约过期的任务
只会在下一次 lease() 时被回收;当前接口没有续租、最大尝试或死信队列。执行时间可能超过租约
时,要么提高租约并预留时钟漂移,要么把任务拆小。
网络超时发生时,Lua 可能已经提交。外部写操作必须带幂等键,最终运行状态必须通过
RunRepository.compare_and_set() 提交。cancel() 只能阻止等待中的任务或标记租用中的任务,
不会中断已经运行的 Python 代码。
Key 布局
所有 Key 都位于 <prefix> 下:
<prefix>:queue:pending List
<prefix>:queue:delayed Sorted Set
<prefix>:queue:jobs Hash
<prefix>:queue:leases Hash
<prefix>:queue:lease-expiry Sorted Set
<prefix>:runs:index Sorted Set
<prefix>:runs:<run_id> String (versioned JSON)
<prefix>:events:<run_id> Stream
运行记录与事件没有 TTL 或删除 API。归档、删除、容量告警和数据保留属于部署方职责。
Redis Cluster
队列脚本、仓储 CAS 和批量读取都会访问多个 Key,因此它们必须落在同一个 hash slot。默认前缀在
Cluster 中可能触发 CROSSSLOT;使用固定 hash tag,例如 matterloop:{prod}。这样会把这组数据
集中到一个 slot。需要横向分片时,请按租户配置多个前缀/客户端,或实现不同后端。
事件与敏感数据
RedisEventPublisher 会把事件时刻的完整 checkpoint 写入 Stream,里面可能包含目标、模型输出、
metadata 和人工反馈。本包不会自动调用 Redactor。生产环境应设置 Redis ACL、TLS、静态加密、
保留期限和单事件大小限制。
读取事件使用排他 Stream 游标 after。Stream 被裁剪后,旧游标不会报告缺口,只会从仍存在的
下一条开始;需要不可丢失审计时,不要依赖近似裁剪的 Redis Stream 作为唯一记录。
协议与错误
AsyncRedisClient 是最小结构协议,需要 eval、get、mget、zrevrange、xadd、xrange
和 aclose。RedisPayloadCodec 使用严格、版本化 JSON;未知版本或损坏内容抛
RedisPayloadError。网络、ACL、超时和 Cluster 错误由底层客户端原样传播,本包不自动重试。
构造入口为 RedisQueueBackend(client, config, codec)、RedisRunRepository(client, config, codec)
和 RedisEventPublisher(client, config, checkpoint_codec)。完整队列控制面和关闭顺序见
企业集成指南。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matterloop_integration_redis-0.1.0.tar.gz.
File metadata
- Download URL: matterloop_integration_redis-0.1.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31554c78e3517ae44cefc036c49d0210eb8e856d38e72b575c26df5baad3d153
|
|
| MD5 |
133f46547cf5238a0d24f3f721ac0c29
|
|
| BLAKE2b-256 |
04e02402459b8438eda8f05323cd1a069f370034376a2eb8ccbab4347a6750ae
|
Provenance
The following attestation bundles were made for matterloop_integration_redis-0.1.0.tar.gz:
Publisher:
publish.yml on huleidada/matterloop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matterloop_integration_redis-0.1.0.tar.gz -
Subject digest:
31554c78e3517ae44cefc036c49d0210eb8e856d38e72b575c26df5baad3d153 - Sigstore transparency entry: 2180927070
- Sigstore integration time:
-
Permalink:
huleidada/matterloop@fccaf6cab6bb0ed7902f0feb56bf92ae42881f4c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/huleidada
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fccaf6cab6bb0ed7902f0feb56bf92ae42881f4c -
Trigger Event:
push
-
Statement type:
File details
Details for the file matterloop_integration_redis-0.1.0-py3-none-any.whl.
File metadata
- Download URL: matterloop_integration_redis-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ae65c5d3d55a32f62105abd8216cad959fc04039972b75fa12fb9a23affac0b
|
|
| MD5 |
53d250c872ec383802db1eef38fecb7a
|
|
| BLAKE2b-256 |
3fa3e1ca92b04214988693b7accad9d9982e78b7574f11d4a913bc605ec413da
|
Provenance
The following attestation bundles were made for matterloop_integration_redis-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on huleidada/matterloop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matterloop_integration_redis-0.1.0-py3-none-any.whl -
Subject digest:
1ae65c5d3d55a32f62105abd8216cad959fc04039972b75fa12fb9a23affac0b - Sigstore transparency entry: 2180927356
- Sigstore integration time:
-
Permalink:
huleidada/matterloop@fccaf6cab6bb0ed7902f0feb56bf92ae42881f4c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/huleidada
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fccaf6cab6bb0ed7902f0feb56bf92ae42881f4c -
Trigger Event:
push
-
Statement type: