Skip to content

fix(active-memory): reuse current requests across prompt rebuilds - #147193

Closed
sercada wants to merge 1 commit into
openclaw:mainfrom
sercada:fix/active-memory-current-request
Closed

sercada wants to merge 1 commit into
openclaw:mainfrom
sercada:fix/active-memory-current-request

Conversation

@sercada

@sercada sercada commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Related: #88077, #106957, #115627. Alternative to the envelope-parsing approach in #110898.

What Problem This Solves

Fixes Active Memory treating reconstructed conversation history as the current request and spending another recall budget when the same request's prompt is rebuilt.

User Impact

With the harness producer update below, old history no longer activates recall for an ordinary new message, and prompt rebuilding reuses the current request's result. Different requests and authorization/resource scopes remain independent. There are no configuration or memory-source changes.

Integration dependency: the Codex producer is in a separate repository that is unavailable to this contributor. This PR supplies the public hook contract, core relay, and Active Memory consumer; Codex must supply the two optional fields below for the reconstructed-prompt fix to take effect. Existing producers retain their current behavior until updated. This PR is not presented as a complete standalone Codex rollout.

Why This Change Was Made

Carry the existing request from its producer instead of parsing user-controlled envelope delimiters or truncating the user's message. Run-local reuse uses request text plus native message identity while retaining all existing authorization/resource dimensions. The independent cross-turn cache stays query-based.

The timeout change is a deliberate budget policy: retain a terminal timeout result through agent_end, even while resource cleanup settles. Previously, cleanup allowed another recall for the same request. It does not fix or explain the first timeout and does not prevent a subsequent run from recalling.

