Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 10, 2026, 10:32 PM ET / September 11, 2026, 02:32 UTC (Revision 3). ClawSweeper reviewWhat this changesPreserves resolved model identity, native context window, and token budget through durable context-engine commits, including recovery and retries. Merge readiness⛔ Blocked before merge - 3 items remain This remains a useful fix: current main and the latest release still omit model metadata from durable commits. No actionable patch defect was found, and the real-engine recovery evidence is sufficient. The previously identified persisted-contract approval remains unresolved. Priority: P2 Review scores
Verification
How this fits togetherContext engines prepare and compact an agent’s conversation history. The durable turn outbox stores accepted turns until the selected engine commits them, including after a restart or temporary failure. flowchart LR
A[Resolved model facts] --> B[Accepted agent turn]
B --> C[Durable turn outbox]
C --> D[Recovery or retry]
D --> E[Context engine commit]
E --> F[Budget-aware post-turn processing]
Decision needed
Why: The implementation and compatibility evidence support the change, but repository policy reserves acceptance of restart-visible persistent semantics for maintainers. Before merge
Agent review detailsSecurityNone. PR surfaceSource +42, Tests +50. Total +92 across 13 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Adopt the existing outbox-based repair with an accepted contract for the four optional model facts, legacy-row fallback, and older-reader behavior. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main drops resolved model facts before durable commitTurn, including recovery. No runtime reproduction was executed during this read-only review. Is this the best way to solve the issue? Yes. Carrying resolved facts through the existing durable payload fixes the owning handoff without a parallel mechanism; the latest commit correctly separates the native window from the effective budget. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 89f364512258. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Real-engine proof is now included in the PR body. I exercised the OpenClaw durable outbox with the actual local LCM engine after reconstructing it: an older row without runtime metadata drained using the documented 128k fallback, while a new row carried 180k budget, 200k model window, provider, and model ID; both drained with no pending rows. The remaining decision is intentionally for maintainers: accept the optional restart-visible JSON payload extension, with old rows retaining fallback behavior. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Yigtwxx
left a comment
There was a problem hiding this comment.
I measured this at head b74687746d1. The plumbing is clean and the recovery/retry coverage is genuinely good, but I think the value being carried is the wrong one, and the three producers do not agree on what they are carrying.
1. The persisted tokenBudget is the raw override, not the resolved budget
attempt-finalize.ts:239 and selection.ts:599 write attempt.contextTokenBudget / internalParams.contextTokenBudget straight through. That field is optional (embedded-agent-runner/run/types.ts:166, agent-settings.ts:36) and is only set when an explicit budget override is configured. The number the turn actually ran under is resolved separately:
// src/agents/embedded-agent-runner/run/attempt-history-prepare.ts:186-194
const contextTokenBudget = Math.max(1, Math.floor(
attempt.contextTokenBudget ??
attempt.model.contextWindow ??
attempt.model.maxTokens ??
DEFAULT_CONTEXT_TOKENS,
));So in the default configuration - no explicit override - the runtime resolves a budget from the model window, but the durable row records nothing.
Measured on your own fixture. attempt-phase-lifecycle.test.ts passes both model: { contextWindow: 200_000 } and contextTokenBudget: 180_000; I removed only the second line, leaving everything else identical, and reran the suite:
node node_modules/vitest/vitest.mjs run \
--config test/vitest/vitest.agents-embedded-agent-run.config.ts \
src/agents/embedded-agent-runner/run/attempt-phase-lifecycle.test.ts
| Fixture | recorded runtimeContext |
|---|---|
| as in the PR (12/12 pass) | { provider: "test", modelId: "model", modelContextWindow: 200000, tokenBudget: 180000 } |
| explicit budget removed | { provider: "test", modelId: "model", modelContextWindow: 200000, tokenBudget: undefined } |
The window survives, the budget does not. For that same attempt the resolved budget is 200,000 by the expression above, so the row records undefined where the runtime resolved a real number, and a consumer with a documented 128,000 fallback still falls back.
That is the case in the problem statement. "A context engine used its 128,000-token fallback during post-turn processing despite a 1,000,000-token inference window" describes a model with a large window; unless that deployment also sets an explicit contextTokenBudget, this change records tokenBudget: undefined for it and the fallback still wins. Every test and the terminal evidence in the body set contextTokenBudget explicitly (180,000), so the default configuration is never exercised.
There is also a contract mismatch on the field itself:
// src/context-engine/types.ts:317-318
/** Runtime-resolved context window budget for the active model call. */
tokenBudget?: number;The slot is documented as runtime-resolved; the PR writes the unresolved override into it. Passing the same expression attempt-history-prepare.ts computes (or the already-resolved value, if it is reachable at finalize time) would make the field mean what its doc comment says, and would make the fix work without an override.
2. The three producers are mirror images of each other
| Field | cli-run-transcript.ts:375-380 |
attempt-finalize.ts:235-240 |
selection.ts:595-600 |
|---|---|---|---|
provider |
runParams.modelProvider ?? runParams.provider |
attempt.provider |
internalParams.provider |
modelContextWindow |
runParams.modelContextWindow |
attempt.model.contextWindow |
internalParams.model.contextWindow |
tokenBudget |
context.contextWindowInfo?.tokens |
attempt.contextTokenBudget |
internalParams.contextTokenBudget |
The CLI row is the inverse of the embedded row, not a variant of it:
- CLI
tokenBudgetiscontextWindowInfo.tokens, which is exactly what the CLI runner already uses as its own budget (cli-runner/prepare.ts:1665,contextTokenBudget: contextWindowInfo.tokens) - i.e. the resolved value, essentially always defined. - CLI
modelContextWindowisrunParams.modelContextWindow, which is optional (cli-runner/types.ts:162) and is a caller-supplied raw value, notcontextWindowInfo.tokens(prepare.ts:1601shows the resolved window flowing into a different field).
So for the same model an engine can see { modelContextWindow: undefined, tokenBudget: 200000 } from the CLI route and { modelContextWindow: 200000, tokenBudget: undefined } from the embedded route. provider diverges too: only the CLI producer prefers modelProvider. Since the whole point is that engines can trust these four facts, it would help to resolve them once in a shared helper and have all three producers call it, rather than three hand-written literals.
The body says "Native, plugin-harness, and CLI producers provide these facts." Measured, in the default configuration the native and harness producers provide three of the four.
3. runtimeContext on commitTurn is a shared slot, and this makes it partial
commitTurn's parameter is typed ContextEngineRuntimeContext (src/context-engine/types.ts:451), the same type assemble, afterTurn and the maintenance hooks take. On the non-durable path that slot is filled by buildAfterTurnRuntimeContextFromUsage (attempt-finalize.ts:244), which produces the full object from buildAfterTurnRuntimeContext (attempt-prompt-helpers.ts:508): cwd, sessionTarget, promptCache, transcriptStorage, rewriteTranscriptEntries, llm, and more.
Before this PR, commitTurn simply received no runtimeContext from the durable path, so an engine could branch on undefined. After it, runtimeContext is defined but carries four keys, and runtimeContext !== undefined no longer implies the fields an engine reads elsewhere are present. An engine sharing one readRuntimeContext(ctx) helper across afterTurn and commitTurn - a natural thing to do given the identical type - now silently gets undefined for everything except these four.
Related: ContextEngineRuntimeContext is Record<string, unknown> & { ... } (types.ts:309), and of the four fields only tokenBudget is declared. provider, modelId and modelContextWindow ride in on the index signature, so a plugin engine written against the public type reads them as unknown and has to cast. If they are meant to be part of the contract, declaring them next to tokenBudget would make that explicit and would let the type system catch producer drift like point 2.
Smaller note
recoverContextEngineTurnOutbox reads payload.runtimeContext back out of the stored row. The outbox tests cover this, and I did not find a schema that would strip unknown keys, but it is worth confirming that a row written by an older build (no runtimeContext) and one written by a newer build round-trip through the same parse without the field being dropped on the way in - the retry assertion currently checks the field only after Object.assigning it onto the payload in the test itself, not after a real write/read cycle.
None of this touches the recovery and retry work, which looks right to me.
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Acting on Josh Lehman’s explicit instruction to land this PR, I’m recording his maintainer acceptance of the additive optional durable metadata contract:
That downgrade behavior is accepted. The payload remains bounded to four optional primitive facts and does not require a SQLite schema or protocol version change. |
|
Maintainer review complete for exact head The original contributor head had one actionable P2: embedded producers could persist the already-capped effective window as the native model window. Commit Evidence:
ClawSweeper’s latest exact-head review reports sufficient real-engine proof and no correctness or security finding. Its remaining checklist items are the same persisted-contract owner decision, now explicitly resolved in the maintainer acceptance. |
jalehman
left a comment
There was a problem hiding this comment.
Approved at f8cc0ea9d7c18d9d2b1e6dd63b5182be1b78223d after fresh source review, clean P0–P2 autoreview, focused and changed-file gates, exact-head required CI, and repository-native prepare. The persisted optional metadata and documented downgrade behavior have explicit maintainer acceptance.
|
Merged via squash.
|
…142871) * fix: retain model budgets for durable context-engine turns * fix(agents): preserve native context window metadata --------- Co-authored-by: Marvinthebored <[email protected]> Co-authored-by: jalehman <[email protected]>
Closes #142870
What Problem This Solves
Fixes an issue where users of durable context engines could get premature compaction because accepted turns lost the model's resolved context window and token budget. For example, a context engine used its 128,000-token fallback during post-turn processing despite a 1,000,000-token inference window.
Why This Change Was Made
Carry the resolved provider, model ID, context window, and token budget through the existing durable turn payload into
commitTurn.runtimeContext. Native, plugin-harness, and CLI producers provide these facts. Accepted-turn recovery and retries preserve them.Only these four primitive model facts are persisted, not live capabilities, credentials, or the full runtime configuration. Existing rows without this optional metadata keep their current behavior. No database schema migration is needed.
User Impact
Context engines that accept
runtimeContextcan use the turn's actual model budget during post-turn processing, including after recovery. This prevents the host from forcing fallback budgets merely by dropping those facts.Evidence
Before the fix, two existing outbox tests failed new assertions because recovered and retried commits lacked
runtimeContext. With the fix, all 8 outbox tests passed.Extended existing native-producer and accepted-finalization fixtures to assert a 200,000-token model window and a distinct 180,000-token budget. The lifecycle and finalization suites passed all 12 and 13 tests respectively.
Existing CLI-transcript and harness-selection suites also passed. The five selected suites passed all 190 tests on the upstream-based PR branch.
Real-engine proof used the OpenClaw durable outbox with the actual local
LcmContextEngine. After reconstructing the engine before draining, an older row without metadata used the documentedtokenBudget=128000fallback, while a new row carriedtokenBudget=180000,modelContextWindow=200000,provider=anthropic, andmodel=anthropic/claude-sonnet-4-6; both rows drained successfully. The redacted terminal output was:Core source and all core-test typecheck shards passed on the combined development patch, as did targeted lint and formatting. The broader changed-files gate stopped on an unrelated compatibility-expiry record, also reproduced on the unchanged checkout.
Independent adversarial review found no actionable correctness or security issues.
AI-assisted implementation and independent review. Sanitized work log; private session transcripts are not published. The optional persisted payload contract remains explicitly submitted for maintainer acceptance.