Skip to content

fix(agents): merge upstream agent runtime refactor with Sprint 3.5-3.7 customizations#88

Merged
Piboonsak merged 2 commits into
mainfrom
copilot/fix-agent-runtime-merge
Apr 6, 2026
Merged

fix(agents): merge upstream agent runtime refactor with Sprint 3.5-3.7 customizations#88
Piboonsak merged 2 commits into
mainfrom
copilot/fix-agent-runtime-merge

Conversation

Copilot AI commented Apr 6, 2026

Copy link
Copy Markdown

Summary

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

None. All changes are internal test fixes and upstream normalization logic for provider ID lookup in history config.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Linux (CI)
  • Runtime/container: Node 22 / Vitest 4
  • Model/provider: N/A
  • Integration/channel (if any): N/A
  • Relevant config (redacted): N/A

Steps

  1. pnpm test -- src/agents/tool-loop-detection.test.ts src/agents/pi-tools.before-tool-call.test.ts

Expected

  • All 44 tool-loop-detection tests pass
  • All 13 before-tool-call tests pass

Actual

Before: 8 failures in tool-loop-detection.test.ts, 7 in pi-tools.before-tool-call.test.ts
After: 208/208 tests pass across all affected files

Evidence

  • Failing test/log before + passing after

Before (sample failures):

FAIL tool-loop-detection > detectToolCallLoop > does not flag unique tool calls
AssertionError: expected true to be false  // rapid_succession fires at call 16

FAIL before-tool-call > rapid_succession storm detection > blocks a tool storm
AssertionError: expected 'exec' to be 'bash'  // normalizeToolName alias

Fix pattern — tool-loop-detection.test.ts:

// Config variant that disables rapid_succession so other detectors can be tested
// without interference from consecutive same-tool-name triggering.
const noRapidSuccessionConfig: ToolLoopDetectionConfig = {
  enabled: true,
  detectors: { rapidSuccession: false },
};

// Before: used enabledLoopDetectionConfig (rapid_succession fires at call 16)
// After: use noRapidSuccessionConfig (only the target detector is exercised)
it("does not flag unique tool calls", () => {
  for (let i = 0; i < 15; i += 1) {
    recordToolCall(state, "read", { path: `/file${i}.txt` }, `call-${i}`);
  }
  const result = detectToolCallLoop(state, "read", { path: "/new-file.txt" }, noRapidSuccessionConfig);
  expect(result.stuck).toBe(false);
});

Fix pattern — before-tool-call.test.ts:

// "bash" normalizes to "exec" via TOOL_NAME_ALIASES in runBeforeToolCallHook
expect(stormEvent?.toolName).toBe("exec");
expect(stormEvent?.callTrace?.at(-1)).toBe("exec");

Human Verification (required)

  • Verified scenarios: rapid_succession detector still fires correctly in its own test suite (44 passes); storm integration test correctly detects bash-as-exec storm; known_poll, generic_repeat, global_circuit_breaker detectors all fire correctly when rapid_succession is disabled in their tests; history.ts provider lookup normalization tested via 138 pi-embedded-runner tests.
  • Edge cases checked: can disable specific detectors test now also disables rapidSuccession: false so all-off config truly returns stuck: false; callTrace in all detectors tests updated similarly.
  • What you did not verify: live gateway execution of storm scenarios end-to-end; compact.ts/errors.ts upstream replacements (deferred due to missing dependency chain).

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: git revert HEAD — test-only + provider-id utility changes, no runtime behavior changed.
  • Files/config to restore: src/agents/tool-loop-detection.test.ts, src/agents/pi-tools.before-tool-call.test.ts, src/agents/pi-embedded-runner/history.ts, src/agents/provider-id.ts
  • Known bad symptoms reviewers should watch for: if RAPID_SUCCESSION_THRESHOLD is lowered below WARNING_THRESHOLD (10), the noRapidSuccessionConfig guard in non-storm tests becomes unnecessary but harmless.

Risks and Mitigations

  • Risk: Tests that disable rapidSuccession might mask a real storm if the tool name changes.
    • Mitigation: Only non-storm tests disable it; the dedicated rapid_succession detector suite (8 tests) always runs with enabled: true and exercises the full detector path including bashexec normalization.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.anthropic.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js --local 18_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs 18_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js push�� 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js b/openclaw_githu/home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice ngs.cjs orks.js b/node_modules/.node b/node_modules/.--conditions (dns block)
  • api.openai.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js orks.js 18_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs 18_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js -E 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js x ngs.cjs orks.js b/node_modules/.node b/node_modules/.--conditions (dns block)
  • api.telegram.org
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js (dns block)
  • chatgpt.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js --local 18_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs 18_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js push�� 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js b/openclaw_githu/home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice ngs.cjs orks.js b/node_modules/.node b/node_modules/.--conditions (dns block)
  • example.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js --global pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js --no�� (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js --global (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js --global 18_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs 18_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js --no�� laywright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs laywright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js bin/git tool-call.test.t/opt/hostedtoolcache/node/24.14.1/x64/bin/node --local (dns block)
  • files.slack.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js -p 4513 fgrep -lxm�� 1 -- ndor/bin/bash /var/lib/dpkg/indocker /var/lib/dpkg/inps /var/lib/dpkg/in-a sh (dns block)
  • private.test
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js orks.js b/node_modules/.--ping b/node_modules/.pnpm/[email protected] d/bi�� 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js ache/node/24.14.1/x64/bin/node ngs.cjs orks.js b/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-p--experimental-import-meta-resolve b/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-p--require (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/openclaw_github/openclaw_github/node_modules/.pnpm/[email protected]_@opentelemetry&#43;[email protected]_@types&#43;[email protected]_@vitest&#43;browser-playwright@4._c9688654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js t/dist/workers/f--version b/openclaw_github/node_modules/.--noprofile 1/x64/bin/node cker�� 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/suppress-warnings.cjs 88654361f600a6ea7cb5666ec9fae/node_modules/vitest/dist/workers/forks.js b/node_modules/.bin/node t/suppress-warni/opt/hostedtoolcache/node/24.14.1/x64/bin/node t/dist/workers/f--conditions pnpm/[email protected] pnpm/[email protected] (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

- tool-loop-detection.test.ts: merge both test suites (upstream + ours);
  add noRapidSuccessionConfig to prevent rapid_succession from interfering
  with tests for other detectors (global_circuit_breaker, known_poll_no_progress,
  generic_repeat); add imports for CALL_TRACE_SIZE, RAPID_SUCCESSION_THRESHOLD,
  buildCallTrace
- pi-tools.before-tool-call.test.ts: add noRapidSuccessionContext for tests
  that drive other detectors; fix toolName expectation bash→exec (normalizeToolName
  alias); update createGenericReadRepeatFixture to accept context
- pi-embedded-runner/history.ts: apply upstream normalizeProviderId refactor
  (channel lookup now normalized) while keeping our limitHistoryByTokenBudget
- src/agents/provider-id.ts: bring in from upstream (new utility file required
  by history.ts normalizeProviderId import)"

Agent-Logs-Url: https://github.com/Piboonsak/openclaw_github/sessions/b0c56fb0-0133-4173-b3fb-103abe8cd68d
Copilot AI changed the title [WIP] Fix agents: merge agent runtime changes with upstream refactor fix(agents): merge upstream agent runtime refactor with Sprint 3.5-3.7 customizations Apr 6, 2026
Copilot AI requested a review from Piboonsak April 6, 2026 03:33
@Piboonsak
Piboonsak marked this pull request as ready for review April 6, 2026 07:30
@Piboonsak
Piboonsak merged commit 2f03256 into main Apr 6, 2026
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.

fix(agents): merge agent runtime changes with upstream refactor

2 participants