Skip to content

fix(memory): preserve standing intents after prompt hook timeouts - #145107

Merged
steipete merged 2 commits into
mainfrom
codex/standing-intent-hook-lifetime-20260911
Sep 11, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/standing-intent-hook-lifetime-20260911

Conversation

@steipete

@steipete steipete commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Related: #144832, #116522

What Problem This Solves

Fixes an issue where a standing intent could spend a reminder fire after its prompt hook had timed out, leaving the reminder unavailable even though its context never reached that prompt.

Why This Change Was Made

The hook runner gives each before_prompt_build handler its own hookInvocation.assertActive() capability and expires it when that handler returns, rejects, or times out. Memory Core checks it after lazy loading and immediately before its synchronous database effects. Shared database admission and underlying work keep their existing ownership and cleanup.

This is a scoped result-eligibility guard for ordinary and authorized prompt phases. The separate cooperative-cancellation proposal in #116522 remains open; this change does not address its broader cancellation and child-process lifecycle scope or close #115450.

User Impact

Late matching no longer consumes a standing-intent fire. A host without the required capability logs a clear diagnostic and skips matching without consuming the intent. The SDK field is optional for compatibility and grants neither tool authorization nor a guarantee of eventual model consumption.

Evidence

  • The actual registered-hook/SQLite regression failed on the original source: after the discarded result, the row became done with fire_count: 1. It passes with the repair. All 91 focused tests across seven files pass, including configured short deadlines, stale-first/live-second handlers in both phases, missing-host diagnostics, and a live caller sharing cold admission.
  • The delay and hook timeout are controlled by the fixture/fake timers. Hook dispatch, SQLite effects, and the cold-open child in the coalesced-caller control are real; this is not measured production latency or live Gateway proof.
  • Full selected changed checks passed. Fresh PR-head Linux CI at d3f34c5ce8ac504dfcfb3e454d83ae176b70c749 executed 68 of the 91 focused cases across four files, including the registered-hook/SQLite timeout regression, missing-host diagnostic, live coalesced cold-open control, and all eight invocation cases. The remaining three unchanged plugin sibling files were verified locally. The standalone Testbox attempt stopped at provider status lookup before execution; its lease is closed and no standalone Linux result is claimed.
  • Independent P2 code review is clean, with an additional source-based assessment of the distinct lifetime semantics versus fix(plugins): abort hook ctx.abortSignal on hook timeout expiry #116522.

Review Disposition

The host and Memory Core consumer are updated together in this PR; Memory Core is a private bundled plugin. Diagnostic skipping on an unsupported host is the intentional compatibility behavior, covered by the missing-capability regression and documented in the hook guide.

The data-model warning does not correspond to a stored-format change. The patch adds an invocation assertion before the existing standing-intent database callback; schema definitions, schema assurance, lifecycle SQL, claim SQL, row encoding, indexes, and migration versions are unchanged. Existing stored intents use the same database and transaction path when the handler remains active. No data migration is introduced or needed.

The controlled timeout regression proves the discarded-result/late-write invariant, not measured live Gateway latency. The first run failed an unrelated daemon-test file-length check on its synthetic merge base; main already repaired that check. The subsequent main integration leaves this PR’s full nine-file patch byte-identical to the reviewed original. Fresh Linux jobs passed again on the refreshed PR head: Memory Core and hook invocation. Both ran on Ubuntu 24.04.3 with Node 24.19.0, using synthetic merge fbda7e2b322e7bd6c2eaac47232af4e57cacc002 into main 58a6953549d011ffe44dcc3a7f3290b50e64b349. No focused case was skipped. The failed standalone Testbox attempt remains unverified and is not counted as test evidence.

Give each before_prompt_build handler an ephemeral result-acceptance
capability and revoke it when the runner stops awaiting that handler.
Memory Core checks it after lazy loading and before its synchronous
standing-intent effects, preserving live callers of a shared database open.

Missing host support produces a diagnostic without consuming a reminder.
Document the optional SDK capability and cover timed-out, settled, and
coalesced callers. Underlying work retains its existing cleanup lifecycle.

