Skip to content

fix(memory-lancedb): keep the cold-start embed deadline on the monotonic clock - #186037

Merged
obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/memory-lancedb-embed-deadline-monotonic-237
Oct 27, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/memory-lancedb-embed-deadline-monotonic-237

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A healthy memory_recall (or automatic prompt recall) can be rejected as a timeout — or an expired embedding request can be dispatched past its budget — when the host wall clock steps during a provider cold start. In extensions/memory-lancedb/embeddings.ts, ProviderAdapterEmbeddings.embed() seeds its absolute embed deadline with Date.now() and, after awaiting the shared provider's cold-start initialization, recomputes the remaining abort budget with Date.now() again: a forward step shrinks (or negates) the budget so a healthy query is fenced as memory-lancedb embedding timed out, while a rollback inflates it so an already-expired query is dispatched — exactly the "never dispatch that expired query" case the guard exists to stop.

Why This Change Was Made

The embed deadline is process-local — never persisted, never compared against a wall-clock epoch by another process — so the monotonic clock is the only correct source, matching the repo's wall-clock-to-monotonic pattern (merged #177155, #183104, #184711 for the sibling recall-deadline path in the same file).

  • Seed now uses performance.now() instead of Date.now().
  • The remaining-budget read is Math.floor(deadlineAtMs - performance.now()), keeping the integer contract setTimeout requires.
  • This is the cold-start path fix(memory-lancedb): use monotonic clock for recall deadline budget #184711 explicitly scoped out ("cold-start deadline ... out of scope"); the fixes are complementary, not overlapping.
  • No signature, config, or persisted-data change; production net +2 lines (an oxfmt line-wrap, not new logic).

User Impact

A healthy recall whose provider is still cold-starting is no longer rejected because the clock stepped forward mid-initialization, and an expired query can no longer be dispatched past its budget after a rollback. Timeout text, result ordering, and error reporting are unchanged.

Evidence

Shipped entry point: real recall across a clock step

A real openclaw agent --local turn (real plugin load, real RecallService, real provider adapter, real HTTP embedding dispatch to a local OpenAI-compatible endpoint that logs every request). A --import shim steps Date.now by +30 s between the adapter's deadline seed and its remaining-budget read — the window a host clock correction lands in. It matches the direct caller frame, so the seed keeps the real clock and only the read is stepped. Every run starts from a fresh state dir, so the provider is always cold-started.

Pre-fix (Date.now seed + read): healthy recall fenced, no embedding request ever sent.

CLOCK_SEED real=1793116945400 offset=30000 arm=1 seedReturnsReal=1
CLOCK_READ real=1793116945441 stepped=1793116975441 offset=30000
CLOCK_SUMMARY adapterDateNowCalls=2 stepped=true offset=30000
# endpoint log: chat only, zero /v1/embeddings requests
CHAT_REQUEST at=131458ms
[plugins] memory-lancedb: recall failed: MemoryRecallEmbeddingError: memory-lancedb embedding timed out

Post-fix (performance.now seed + read): same shim, same step, recall dispatches.

CLOCK_SUMMARY adapterDateNowCalls=0 stepped=false offset=30000
EMBED_REQUEST at=141768ms model=text-embedding-3-small inputs=1 first="Which editor do you recommend?"
EMBED_RESPONDED at=141773ms
CHAT_REQUEST at=142914ms
# no timeout line anywhere in the run

Control (pre-fix source, shim loaded, offset 0): same path without the step dispatches normally, so the failure above is the clock step, not the harness.

CLOCK_DISABLED offset=0 mode=control
EMBED_REQUEST at=173117ms model=text-embedding-3-small inputs=1 first="Which editor do you recommend?"

The step is injected rather than host-NTP; the measured seed→read window here was 41 ms (1793116945400 → 1793116945441), which is exactly the window an instantaneous clock correction lands in.

Timeout still enforced after the fix

A 16 s embedding response against the 15 s recall budget is still abandoned at the budget:

EMBED_REQUEST at=151123ms ... delayMs=16000
[plugins] memory-lancedb: auto-recall timed out after 15000ms; skipping memory injection to avoid stalling agent startup

Regression test RED / GREEN

keeps the cold-start embed deadline on the monotonic clock across a wall-clock step (auto-recall.deadline.test.ts) uses a synthetic cold provider (pending ready.promise) and vi.setSystemTime to step Date.now() by +30 s between seed and read.

$ npx vitest run extensions/memory-lancedb/auto-recall.deadline.test.ts   # pre-fix (Date.now)
 ✗ keeps the cold-start embed deadline on the monotonic clock across a wall-clock step
   expect(requests[0]?.aborted).toBe(false)   // requests empty: query fenced pre-dispatch
 Tests  1 failed | 2 passed (3)

