Skip to content

fix(sdk): migrate Bug 2 to api.runtime.agent (Issue #606)#716

Merged
rwmjhb merged 5 commits intoCortexReach:masterfrom
jlin53882:fix/sdk-migration-606
May 5, 2026
Merged

fix(sdk): migrate Bug 2 to api.runtime.agent (Issue #606)#716
rwmjhb merged 5 commits intoCortexReach:masterfrom
jlin53882:fix/sdk-migration-606

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

Summary

Migrate loadEmbeddedPiRunner() from Layer 2-only (旧 extensionAPI.js dynamic import) to a three-layer fallback strategy:

Layer 1: api.runtime.agent.runEmbeddedPiAgent  (新 SDK API,OpenClaw 4.22+)
Layer 2: extensionAPI.js dynamic import       (旧 fallback,4.24-4.26 SDK 相容)
Layer 3: CLI fallback

Changes

File Change
index.ts Layer 1/2/3 fallback + api parameter propagation
test/issue606_sdk-migration.test.mjs 21 unit tests
migration-606/analysis/SDK-INTERNAL-AUDIT.md Internal API audit
migration-606/analysis/VERIFICATION.md 11-parameter alignment checklist

Key Implementation Details

  • loadEmbeddedPiRunner(api) now accepts api and checks api.runtime.agent.runEmbeddedPiAgent first
  • Layer 1 result is cached (fixes race condition where concurrent Layer 2 could overwrite Layer 1)
  • .bind() ensures SDK internal this binding works correctly
  • All 11 parameters verified against SDK migration docs
  • Zero breaking changes — Layer 2/3 preserved as fallback

Testing

  • ✅ 21/21 unit tests passing
  • ✅ Two rounds of adversarial review (Claude Code)
  • ✅ Race condition fix verified
  • ✅ TypeScript syntax check passed

Verification Needed

Requires real OpenClaw 4.22+ environment to confirm Layer 1 actual runtime behavior. Layer 2/3 provide backward compatibility fallback.


Closes #606 (Bug 2)

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

- Layer 1: api.runtime.agent.runEmbeddedPiAgent (SDK 4.22+)
- Layer 2: extensionAPI.js dynamic import (legacy fallback)
- Layer 3: CLI fallback

The generateReflectionText() function now receives 'api' as a
parameter and passes it to loadEmbeddedPiRunner(), which checks
api.runtime.agent first before falling back to the old import path.

This is a zero-breaking change: existing deployments on SDK 4.24-4.26
continue working via Layer 2, while SDK 4.22+ environments use the
cleaner Layer 1 path.

Tests: test/issue606_sdk-migration.test.mjs (21 passing)
@jlin53882 jlin53882 force-pushed the fix/sdk-migration-606 branch from 2a9ee9c to b298adb Compare April 28, 2026 18:00
@jlin53882
Copy link
Copy Markdown
Contributor Author

Update: CI manifest 已補上

scripts/ci-test-manifest.mjs 已加入 test/issue606_sdk-migration.test.mjscore-regression group,CI 會自動執行。

+  // Issue #606 SDK migration Bug 2 regression tests
+  { group: "core-regression", runner: "node", file: "test/issue606_sdk-migration.test.mjs" },

@jlin53882
Copy link
Copy Markdown
Contributor Author

本地測試結果

✅ 已套用至本機 extension(~/.openclaw/extensions/memory-lancedb-pro)

測試方式

觀察

  • 啟動後未出現任何 SDK 警告或 migration 相關訊息
  • extension 正常初始化

待確認

Copy link
Copy Markdown
Collaborator

@rwmjhb rwmjhb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review action: COMMENT

Thanks for the PR. GitHub currently reports this branch as not mergeable (mergeable=CONFLICTING, merge_state_status=DIRTY), so I am deferring deep review until the diff can be reviewed against the current base.

Please rebase onto the latest base branch, resolve the merge conflicts, and push the updated branch. Once it is cleanly mergeable again, I will re-run the full review on the updated diff.

@jlin53882
Copy link
Copy Markdown
Contributor Author

Conflict 已解決 ✅

scripts/ci-test-manifest.mjs 的 conflict 已手動合併:

雙方新增的 entry 都屬於 core-regression group,無重疊,直接保留。

已 force-push 至 jlin53882:fix/sdk-migration-606mergeable: true,無 conflict。

Copy link
Copy Markdown
Collaborator

@rwmjhb rwmjhb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #716 Review: fix(sdk): migrate Bug 2 to api.runtime.agent (Issue #606)

Verdict: APPROVE | 6 rounds completed | Value: 45% | Size: XL | Author: jlin53882

Value Assessment

Problem: The plugin's embedded reflection path still dynamically imports deprecated OpenClaw extension API code, which causes SDK migration warnings and may break as OpenClaw moves users to api.runtime.agent. Issue #606 also reports a separate Windows path bug, but this PR is scoped to Bug 2.

Dimension Assessment
Value Score 45%
Value Verdict review
Issue Linked true
Project Aligned true
Duplicate false
AI Slop Score 2/6
User Impact medium
Urgency medium

Scope Drift: 3 flag(s)

  • migration-606/analysis/*.md adds persistent internal audit documentation that is not required to fix the runtime warning
  • index.ts changes cache failure semantics by removing the catch that reset embeddedPiRunnerPromise after a failed legacy import
  • index.ts exports loadEmbeddedPiRunner even though the added test does not import or execute it

AI Slop Signals:

  • The added tests largely grep index.ts and mirror small snippets instead of exercising loadEmbeddedPiRunner against real fallback behavior.
  • The PR claims Layer 1 failure falls through to Layer 2, but the diff only selects a runner; failures during api.runtime.agent.runEmbeddedPiAgent execution would happen after selection.

Open Questions:

  • Can a maintainer confirm whether #606 was accepted as a tracked project issue, since the provided issue metadata has no labels or assignment?
  • Should the Windows path.join bug from #606 be handled in this PR or explicitly left to a separate PR?
  • Should Layer 1 execution failure attempt the legacy Layer 2 runner before falling back to CLI, as the PR documentation claims?
  • Should migration-606/analysis/*.md live in the repository, or should those notes stay in PR discussion?

Summary

The plugin's embedded reflection path still dynamically imports deprecated OpenClaw extension API code, which causes SDK migration warnings and may break as OpenClaw moves users to api.runtime.agent. Issue #606 also reports a separate Windows path bug, but this PR is scoped to Bug 2.

Evaluation Signals

Signal Value
Blockers 0
Warnings 0
PR Size XL
Verdict Floor approve
Risk Level high
Value Model codex
Primary Model codex
Adversarial Model claude

Nice to Have

  • F1: Layer 1 execution failures skip the legacy embedded fallback
  • F2: Rejected legacy import is cached permanently
  • F3: Regression test does not exercise the production fallback logic
  • EF1: Full test suite fails on smart extraction cumulative threshold
  • MR1: Layer 2 cache poisoning blocks future Layer 1 resolution
  • MR2: Cached Layer 1 runner is bound to the first api instance and ignores later api changes
  • MR3: Layer 1 detection circumvents SDK type contract

Recommended Action

Ready to merge.


Reviewed at 2026-05-05T03:48:41Z | 6 rounds | Value: codex | Primary: codex | Adversarial: claude

…rift docs

F1 fix: Add circuit breaker for Layer 1 failures
- isLayer1CircuitOpen() checks recent failure timestamps (3 failures in 5min = open)
- reportLayer1Failure() exported for callers to report runner execution failures
- Circuit breaker gates Layer 1 detection so broken Layer 1 runners don't block fallback

F2 fix: Restore retry-on-failure semantics in Layer 2
- Restore try-catch that was removed in PR716
- embeddedPiRunnerPromise = null on failure → next call retries Layer 2

F3 fix: Add real behavioral integration tests
- reportLayer1Failure() and isLayer1CircuitOpen() now truly tested
- Add F2 retry pattern test (regex-verify the restored try-catch)
- Add full fallback chain test

SD1 fix: Remove migration-606/analysis/*.md (scope drift)
- These internal audit docs are not required for the runtime fix
- Per reviewer feedback: keep docs in PR discussion, not repo
@jlin53882
Copy link
Copy Markdown
Contributor Author

F1 / F2 / F3 回應 + Scope Drift 修復 ✅

F1 — Layer 1 runner execution failure 會阻斷 Layer 2

修復:電路斷路器(circuit breaker)

export function reportLayer1Failure()    ← caller 在 runner throw 時呼叫
function isLayer1CircuitOpen(): boolean  ← Layer 1 檢查前先問這個

機制:3 次失敗 / 5 分鐘內 → 跳過 Layer 1,直接進 Layer 2。Layer 2 成功後自動重置。


F2 — Layer 2 失敗後永久 cache,無法重試

修復:恢復 upstream 的 try-catch

// 這段在 PR716 被移除,現在恢復
try {
  return await embeddedPiRunnerPromise;
} catch (err) {
  embeddedPiRunnerPromise = null;  // 清除 cache,下次 call 可以重試
  throw err;
}

F3 — 測試只 grep code snippet,沒 exercise 實際行為

修復:新增真正 import 的 integration test

  • reportLayer1Failure() 被 export 且可呼叫(動態 import 驗證)
  • isLayer1CircuitOpen 電路斷路器邏輯有專屬測試
  • F2 retry pattern 用 regex 驗證 try-catch 是否存在
  • 完整 fallback chain 邏輯測試(Layer 1 沒有 → 觸發 Layer 2)

Scope Drift 處理

項目 處理方式
migration-606/analysis/*.md ✅ 已刪除,不進 repo
try-catch 移除 ✅ 已恢復(也是 F2 修復)
loadEmbeddedPiRunner export ✅ 保留,SD3 是測試問題非 source code 問題

Commit: 6fde059 已 force-push 至 fix/sdk-migration-606.

@rwmjhb rwmjhb merged commit 09965e3 into CortexReach:master May 5, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Windows compatibility: path.join() bug + deprecated extension-api import

3 participants