Required corresponding Codex caller update, immediately before calling the shared harness helper (using existing local variables):

 return await resolveAgentHarnessBeforePromptBuildResult({
+  currentUserMessage: params.prompt,
+  currentUserMessageId: currentUserTurnIdempotencyKey,
   prompt: prependCurrentInboundContext(promptState.promptText, params.currentInboundContext),

That producer must capture the admitted request before continuity/context projection and preserve the native message identity across preparations. It must not derive either field from reconstructed prompt text. The published 2026.9.4 producer was inspected; current private source could not be inspected, so maintainers must verify and land its source change separately.

Evidence

  • vitest run extensions/active-memory src/agents/harness/prompt-compaction-hook-helpers.test.ts: 450 tests passed across 9 files (133.77 seconds, Node 24.18.0). Native hook relay tests cover both ordinary and authorized prompt dispatch.
  • Active Memory regressions cover false escalation from projected history, reuse across prompt rebuilds, independent identical messages, timeout retention, run-end release, and retry of rejected pre-start attempts.
  • Existing authority, memory-provider, channel, timeout-partial, cleanup, query, and cache tests are included in focused validation.
  • Stock control: the same five regression assertions fail against the unmodified production sources (ordinary/authorized relay, false escalation, duplicate recall, and timeout replacement).
  • Core and extension typechecks, focused type-aware lint, formatting, and source/extension import-boundary inventory passed.
  • Autoreview: no actionable P0–P2 findings in the supplied scope. The reviewer did not execute code.
  • Full build/full-repository suite and live current-main Codex integration are not claimed. No provider-latency or billed-token improvement is claimed.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: active-memory size: S labels Sep 13, 2026
@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: 🦪 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 Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 13, 2026, 12:53 PM ET / 16:53 UTC.

ClawSweeper review

What this changes

Adds current-request fields to prompt hooks, uses them for Active Memory recall and request reuse, and retains timeout results until the run ends.

Merge readiness

⛔ Blocked before merge - 6 items remain

This remains useful work: current main lacks the request-aware recall path, and the related merged fix does not cover it. The proposed integration is incomplete and lacks real behavior proof.

Priority: P2
Reviewed head: cbd7816e15533eb1b1d4f0b6ef2809e9dc58e701
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused implementation and regressions are useful, but missing producer wiring and real behavior evidence prevent merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The supplied evidence exercises hook relay and Active Memory with injected request fields and mocked execution, but does not show the real Codex producer preserving a request across projection rebuilds or the changed timeout lifecycle. 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 real behavior proof before merge: The supplied evidence exercises hook relay and Active Memory with injected request fields and mocked execution, but does not show the real Codex producer preserving a request across projection rebuilds or the changed timeout lifecycle. 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 10 items Pinned introduction scope: The verified merge-base-to-head patch adds the request contract and consumer but does not update the Codex producer. The verified test merge preserves that same scope.
Producer is present but does not supply the fields: The tracked Codex producer has params.prompt and currentUserTurnIdempotencyKey, but its shared-helper call passes only the projected prompt. This contradicts the body's claim that the producer source is unavailable in this repository.
Current main still needs the integration: Current main contains the same producer call without either current-request field; the hook helper and recall registry also retain their pre-PR behavior.
Findings 1 actionable finding [P2] Populate the new fields at the Codex producer
Security None None.

How this fits together

Active Memory enriches an agent’s prompt with relevant memories before the model responds. The harness supplies the request and projected history; Active Memory decides whether to recall and whether an existing result can be reused.

flowchart TD
  A[Admitted user request] --> B[Harness prompt preparation]
  C[Conversation history] --> B
  B --> D[Prompt hook]
  D --> E[Recall intent and request identity]
  E --> F[Reuse result or search memory]
  F --> G[Enriched agent prompt]
Loading

Decision needed

Question Recommendation
Should a timed-out Active Memory request remain terminal until agent_end, including on producers that do not supply the new request fields? Adopt one budget per request: Accept terminal timeout reuse alongside completed producer wiring and real recovery evidence across run boundaries.

Why: This deliberately replaces the cleanup-then-retry behavior in the prior merged implementation, trading same-run recovery for a bounded recall budget.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The supplied evidence exercises hook relay and Active Memory with injected request fields and mocked execution, but does not show the real Codex producer preserving a request across projection rebuilds or the changed timeout lifecycle. 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.
  • Populate the new fields at the Codex producer (P2) - The new consumer falls back to event.prompt whenever these fields are absent, but the tracked producer at extensions/codex/src/app-server/run-attempt-prompt.ts:252 still supplies only the projected prompt. Consequently, real Codex prompt rebuilds retain the reported false escalation and query-based duplicate recall behavior; only the timeout policy changes. That module already holds params.prompt and currentUserTurnIdempotencyKey. Wire them through the shared helper and cover the actual preparation path instead of leaving the new behavior reachable only through injected test events.
  • Resolve merge risk (P2) - Existing producers also lose the opportunity to recover recall after a transient timeout within the same run; this policy change needs explicit acceptance.
  • Resolve merge risk (P1) - The two optional plugin hook fields need an agreed producer contract and rollout so plugin authors can rely on their request-boundary semantics.
  • Complete next step (P2) - Complete producer wiring, confirm the hook contract and timeout policy, and supply after-fix real runtime evidence. Redact IP addresses, API keys, phone numbers, private endpoints, and other private details. Updating the PR body should trigger fresh review; if it does not, ask a maintainer to comment @clawsweeper re-review.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P2] Populate the new fields at the Codex producer — src/agents/harness/prompt-compaction-hook-helpers.ts:35-36
Agent review details

Security

None.

PR surface

Source +14, Tests +53, Docs +5. Total +72 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 34 20 +14
Tests 2 94 41 +53
Docs 1 6 1 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 134 62 +72

Review metrics

Metric Value Why it matters
Hook contract 2 optional fields; 0 production producers updated The new consumer path cannot activate through the inspected runtime callers.
Production versus tests Production net +14 lines; tests net +53 lines Production growth supports an explicit request contract, while the tests cover relay, reuse, and timeout behavior.

Merge-risk options

Maintainer options:

  1. Approve and prove the coordinated behavior (recommended)
    Confirm the optional hook contract and timeout policy, complete the producer, and demonstrate existing and updated producer behavior.
  2. Separate the timeout policy
    Preserve cleanup-then-retry behavior while completing the request-boundary fix.

Technical review

Best possible solution:

Carry the admitted request and stable identity through the existing producer, retain all authorization partitions, and adopt one-budget timeout semantics only with explicit owner acceptance and upgrade proof.

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

Yes, from source: Codex passes projected history as prompt, and Active Memory uses that input for intent and recall identity. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

The explicit producer-owned request is the right approach, but the producer must populate it; retaining terminal timeouts is a separate policy choice.

Full review comments:

  • [P2] Populate the new fields at the Codex producer — src/agents/harness/prompt-compaction-hook-helpers.ts:35-36
    The new consumer falls back to event.prompt whenever these fields are absent, but the tracked producer at extensions/codex/src/app-server/run-attempt-prompt.ts:252 still supplies only the projected prompt. Consequently, real Codex prompt rebuilds retain the reported false escalation and query-based duplicate recall behavior; only the timeout policy changes. That module already holds params.prompt and currentUserTurnIdempotencyKey. Wire them through the shared helper and cover the actual preparation path instead of leaving the new behavior reachable only through injected test events.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7bda807a35f9.

Labels

Label justifications:

  • P2: This addresses bounded Active Memory correctness and repeated recall cost without evidence of a core runtime outage.
  • merge-risk: 🚨 compatibility: The patch changes existing timeout recovery behavior and expands the public prompt hook contract.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The supplied evidence exercises hook relay and Active Memory with injected request fields and mocked execution, but does not show the real Codex producer preserving a request across projection rebuilds or the changed timeout lifecycle. 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:

  • Pinned introduction scope: The verified merge-base-to-head patch adds the request contract and consumer but does not update the Codex producer. The verified test merge preserves that same scope. (src/agents/harness/prompt-compaction-hook-helpers.ts:35, cbd7816e1553)
  • Producer is present but does not supply the fields: The tracked Codex producer has params.prompt and currentUserTurnIdempotencyKey, but its shared-helper call passes only the projected prompt. This contradicts the body's claim that the producer source is unavailable in this repository. (extensions/codex/src/app-server/run-attempt-prompt.ts:252, cbd7816e1553)
  • Current main still needs the integration: Current main contains the same producer call without either current-request field; the hook helper and recall registry also retain their pre-PR behavior. (extensions/codex/src/app-server/run-attempt-prompt.ts:252, 7bda807a35f9)
  • Latest release contract: The supplied latest release has prompt and messages in the prompt-build event, without either proposed current-request field. No released implementation of this contract was established. (src/plugins/hook-before-agent-start.types.ts:22, 3a9d69db306c)
  • Timeout policy changes independently of producer adoption: The registry now returns the existing promise even after timeout cleanup and retains it until agent_end. The changed regression explicitly verifies this behavior with no current-request fields, so existing producers are affected too. (extensions/active-memory/recall-state.ts:99, cbd7816e1553)
  • Existing authority partitions remain: Request identity replaces only the query component of run-local reuse. Agent/session, authority fingerprint, memory provider, projects, model, tools, and resource scope remain partitioning inputs; the hook still revalidates live tool authority after recall. (extensions/active-memory/recall.ts:459, cbd7816e1553)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Josh Avant: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Wire the tracked Codex producer and cover prompt preparation with changing projections and stable admitted identity.
  • Obtain explicit acceptance of terminal timeout reuse and the optional hook contract.
  • Add redacted after-fix runtime logs or terminal output showing request reuse, distinct requests, timeout reuse, and recall recovery in a subsequent run.

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.

@lordratner

Copy link
Copy Markdown
Contributor

I opened a focused contribution on top of this PR: sercada#1

It does two things in separate commits:

  1. Wires the tracked Codex producer to pass params.prompt and currentUserTurnIdempotencyKey, with a real preparation-path regression using a large projected envelope.
  2. Restores the existing post-timeout retry behavior so the unrelated “one recall budget per run” policy can be reviewed separately rather than bundled with the request-boundary fix.

One factual correction for this PR's description: the relevant Codex producer is present in this repository at extensions/codex/src/app-server/run-attempt-prompt.ts; it is not confined to a separate unavailable repository.

Validation on the contribution: 264 focused tests passed, core/extensions typechecks passed, and formatting passed. No runtime deployment was performed.

@sercada

sercada commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #149180, which landed on main on 2026-09-16 with this PR's request-boundary change and keeps this contribution in its history. Closing in favor of that merged fix. The remaining one-recall-budget-after-timeout behavior is being reviewed separately.

@sercada sercada closed this Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: active-memory merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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