Skip to content

fix(active-memory): bound timeout circuit breakers - #105316

Merged
steipete merged 1 commit into
openclaw:mainfrom
ZOOWH:codex/active-memory-bound-timeout-breakers
Aug 26, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
ZOOWH:codex/active-memory-bound-timeout-breakers

Conversation

@ZOOWH

@ZOOWH ZOOWH commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Active Memory's process-local timeoutCircuitBreaker map could grow without bound: entries were only removed when the same key was checked after cooldown or after a later success, so distinct failing agent/provider/model combinations that were never revisited stayed for the process lifetime.

Why This Change Was Made

Bound the map in its current owner, extensions/active-memory/recall-state.ts. On each timeout, recordCircuitBreakerTimeout first removes all entries that have expired under the existing normalized circuitBreakerCooldownMs, including the current key, then refreshes the current entry's insertion order. After insertion, it evicts the oldest entry only when the existing DEFAULT_MAX_CACHE_ENTRIES limit of 1000 is exceeded. The sole production caller in extensions/active-memory/recall.ts supplies the already configured cooldown.

No configuration option, public interface, authorization boundary, or persistent storage changes. Production delta: +12 lines, justified by bounded process-local resource ownership.

User Impact

Before: Each new failing agent/provider/model combination could permanently add process state, and stale below-threshold timeout counts could survive their cooldown.

After: Expired timeout counts and peer entries honor the configured cooldown, distinct agent/provider/model circuit breakers remain isolated, and remaining process-local breaker state has a hard cap of 1000 keys.

Evidence

  • Base: 97196164358dd9b58bd6d2207ccfcd219a2492ad
  • Head: e1afbe815b71631c948ce3c95cd9f4b91e58c12a
  • Untouched-base regression: 5 failing cases and 1 passing isolation control.
  • Fixed-head regression: 8 passing tests, including 6 current-owner cases and 2 existing real plugin-registration/hook-dispatch timeout-and-recovery scenarios.
  • Owner behavior directly proves configured 5-second and 120-second cooldowns expire peer entries, expired current-key counters restart, the 1001st key evicts the oldest entry, refreshing an existing key preserves least-recently-updated eviction order, and agent/provider/model boundaries stay isolated.
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs \
  extensions/active-memory/recall-state.test.ts \
  extensions/active-memory/index.test.ts \
  -t 'active-memory timeout circuit breakers|skips recall after consecutive timeouts when circuit breaker trips|resets circuit breaker after a successful recall'
Test Files  2 passed (2)
     Tests  8 passed | 197 skipped (205)

Contributor's historical live Gateway proof

The original contributor also exercised the real gateway path while developing this PR; this historical proof demonstrates the reachable timeout and circuit-breaker behavior, while the exact-head regression above proves the corrected current owner, expiry, capacity, ordering, and recovery.

Environment tested: Windows, Node v24.18.0, real gateway child process with plugins.slots.memory=memory-core and plugins.entries.active-memory enabled; webchat Control UI client; hanging recall provider; fail-fast main provider.

  1. Start an ephemeral gateway with agents am0, am1, and am2, timeoutMs=800, circuitBreakerMaxTimeouts=1, circuitBreakerCooldownMs=600000, and logging enabled.
  2. Send webchat chat.send for each agent to produce distinct timeout keys.
  3. Immediately send again for am0 within its cooldown.
[plugins] active-memory: agent=am0 session=<redacted> activeProvider=hang activeModel=slow done status=timeout elapsedMs=2566 summaryChars=0
[plugins] active-memory: agent=am1 session=<redacted> activeProvider=hang activeModel=slow done status=timeout elapsedMs=4855 summaryChars=0
[plugins] active-memory: agent=am2 session=<redacted> activeProvider=hang activeModel=slow done status=timeout elapsedMs=4844 summaryChars=0
[plugins] active-memory: agent=am0 session=<redacted> activeProvider=hang activeModel=slow skipped (circuit breaker open after consecutive timeouts)

Observed historical result: Three distinct timeout records and one same-agent circuit-breaker skip; the gateway loaded both active-memory and memory-core.

Not tested: A multi-hour live-gateway 1000-key soak. The exact-head owner regression directly covers capacity eviction, cooldown expiry, ordering, isolation, and the registered plugin timeout/recovery flow.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 12, 2026
@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 26, 2026, 5:44 AM ET / 09:44 UTC.

ClawSweeper review

What this changes

Bounds Active Memory’s process-local timeout circuit-breaker map by removing cooled entries and evicting the oldest entry above 1,000 keys.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 7 items remain

Keep open: the new capacity eviction can reopen an already-tripped breaker before its documented cooldown expires, so the patch is not ready to merge.

