Add persistent store implementation (replace in-memory store)
还没有人认领这个 Issue。
评估
调研方向
Start with pkg/domain/environment/repository.go, pkg/infra/store/memory.go, and its memory_test.go to understand the five-method contract, copy semantics, and error behavior. Then inspect cmd/waggle/main.go:59 for wiring and configuration. Done means a persistent implementation, parallel table-driven coverage, context handling, and updated default wiring satisfy the listed acceptance criteria.
由索引模型根据 Issue 内容生成。
描述
Summary
Waggle currently uses an in-memory MemoryStore (pkg/infra/store/memory.go) that implements the environment.Repository interface. All environment state is lost on restart. We need a persistent store so environments can survive server restarts and support operational use cases like auditing.
Current Architecture (DDD)
The codebase follows Domain-Driven Design with clean separation:
- Domain interface:
pkg/domain/environment/repository.godefinesRepositorywith 5 methods:Save,FindByID,FindAll,Delete,Count - Current adapter:
pkg/infra/store/memory.goimplementsRepositorywith amap[string]*Environment+sync.RWMutex - Service layer:
pkg/service/environment.godepends on theRepositoryinterface (not the concrete store) - Wiring:
cmd/waggle/main.go:59instantiatesstore.NewMemoryStore()and injects it
The service layer calls Save() after every state transition (Creating, Running, Error, Destroying) and Delete() on destroy. FindByID() and FindAll() are read-only. All methods accept context.Context.
Critical contract: copy semantics
The MemoryStore returns copies on both Save() and FindByID() to prevent aliasing bugs. The persistent store must maintain equivalent isolation — a mutated *Environment returned from FindByID() must not affect the stored state until Save() is called again.
Approach
New adapter in pkg/infra/store/
Add a new file (e.g., bolt.go or sqlite.go) implementing environment.Repository. The implementation choice depends on requirements:
| Option | Pros | Cons |
|---|---|---|
| bbolt (embedded KV) | Zero config, single file, no external deps | No SQL, limited query flexibility |
| SQLite (embedded SQL) | SQL queries, mature, well-understood | CGO dependency (unless modernc) |
For a single-binary MCP server, bbolt or modernc SQLite (pure Go) are good fits — no external database to manage.
Serialization
The Environment struct needs to be serialized/deserialized. Options:
- JSON (simple, human-readable, already used in MCP responses)
- Protobuf (compact, schema-versioned — overkill for now)
Wiring change
Only cmd/waggle/main.go needs to change:
// Before
repo := store.NewMemoryStore()
// After (example with bbolt)
repo, err := store.NewBoltStore(cfg.DataDir + "/waggle.db")
if err != nil {
return fmt.Errorf("open store: %w", err)
}
defer repo.Close()
Configuration
Add a WAGGLE_STORE_PATH env var (or reuse DataDir) for the database file path. The MemoryStore should remain available for testing and as a fallback.
Acceptance Criteria
- New
Repositoryimplementation inpkg/infra/store/with persistent storage - Implements all 5 methods:
Save,FindByID,FindAll,Delete,Count - Returns
environment.ErrNotFoundfor missing entities (matching MemoryStore contract) - Copy semantics maintained (returned
*Environmentis independent of stored state) - Context respected for cancellation/timeout on all operations
-
MemoryStorekept for tests (not deleted) - Wiring in
main.goupdated to use persistent store by default - Configuration via environment variable for store path
- Table-driven parallel unit tests matching
memory_test.gocoverage -
doc.gowith SPDX headers if new package created
- 主要语言
- Go
- 星标
- 4
- 派生
- 1
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
stacklok/waggle 的其他 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
TUM-Dev/Campus-Backend#678 ·
维护者通常 1 天内回复
-
fix(app): fail closed if GetGeneralSetting fails during initialization可能已有人在做 @kalavt 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
tsukumogami/tsuku#2813 ·
维护者通常 1 天内回复
-
component:obi contribfest go test
难度 2/5 1 小时以内 新手友好度 83/100
open-telemetry/opentelemetry-ebpf-instrumentation#4143 · 1 条评论 ·
维护者通常 1 天内回复