Related: #144832
Validation: 91 focused tests, selected changed checks, and independent P2 review.
@clawsweeper

clawsweeper Bot commented Sep 11, 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 docs Improvements or additions to documentation extensions: memory-core Extension: memory-core size: M maintainer Maintainer-authored PR labels Sep 11, 2026
@steipete
steipete marked this pull request as ready for review September 11, 2026 17:47
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Sep 11, 2026
@clawsweeper

clawsweeper Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 11, 2026, 2:06 PM ET / 18:06 UTC (Revision 2).

ClawSweeper review

What this changes

Adds a per-handler prompt-hook lifetime check so delayed Memory Core matching cannot consume a reminder after its hook times out, with regression tests and SDK documentation.

Merge readiness

⛔ Blocked before merge - 2 items remain

This fix remains necessary on current main, and no actionable patch defects were found. The updated disposition resolves the prior compatibility and migration concerns.

Priority: P2
Reviewed head: d3f34c5ce8ac504dfcfb3e454d83ae176b70c749

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with useful boundary regressions, clear compatibility disposition, and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer-author classification exempts this PR from external-contributor proof. Its reported registered-hook/SQLite regression exercises delayed matching and shared cold admission with controlled timing; it is not live Gateway evidence, and the unsuccessful Testbox attempt is not counted.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer-author classification exempts this PR from external-contributor proof. Its reported registered-hook/SQLite regression exercises delayed matching and shared cold admission with controlled timing; it is not live Gateway evidence, and the unsuccessful Testbox attempt is not counted.
Evidence reviewed 9 items Per-handler lifetime ownership: The introduced hook-runner change creates an independent capability for each before_prompt_build handler and revokes it in finally before result merging, error handling, or the next handler. Both ordinary and authorized prompt phases use this dispatcher.
Guard precedes existing synchronous effects: Memory Core checks lifetime after lazy loading and again inside the admitted database callback, before schema assurance and the synchronous matching transaction. Row encoding, lifecycle SQL, claim SQL, transaction boundaries, and schema versions are unchanged.
Shared admission remains independent: The database owner's optional third-argument assertion also governs the initiating physical open. Keeping hook expiry inside Memory Core's callback avoids rejecting that shared open and preserves other admitted callers.
Findings None None.
Security None None.

How this fits together

Memory Core stores event-triggered reminders and matches them against incoming user prompts. Prompt hooks inject matching reminders into model context while updating their stored fire budgets.

flowchart TD
  A[User prompt] --> B[Prompt hook handler]
  B --> C[Shared database admission]
  C --> D{Handler still active?}
  D -->|Yes| E[Match and update reminder budget]
  E --> F[Reminder context for model]
  D -->|No| G[Preserve reminder budget]
Loading

Before merge

  • Resolve merge risk (P1) - Pairing the updated Memory Core plugin independently with an older host disables reminder matching with a warning; the documented, accepted rollout updates this private bundled plugin and host together.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +37, Tests +296, Docs +28. Total +361 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 46 9 +37
Tests 2 300 4 +296
Docs 3 28 0 +28
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 374 13 +361

Review metrics

Metric Value Why it matters
Plugin API addition 1 optional context capability; 0 new configuration options The public addition is limited to handler lifetime and includes a concrete bundled consumer and compatibility documentation.
Production versus regression coverage Production net +37 lines; tests net +296 lines Production growth implements the shared lifetime guard; coverage exercises timeout, settlement, unsupported hosts, and shared admission.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/memory-core/src/standing-intents.ts, vector/embedding metadata: extensions/memory-core/index.ts, vector/embedding metadata: extensions/memory-core/src/standing-intents.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Retain the accepted bundled rollout (recommended)
    Keep host and Memory Core paired, with the documented warning-and-skip behavior for unsupported hosts.

Technical review

Best possible solution:

Ship the paired host/plugin repair with handler lifetime owned by the runner and existing reminder storage and shared-admission semantics preserved.

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

Yes, from source: hold database admission beyond the prompt-hook timeout, then resume matching; current main can still consume the fire after discarding the hook result. The registered-path regression covers this sequence, but was not rerun here.

Is this the best way to solve the issue?

Yes. The runner owns result eligibility, and Memory Core checks it immediately before synchronous effects without cancelling shared database work or changing stored formats.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 58a6953549d0.

Labels

Label justifications:

  • P2: This repairs a bounded reminder-budget loss when prompt matching completes after timeout.
  • merge-risk: 🚨 compatibility: Memory Core now requires the new host capability at runtime, with unsupported-host skipping explicitly accepted for the paired bundled rollout.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied maintainer-author classification exempts this PR from external-contributor proof. Its reported registered-hook/SQLite regression exercises delayed matching and shared cold admission with controlled timing; it is not live Gateway evidence, and the unsuccessful Testbox attempt is not counted.

Evidence

What I checked:

  • Per-handler lifetime ownership: The introduced hook-runner change creates an independent capability for each before_prompt_build handler and revokes it in finally before result merging, error handling, or the next handler. Both ordinary and authorized prompt phases use this dispatcher. (src/plugins/hooks.ts:863, d3f34c5ce8ac)
  • Guard precedes existing synchronous effects: Memory Core checks lifetime after lazy loading and again inside the admitted database callback, before schema assurance and the synchronous matching transaction. Row encoding, lifecycle SQL, claim SQL, transaction boundaries, and schema versions are unchanged. (extensions/memory-core/src/standing-intents.ts:76, d3f34c5ce8ac)
  • Shared admission remains independent: The database owner's optional third-argument assertion also governs the initiating physical open. Keeping hook expiry inside Memory Core's callback avoids rejecting that shared open and preserves other admitted callers. (src/state/openclaw-agent-db-admission.ts:71, d3f34c5ce8ac)
  • Meaningful registered-path regression coverage: Tests register the actual Memory Core plugin, delay admission, expire the hook, resume outstanding work, and assert that the stored intent remains armed with fire_count zero. Additional cases cover unsupported hosts and a live caller sharing cold admission. Hook-runner tests cover settlement and sibling isolation in both phases. The body reports 91 passing focused cases and an original-source failure; tests were inspected but not executed during this read-only review. (extensions/memory-core/src/standing-intents.async.test.ts:301, d3f34c5ce8ac)
  • Compatibility disposition is explicit: The captured body and live body both explain that the private bundled Memory Core plugin and host update together, and intentionally accept diagnostic skipping on unsupported hosts. The optional SDK field and its limits are documented. The previous review contained no findings or published rank-up moves. Public docs: docs/plugins/hooks/prompt-and-session.md. (docs/plugins/hooks/prompt-and-session.md:70, d3f34c5ce8ac)
  • Current main still needs the repair: Live main remains at the supplied base SHA. Its hook dispatcher still awaits withHookTimeout without a handler-lifetime capability, and its asynchronous standing-intent callback has no invocation guard. (src/plugins/hooks.ts:863, 58a6953549d0)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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 (1 earlier review cycle)
  • reviewed 2026-09-11T17:47:06.162Z sha 0a66c62 :: blocked before merge. :: none

Merge current main to pick up the existing daemon install test lint repair. The standing-intent patch against the merged main is byte-identical to the reviewed original; no new product changes.
@steipete
steipete merged commit ddcbea7 into main Sep 11, 2026
182 checks passed
@steipete
steipete deleted the codex/standing-intent-hook-lifetime-20260911 branch September 11, 2026 18:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 12, 2026
…enclaw#145107)

Give each before_prompt_build handler an ephemeral result-acceptance
capability and revoke it when the runner stops awaiting that handler.
Memory Core checks it after lazy loading and before its synchronous
standing-intent effects, preserving live callers of a shared database open.

Missing host support produces a diagnostic without consuming a reminder.
Document the optional SDK capability and cover timed-out, settled, and
coalesced callers. Underlying work retains its existing cleanup lifecycle.

Related: openclaw#144832
Validation: 91 focused tests, selected changed checks, and independent P2 review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

Hook timeout releases lane but leaves hook child processes alive

1 participant