Priority: P1
Reviewed head: e1afbe815b71631c948ce3c95cd9f4b91e58c12a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The PR has a focused owner-side repair and useful regression coverage, but its cap behavior conflicts with the cooldown contract and lacks direct after-fix proof.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The supplied historical gateway logs show timeout and breaker-skip behavior, but not the branch’s after-fix expiry or 1,000-key capacity behavior; add a redacted after-fix gateway trace before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The supplied historical gateway logs show timeout and breaker-skip behavior, but not the branch’s after-fix expiry or 1,000-key capacity behavior; add a redacted after-fix gateway trace before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main behavior: Current main still records timeout entries without expiry or capacity cleanup, so the central bounded-state behavior is not already implemented.
Configured cooldown contract: The plugin metadata promises to skip recall for the configured cooldown after the breaker trips.
Introduced compatibility break: After inserting a timeout entry, the patch deletes the oldest key whenever the map exceeds 1,000 entries, regardless of whether that key is still within its cooldown.
Findings 1 actionable finding [P1] Preserve the configured cooldown when the map reaches capacity
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/active-memory/recall-state.test.ts

Result: FAIL (partial) — step 2 expect_output active-memory timeout circuit breakers: expected terminal output was not visible within 30 seconds: "active-memory timeout circuit breakers"

[test] starting test/vitest/vitest.extension-active-memory.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-105316-qd5wwc/target

 ✓  extension-active-memory  extensions/active-memory/recall-state.test.ts (6 tests) 141ms

 Test Files  1 passed (1)
      Tests  6 passed (6)
   Start at  09:45:46
   Duration  1.62s (transform 1.22s, setup 973ms, import 138ms, tests 141ms, environment 0ms)

[test] passed 1 Vitest shard in 8.00s
[test] starting test/vitest/vitest.extension-active-memory.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-105316-qd5wwc/target

 ✓  extension-active-memory  extensions/active-memory/recall-state.test.ts (6 tests) 92ms

 Test Files  1 passed (1)
      Tests  6 passed (6)
   Start at  09:45:55
   Duration  834ms (transform 377ms, setup 444ms, import 62ms, tests 92ms, environment 0ms)

[test] passed 1 Vitest shard in 7.31s

Assertions:

  • FAIL expect_output: active-memory timeout circuit breakers
  • FAIL expect_output: Test Files

How this fits together

Active Memory invokes a recall subagent through the plugin hook and records timeout state by agent, provider, and model. Later recall attempts consult that state to decide whether to skip work during the configured cooldown.

flowchart LR
A[Plugin recall hook] --> B[Recall subagent]
B --> C[Timeout breaker state]
C --> D{Breaker open?}
D -->|yes| E[Skip recall]
D -->|no| F[Run recall]
F --> C
C --> G[Expiry and capacity cleanup]
Loading

Decision needed

Question Recommendation
When Active Memory reaches 1,000 timeout keys, may eviction reopen an already-tripped breaker before its configured cooldown ends? Preserve active cooldowns: Keep tripped breakers until cooldown expiry and make capacity pressure affect only admission of new or non-open state.

Why: The existing plugin contract promises a cooldown duration, while a strict fixed-size map requires an explicit priority rule when all retained entries are live.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The supplied historical gateway logs show timeout and breaker-skip behavior, but not the branch’s after-fix expiry or 1,000-key capacity behavior; add a redacted after-fix gateway trace before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve the configured cooldown when the map reaches capacity (P1) - Evicting the oldest entry here can delete a breaker that is still open. The next recall sees no entry and runs before its configured cooldown, contradicting the plugin’s documented cooldown behavior; retain open breakers or explicitly choose and document a different admission policy.
  • Resolve merge risk (P2) - At 1,001 live keys, eviction can turn a still-open breaker into a missing entry and re-enable a recall before the documented cooldown, risking renewed timeout work.
  • Resolve merge risk (P1) - The PR has a net production increase of 12 lines; a bounded state owner needs this behavior, but the cap policy must be resolved before that growth is justified.
  • Resolve merge risk (P2) - The supplied gateway log shows timeout and skip behavior, not after-fix cooldown cleanup or capacity behavior.
  • Complete next step (P2) - A maintainer must choose the documented cooldown-versus-capacity policy before a mechanical repair can be safely routed.

Findings

  • [P1] Preserve the configured cooldown when the map reaches capacity — extensions/active-memory/recall-state.ts:60-63
Agent review details

Security

None.

PR surface

Source +12, Tests +86. Total +98 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 19 7 +12
Tests 1 86 0 +86
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 105 7 +98

Review metrics

Metric Value Why it matters
Production vs test delta production +18/-6 (net +12); tests +86 The added owner-side cleanup is small but changes a configured breaker’s lifetime semantics, so the positive production growth needs the resolved cap policy.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/active-memory/recall-state.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Preserve configured cooldowns (recommended)
    Change capacity handling so an open breaker cannot be evicted before cooldown expiry, and add an end-to-end hook regression for the 1,001-key case.
  2. Accept early reopening explicitly
    If maintainers choose a hard cap over the existing cooldown promise, document the changed semantics and accept the resulting timeout-retry risk.

Technical review

Best possible solution:

Preserve the configured cooldown for already-tripped breakers under capacity pressure, define bounded admission for new state explicitly, add a hook-level regression, and then provide a redacted after-fix gateway trace.

Do we have a high-confidence way to reproduce the issue?

Yes—source-reproducible: configure a one-timeout breaker, create 1,001 distinct keys within the cooldown, then query the oldest key; eviction makes it appear closed before its cooldown expires.

Is this the best way to solve the issue?

No: the LRU cap is a plausible memory bound but violates the existing cooldown contract; capacity admission must preserve live breaker protection or receive explicit approval as a contract change.

Full review comments:

  • [P1] Preserve the configured cooldown when the map reaches capacity — extensions/active-memory/recall-state.ts:60-63
    Evicting the oldest entry here can delete a breaker that is still open. The next recall sees no entry and runs before its configured cooldown, contradicting the plugin’s documented cooldown behavior; retain open breakers or explicitly choose and document a different admission policy.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a901d3318474.

Labels

Label changes:

  • add P1: The patch can cause a configured timeout breaker to reopen early and repeat failing recall work under capacity pressure.
  • add merge-risk: 🚨 compatibility: Evicting a live breaker changes the documented cooldown behavior for existing configurations.
  • add merge-risk: 🚨 availability: Early eviction can reissue recalls that the breaker would otherwise suppress after repeated timeouts.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • remove P2: Current review triage priority is P1, so this older priority label is no longer current.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: The patch can cause a configured timeout breaker to reopen early and repeat failing recall work under capacity pressure.
  • merge-risk: 🚨 compatibility: Evicting a live breaker changes the documented cooldown behavior for existing configurations.
  • merge-risk: 🚨 availability: Early eviction can reissue recalls that the breaker would otherwise suppress after repeated timeouts.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The supplied historical gateway logs show timeout and breaker-skip behavior, but not the branch’s after-fix expiry or 1,000-key capacity behavior; add a redacted after-fix gateway trace before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Prior work on Active Memory recall state is the closest available history signal for the owner module. (role: recent area contributor; confidence: medium; commits: 1b9481012b59; files: extensions/active-memory/recall-state.ts, extensions/active-memory/recall.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Preserve an open breaker through its configured cooldown under capacity pressure and add a regression using maxTimeouts=1.
  • Add redacted after-fix gateway evidence for the changed expiry/capacity behavior.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-31T16:31:29.464Z sha 5bf424dcac506de725fe117724a862bcd0ca4672 :: needs changes before merge. :: [P1] Rebase breaker state handling into the current owner
  • reviewed 2026-08-05T10:48:08.334Z sha 5bf424dcac506de725fe117724a862bcd0ca4672 :: needs changes before merge. :: [P1] Move breaker state handling to its current owner
  • reviewed 2026-08-14T07:19:33.051Z sha 5bf424dcac506de725fe117724a862bcd0ca4672 :: needs real behavior proof before merge. :: [P1] Port circuit-breaker mutation to recall-state
  • reviewed 2026-08-14T19:06:40.863Z sha 5bf424dcac506de725fe117724a862bcd0ca4672 :: needs real behavior proof before merge. :: [P1] Port breaker mutation to the current state owner
  • reviewed August 15, 2026, 5:42 PM ET / 21:42 UTC sha unknown :: needs real behavior proof before merge. :: [P1] Move breaker mutation into recall-state
  • reviewed 2026-08-18T09:49:12.085Z sha 5bf424dcac506de725fe117724a862bcd0ca4672 :: needs real behavior proof before merge. :: [P1] Port breaker cleanup to recall-state
  • reviewed 2026-08-23T16:26:46.554Z sha 5bf424dcac506de725fe117724a862bcd0ca4672 :: needs real behavior proof before merge. :: [P1] Move breaker cleanup to the recall-state owner
  • reviewed 2026-08-26T09:31:38.707Z sha e1afbe8 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 12, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 12, 2026
@ZOOWH
ZOOWH force-pushed the codex/active-memory-bound-timeout-breakers branch from e5f35da to 5bf424d Compare July 12, 2026 15:49
@ZOOWH

ZOOWH commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 12, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 28, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 31, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 23, 2026
@steipete
steipete force-pushed the codex/active-memory-bound-timeout-breakers branch from 5bf424d to e1afbe8 Compare August 26, 2026 09:25
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 26, 2026
@steipete
steipete merged commit e69b076 into openclaw:main Aug 26, 2026
124 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: active-memory merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants