OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

openclaw-plugin: follow-ups from architecture review (archive ids, recall API, keep_recent, assemble early-exit, contract checks)

Open ZaynJarvis opened this issue 3 months ago • 4 comments

Follow-ups from an architecture review of examples/openclaw-plugin (2026-08-28). Each item lists current behavior and the change surface; priorities are initial.

1. Model cannot see archive ids / session id for history lookup

模型需要获取 archive id / session_id,这样才能从 OV 直接搜到 (grep/read) 消息历史 (in case compact 丢了细节)。

  • Current: pre_archive_abstracts is hardcoded [] server-side (openviking/session/session.py get_session_context), so no archive list reaches the model. Only path is ov_archive_search grep → archive label → ov_archive_expand (two hops, keyword-dependent).
  • Surface: get_session_context payload + plugin buildArchiveMemory / system prompt guide.

2. Replace client-side auto-recall find with the new plugin search interface

find 需要改成新的 plugin search 接口(服务端组装召回)。

  • Current: single user-message query, one vector find, client regex rerank (memory-ranking.ts), no history context.
  • Surface: auto-recall.ts buildAutoRecallContext only.

3. Verify turn/tool integrity of keep_recent_count=10 split

调查 commit keep_recent_count 按条数切不看角色的问题;预期服务端会处理好 tool 配对 / turn 完整性,需确认。

  • Current: split is by message count; kept window may start mid-turn or be all assistant/tool messages. ToolPart is self-contained so tool_use/tool_result pairing is safe; semantic turn boundary is not.

4. transformContext assemble should early-exit before any work on non-user tail

B assemble 每次模型调用都跑一次,tool round 时最后一条非 user 也先做 messageDigest / token 估算再 passthrough;early exit 需要更早(如果本来也不做操作的话)。

  • Surface: services/context-lifecycle-service.ts assembleOpenVikingSession (diag("assemble_entry") runs messageDigest on every call).

5. (P2) isMainAssemble duck-typing on OpenClaw params

靠 hasOwnProperty("prompt" | "availableTools" | "citationsMode") 判断,OpenClaw 改参数会静默走错分支。

  • Surface: context-engine.ts assemble().

6. (consider first) retention_mode=turn_budget pending_tokens branch unreviewed

另一套 pending_tokens 计算分支(openviking/session/retention.py, session.py _rebuild_pending_tokens),与 keep_recent_count 滑窗并存,尚未审查。

7. Verify ContextEngine contract against OpenClaw 2026.8.1

openclaw 2026.8.1 需要支持新契约使 assemble 可用。Plugin declares engines.openclaw >=2026.5.27; call sites verified on 2026.8.1 (attempt-history.ts assemble A, tool-result-context-guard.ts assemble B per model call, afterTurn per loop iteration) but the two versions were not diffed.

8. (found during review, unconfirmed priority) WM overview silently dropped when active messages fill the budget

get_session_context fits active messages first and includes latest_archive_overview only if it still fits (session.py ~L2954); otherwise returns "" while the plugin still emits the "Session Context Guide" system prompt referencing a summary that is absent.

ZaynJarvis avatar Aug 27 '26 16:08 ZaynJarvis

I'd like to take item 2 only: replace the OpenClaw plugin's client-side auto-recall find/ranking/assembly path with the server-side search context interface.

I'll keep the PR focused on the existing OpenClaw client and auto-recall boundary, preserve session/actor routing plus observable error/trace behavior, and extend the existing contract tests. I will use the current server context contract directly rather than introduce a parallel retrieval mechanism or speculative fallback. The other follow-up items will remain untouched.

starslittle avatar Aug 28 '26 06:08 starslittle

I'd like to take item 4 only. I plan to move the transformContext non-user-tail guard before token estimation, message digest, diagnostics, and session identity bookkeeping. The no-op path will preserve the original messages and return a zero token-estimate sentinel; OpenClaw's tool-loop call site consumes only messages in both v2026.5.27 and v2026.8.1-beta.3. I'll add focused tests proving that no estimator, digest, client, or bookkeeping work runs on this path.

jamespud avatar Aug 28 '26 11:08 jamespud

I'd like to take item 2 only: replace the OpenClaw plugin's client-side auto-recall find/ranking/assembly path with the server-side search context interface.

I'll keep the PR focused on the existing OpenClaw client and auto-recall boundary, preserve session/actor routing plus observable error/trace behavior, and extend the existing contract tests. I will use the current server context contract directly rather than introduce a parallel retrieval mechanism or speculative fallback. The other follow-up items will remain untouched.

awesome, I'm thinking using common search API that every other plugins are using. so it's consistant. if shared lib can be used, that would also be awesome.

ZaynJarvis avatar Aug 28 '26 15:08 ZaynJarvis

I'd like to take items 3 and 6, if nobody is already working on them.

I'll first reproduce the OpenClaw keep_recent_count boundary cases and verify pending_tokens accounting against the existing turn-budget planner, including append, commit, and reload.

If OpenClaw should support turn_budget, I'll reuse the existing server implementation and preserve current defaults and explicit full-compaction behavior. I won't introduce a separate retention algorithm.

@ZaynJarvis Is this scope appropriate, and is anyone already covering these items internally?

starslittle avatar Sep 05 '26 16:09 starslittle