$ npx vitest run extensions/memory-lancedb/auto-recall.deadline.test.ts   # post-fix (performance.now)
 ✓ 3 passed

Full memory-lancedb shard

node scripts/run-vitest.mjs extensions/memory-lancedb --run → 18 passed | 1 failed files, 115 passed | 1 failed tests. The single failure is arrow-null-predicates.test.ts, which fails identically on clean main (EvalError: Code generation from strings disallowed — apache-arrow's new Function predicate compilation blocked in this Node context); pre-existing, unrelated, and recorded as such.

Merge risk

Two-way door: reverting restores the previous process-local deadline calculation; no state migration or published contract changes. Blast radius is memory-lancedb cold-start embed deadline handling.

Independent bundled-enable Gateway Evidence

#186037 (comment)

Enabled the bundled memory-lancedb with the shipped CLI (no plugin install). Fresh built Gateway cold starts, +30s process-only Date.now correction: main twice times out without dispatching embeddings; candidate twice sends one embedding request and completes recall. Both no-step controls complete recall. The same actual clock correction is recorded on both refs. No source edits or pushes were required.

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-lancedb Extension: memory-lancedb size: S labels Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes the embedding adapter’s cold-start timeout budget independent of wall-clock changes.

Example: The wall clock advances 30 seconds during provider initialization for a recall with a 15-second budget.

  • Before: A healthy recall is rejected before its embedding request is sent.
  • After: The embedding request receives the remaining elapsed-time budget and dispatches normally.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with shipped-entry evidence, a distinct red/green regression, passing affected CI, and no open findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied openclaw agent --local traces exercise real plugin loading, the cold-start provider adapter, and HTTP embedding dispatch with an injected forward clock step, a no-step control, and delayed-response timeout enforcement, satisfying the previous review’s requested proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Memory recall can fail despite an available embedding provider when the host clock changes during initialization.
Reason: The change restores elapsed-time timeout semantics without introducing configuration, public APIs, persisted state, or another owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current cold-start deadline bug with a focused patch, adequate behavior proof, passing affected checks, and no actionable findings.

Priority: P2
Reviewed head: 21b6ce9616526d40a53674ced082d84dfacd752f

Before merge

None.

Findings

None.

Agent review details

How this fits together

Explicit and automatic memory recall pass a timeout budget through the embedding adapter, which initializes a shared provider and returns a vector for LanceDB search.

flowchart TD
  A[Memory recall or prompt hook] --> B[Recall deadline]
  B --> C[Embedding adapter]
  C --> D[Shared provider initialization]
  D --> E[Bounded embedding request]
  E --> F[LanceDB search]
Loading

Technical review

Best possible solution:

Use the existing adapter’s monotonic deadline calculation while preserving shared provider initialization and timeout enforcement.

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

Current-main source shows the two wall-clock reads around awaited initialization, and the contributor supplies a failing CLI trace plus a successful no-step control; no target code was executed during this review.

Is this the best way to solve the issue?

This is the smallest complete production repair: change the existing deadline’s clock source and retain its expiration check, abort timer, and provider lifecycle.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 32679f5ac9f9.

Provenance checked

  • Provider-adapter cold-start deadline keeps the original intent (5dda1e2: Prevent expired recall queries from dispatching or receiving a fresh timeout after shared provider initialization consumes their budget.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +2, Tests +71. Total +73 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 2 +2
Tests 1 71 0 +71
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 75 2 +73

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Clock corrections during cold provider initialization can suppress healthy memory recall or extend embedding work beyond its intended budget.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-27T15:06:37.934Z sha 21b6ce9 :: needs real behavior proof before merge. :: none

Reviewed October 27, 2026, 12:38 PM ET / 16:38 UTC (Revision 2).

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Independent bundled-memory cold-start proof

Compared main 24e16034180f7a08eda5f17d2a2b573cde1868a5 and exact candidate 21b6ce9616526d40a53674ced082d84dfacd752f using built Node 24.22.1 Linux Docker Gateways and fresh task-owned state/processes.

Each run executes the shipped plugins enable memory-lancedb command, which reports Enabled plugin "memory-lancedb". Saved for the next Gateway start. The bundled plugin is enabled, not installed. The public tools.invoke → memory_recall path uses the real RecallService, provider adapter and LanceDB, with an external local OpenAI-compatible embedding HTTP fixture.

An in-process preload observes the real lazy embedding-provider SDK import using Node's loader-resolution hook and applies +30 seconds to Date.now only during that cold-start await. Module resolution and provider implementations are returned unchanged; nothing is held or replaced. The recorded real/shifted clock values confirm exactly +30000ms in every stepped main and candidate run. Real timers, performance.now and the HTTP observer remain unchanged; no system clock change.

Run Clock correction Embedding HTTP requests Recall result Genuine elapsed
Main 1 +30s 0 unavailable: embedding timed out 469 ms
Main 2 +30s 0 unavailable: embedding timed out 478 ms
Candidate 1 +30s 1 No relevant memories found; count 0 530 ms
Candidate 2 +30s 1 No relevant memories found; count 0 478 ms
Main no-step control none 1 No relevant memories found; count 0 539 ms
Candidate no-step control none 1 No relevant memories found; count 0 487 ms

Main falsely exhausts the healthy cold-start budget before dispatching any embedding request. The candidate dispatches and completes recall normally, like the controls. These are fresh empty LanceDB stores, not raw database seeding or mocked adapters. No real provider credentials or plugin installation were used.

This independent run proves the forward-step cold-start defect and normal recall controls. It does not independently claim rollback-overrun or delayed-endpoint timeout coverage; the contributor's separate regression/proof remains attributable to them. No source changes or pushes were needed.

@obviyus
obviyus merged commit bde8a4e into openclaw:main Oct 27, 2026
145 of 146 checks passed
@obviyus

obviyus commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Landed in bde8a4e. Thanks @SunnyShu0925. The first LanceDB recall no longer times out after a clock jump.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@obviyus Thanks!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…nic clock (openclaw#186037)

fix(memory-lancedb): keep the cold-start embed deadline on the monotonic clock

The memory-lancedb embed deadline was measured with the wall clock during cold initialization, so a forward clock step while the provider loaded made the first recall time out before any embedding request was sent. The deadline now uses monotonic time.

Evidence: the bundled memory-lancedb enabled with shipped `plugins enable` on a built Gateway, real memory_recall, a local embedding fixture, and Date.now stepped forward 30 seconds inside the process during the lazy provider import. On main the recall timed out with 0 embedding requests (twice); with this change it sent 1 request and completed (twice), like the no-step runs on both refs. Details: openclaw#186037 (comment). Production 6 lines.

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 28, 2026
…nic clock (#186037)

fix(memory-lancedb): keep the cold-start embed deadline on the monotonic clock

The memory-lancedb embed deadline was measured with the wall clock during cold initialization, so a forward clock step while the provider loaded made the first recall time out before any embedding request was sent. The deadline now uses monotonic time.

Evidence: the bundled memory-lancedb enabled with shipped `plugins enable` on a built Gateway, real memory_recall, a local embedding fixture, and Date.now stepped forward 30 seconds inside the process during the lazy provider import. On main the recall timed out with 0 embedding requests (twice); with this change it sent 1 request and completed (twice), like the no-step runs on both refs. Details: #186037 (comment). Production 6 lines.

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>

Beta.5 baseline adaptation: Measure provider cold-start budget monotonically and floor remaining timeout; preserve prior outer recall budget.

(cherry picked from commit bde8a4e)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit c3a8914eb7a6e532c0668765a17d8258307f7dd7)
RomneyDa added a commit that referenced this pull request Oct 28, 2026
…nic clock (#186037)

fix(memory-lancedb): keep the cold-start embed deadline on the monotonic clock

The memory-lancedb embed deadline was measured with the wall clock during cold initialization, so a forward clock step while the provider loaded made the first recall time out before any embedding request was sent. The deadline now uses monotonic time.

Evidence: the bundled memory-lancedb enabled with shipped `plugins enable` on a built Gateway, real memory_recall, a local embedding fixture, and Date.now stepped forward 30 seconds inside the process during the lazy provider import. On main the recall timed out with 0 embedding requests (twice); with this change it sent 1 request and completed (twice), like the no-step runs on both refs. Details: #186037 (comment). Production 6 lines.

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit bde8a4e)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 632d0be1325d682b0b82f05bdc78c603c617f1b7)
amittell added a commit to amittell/openclaw that referenced this pull request Nov 1, 2026
…o the fork's 5 s budget

beta.5 added "includes %ims of cold provider initialization in the auto-recall deadline" (openclaw#182340,
openclaw#186037) with cases 10_000 and 16_000 around upstream's 15_000 ms auto-recall budget. The fork keeps
auto-recall at 5_000 ms (auto-recall.ts AUTO_RECALL_TIMEOUT_MS), so the 10_000 case expected a request
the fork never makes: it failed 3 of 3 alone on the carry and passed 3 of 3 on bare beta.5.

The cases now straddle 5_000 (3_000 inside, 6_000 past), and the remaining-budget advance uses 5_000.
The test still checks that cold initialization counts against the deadline: the 3_000 case expects the
request aborted at 5 s total, not 5 s after the provider is ready.

Control: with AUTO_RECALL_TIMEOUT_MS set back to 15_000, both adapted cases fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-lancedb Extension: memory-lancedb P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants