refactor: migrate threads index from YAML to ocas variable (Phase 4b) #17

Merged
xiaomo merged 1 commits from refactor/threads-to-ocas-variable into main 2026-06-02 14:28:18 +00:00
Owner

What

Migrate active thread state from threads.yaml to ocas VariableStore.

Why

Phase 4b of issue #11 — the biggest piece of the data layer migration.

Variable design

Field Value
Name @uwf/thread/<thread-id>
Value CAS head hash
Tags suspendedRole, suspendMessage (only when suspended)

Changes

  • New granular API: loadAllThreads, getThread, setThread, deleteThread
  • Removed loadThreadsIndex / saveThreadsIndex (full YAML read/write)
  • ~20 call sites updated in thread.ts, step.ts, shared.ts
  • workflow-util-agent: getActiveThreadEntry reads from variable store
  • Auto-migration: threads.yaml → variables, renames to .migrated
  • New test helper: seedThread/seedThreads
  • 22 files, +418 -282 lines

Verification

  • bun run check
  • bun run test

Ref #11

## What Migrate active thread state from `threads.yaml` to ocas VariableStore. ## Why Phase 4b of issue #11 — the biggest piece of the data layer migration. ## Variable design | Field | Value | |-------|-------| | Name | `@uwf/thread/<thread-id>` | | Value | CAS head hash | | Tags | `suspendedRole`, `suspendMessage` (only when suspended) | ## Changes - New granular API: `loadAllThreads`, `getThread`, `setThread`, `deleteThread` - Removed `loadThreadsIndex` / `saveThreadsIndex` (full YAML read/write) - ~20 call sites updated in `thread.ts`, `step.ts`, `shared.ts` - `workflow-util-agent`: `getActiveThreadEntry` reads from variable store - Auto-migration: `threads.yaml` → variables, renames to `.migrated` - New test helper: `seedThread`/`seedThreads` - 22 files, +418 -282 lines ## Verification - `bun run check` ✅ - `bun run test` ✅ Ref #11
xingyue added 1 commit 2026-06-02 14:23:04 +00:00
- Replace loadThreadsIndex/saveThreadsIndex with granular variable API:
  loadAllThreads, getThread, setThread, deleteThread
- Variable: @uwf/thread/<thread-id>, value=head hash, tags=suspend metadata
- Auto-migration: threads.yaml → variables, renames to .migrated
- Updated ~20 call sites in thread.ts, step.ts, shared.ts
- workflow-util-agent: getActiveThreadEntry reads from variable store
- New test helper: seedThread/seedThreads
- biome fix: removed unused imports
- 22 files changed

Ref #11
xiaomo approved these changes 2026-06-02 14:28:16 +00:00
xiaomo left a comment
Owner

LGTM

Threads 迁移干净,核心设计合理:

新 API 清晰getThread / setThread / deleteThread / loadAllThreads,粒度从全量 YAML 读写降到单条 variable 操作

Suspend metadata 用 tagssuspendedRole / suspendMessage 作为 variable tags 存储,比 YAML 对象嵌套更扁平

迁移逻辑:与 registry 一致(检测 YAML → 导入 → rename .migrated),在 createUwfStore 统一触发

setThreadvarStore.removeset:注释说明了原因(head 可能是不同 schema 的 CAS node),合理

Non-blocking 观察workflow-util-agent/storage.tsgetActiveThreadEntry 每次调用创建新的 createFsStore + createVariableStore,agent adapter 调用频率低所以 OK,但如果未来 agent 需要高频查询可以考虑缓存。

LGTM ✅ Threads 迁移干净,核心设计合理: **新 API 清晰**:`getThread` / `setThread` / `deleteThread` / `loadAllThreads`,粒度从全量 YAML 读写降到单条 variable 操作 **Suspend metadata 用 tags**:`suspendedRole` / `suspendMessage` 作为 variable tags 存储,比 YAML 对象嵌套更扁平 **迁移逻辑**:与 registry 一致(检测 YAML → 导入 → rename `.migrated`),在 `createUwfStore` 统一触发 **`setThread` 中 `varStore.remove` 再 `set`**:注释说明了原因(head 可能是不同 schema 的 CAS node),合理 **Non-blocking 观察**:`workflow-util-agent/storage.ts` 的 `getActiveThreadEntry` 每次调用创建新的 `createFsStore` + `createVariableStore`,agent adapter 调用频率低所以 OK,但如果未来 agent 需要高频查询可以考虑缓存。
xiaomo merged commit e881e0772b into main 2026-06-02 14:28:18 +00:00
xiaomo deleted branch refactor/threads-to-ocas-variable 2026-06-02 14:28:18 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shazhou/united-workforce#17