Skip to content

fix(context-engine): honor assembled prompt authority in precheck#74247

Closed
100yenadmin wants to merge 1 commit intoopenclaw:mainfrom
electricsheephq:fix/context-engine-precheck-prompt-authority
Closed

fix(context-engine): honor assembled prompt authority in precheck#74247
100yenadmin wants to merge 1 commit intoopenclaw:mainfrom
electricsheephq:fix/context-engine-precheck-prompt-authority

Conversation

@100yenadmin
Copy link
Copy Markdown
Contributor

@100yenadmin 100yenadmin commented Apr 29, 2026

Summary

Fixes #74233.

Context-engine assembly is documented as returning the ordered messages ready for the model, but the embedded runner still let the preemptive overflow gate hard-fail on the larger pre-assembly transcript. That made LCM/windowing engines look broken even when their assembled prompt fit the model.

This PR makes assembled context the default prompt authority and keeps the older max-of-assembled-and-unwindowed behavior only for engines that explicitly opt in with promptAuthority: "preassembly_may_overflow".

Changes

  • Adds optional AssembleResult.promptAuthority?: "assembled" | "preassembly_may_overflow", defaulting to "assembled".
  • Stops passing pre-assembly history into the hard precheck unless the context engine opts into raw-history overflow authority.
  • Leaves the lower-level precheck helper capable of honoring explicit unwindowed messages.
  • Adds attempt-level regressions for the LCM failure shape: huge raw history plus a small assembled prompt now proceeds, while explicit preassembly authority still fails early.

Validation

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents.config.ts src/agents/pi-embedded-runner/run/preemptive-compaction.test.ts src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-engine.test.ts
  • pnpm build:plugin-sdk:strict-smoke

Notes

This is the production-side fix for the context blow-up path. LCM-side follow-ups add cache-policy hardening and assembly provenance so future incidents can be diagnosed from host-visible metadata instead of logs only.

Refs Martian-Engineering/lossless-claw#534.

Copilot AI review requested due to automatic review settings April 29, 2026 09:15
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S r: too-many-prs Auto-close: author has more than twenty active PRs. labels Apr 29, 2026
@openclaw-barnacle
Copy link
Copy Markdown

Closing this PR because the author has more than 10 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR fixes a precheck false-positive where the embedded runner was checking the raw pre-assembly transcript against the context budget, causing LCM/windowing engines to appear broken even when their assembled prompt fit the model. The fix makes assembled context the default authority for overflow prechecks and gates the old raw-history behaviour behind an explicit promptAuthority: "preassembly_may_overflow" opt-in on AssembleResult.

Confidence Score: 5/5

This PR is safe to merge; the change is narrowly scoped, additive to the public type, and fully covered by new regression tests.

No P0/P1 issues found. The fix correctly initialises contextEnginePromptAuthority to assembled, updates it only on a successful assemble call, and the fallback path (assemble throws) stays safe because the default keeps the assembled-messages path. Both new test cases demonstrate the exact fixed and opt-in shapes.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(context-engine): honor assembled pro..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a mismatch between context-engine “assembled” prompts and the embedded runner’s overflow precheck logic: the precheck now treats the assembled messages as the default authoritative prompt for overflow detection, preventing false hard-failures when a context engine windows/compacts history but the raw pre-assembly transcript is large.

Changes:

  • Added AssembleResult.promptAuthority?: "assembled" | "preassembly_may_overflow" (defaulting effectively to "assembled").
  • Updated the embedded attempt precheck to only consider pre-assembly (unwindowed) messages when the context engine explicitly opts into that authority.
  • Added regression tests covering both the default (“assembled proceeds”) and opt-in (“preassembly overflow fails early”) behaviors.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/context-engine/types.ts Extends AssembleResult with an optional promptAuthority contract for precheck behavior.
src/agents/pi-embedded-runner/run/attempt.ts Makes assembled messages the default prompt authority for overflow prechecks; gates use of unwindowed messages behind the opt-in authority.
src/agents/pi-embedded-runner/run/preemptive-compaction.test.ts Updates test description to reflect the “explicitly provided unwindowed messages” behavior.
src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-engine.test.ts Adds attempt-level regressions validating default assembled authority and explicit preassembly overflow authority.

@100yenadmin
Copy link
Copy Markdown
Contributor Author

Branch update note: the fork branch 100yenadmin/openclaw-1:fix/context-engine-precheck-prompt-authority has been force-pushed to d26feb5b999d66d866134ad381ead8ce5c954597 to fix the CI lint failure from redundant test template literals. Fresh local validation on that SHA: pnpm lint --threads=8, node scripts/run-vitest.mjs run --config test/vitest/vitest.agents.config.ts src/agents/pi-embedded-runner/run/preemptive-compaction.test.ts src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-engine.test.ts, and pnpm build:plugin-sdk:strict-smoke all pass. GitHub currently refuses reopening this PR because 100yenadmin is at the active-PR cap; this should be reopened once one OpenClaw PR slot is freed.

@openclaw-barnacle
Copy link
Copy Markdown

Closing this PR because the author has more than 10 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit.

@openclaw-barnacle openclaw-barnacle Bot removed the r: too-many-prs Auto-close: author has more than twenty active PRs. label Apr 29, 2026
@100yenadmin
Copy link
Copy Markdown
Contributor Author

Refiled from the cleaned fork branch as #74255. Use #74255 for review/merge; #74247 was auto-closed by the active-PR cap and kept stale head metadata.

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

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context-engine assembled prompts are bypassed by overflow precheck using pre-assembly history

2 participants