Skip to content

feat(ai): record bounded prompt presence checks for frozen injection expectations - #194566

Closed
csuzngjh wants to merge 1302 commits into
openclaw:mainfrom
csuzngjh:ai/prompt-presence-check
Closed

csuzngjh wants to merge 1302 commits into
openclaw:mainfrom
csuzngjh:ai/prompt-presence-check

Conversation

@csuzngjh

@csuzngjh csuzngjh commented Nov 7, 2026

Copy link
Copy Markdown

Prompt presence checks for frozen injection expectations

Implements the approved PRI-1119 minimal design v1.2 (Tier B): bounded, fact-only presence checks that verify whether a frozen injection expectation's full body text appears inside the pre-submission request object, on both the openai-responses and openai-completions paths.

What this does

  • Pure bounded checker (packages/ai/src/transports/prompt-presence-check.ts): three mutually exclusive outcomes — full_hit / checked_missing / unknown with explicit reasons (assembly_truncated, body_over_limit, expectations_over_limit, scan_region_over_limit, cumulative_scan_over_limit, unparseable_content, check_failed). Caps: per-body 64 KiB, per-message region 8 MiB, expectation count 64, message count 512, and a cumulative UTF-8 scan cap (32 MiB) covering legal AND wrong-role regions — exceeding it never outputs checked_missing (owner condition 1).
  • responses path: the existing egress observer frame computes presenceCheck (with per-attempt index) when the request carries a frozen expectation set (options-keyed carrier). The provider.prompt.observed event gains presenceCheck (+ requestIndex stamped by the runner wrapper).
  • completions path (previously zero observation): a checkpoint after onPayload replacement and before encodeBody emits the same event channel with egress: "completions", attemptIndex: 0.
  • runner: per-run requestCount on the run-scoped prompt state (incremented once per attempt assembly), expectation set frozen by the prompt-build phase after the size guard, carrier bound per request, requestIndex stamped on emitted events.
  • plugins: optional structured injectedExpectations field on the before_prompt_build result (validated passthrough; merged by concatenation across plugins).

No request mutation. No body persistence. Requests without frozen expectations are unaffected: no carrier → no presenceCheck field → no measurable added cost.

Owner acceptance conditions — where implemented

  1. Cumulative scan cap (32 MiB default) over legal AND wrong-role regions; exceeding yields unknown:cumulative_scan_over_limit, never checked_missing.
  2. Expectations carry bodyComplete; truncated-assembly fragments force unknown:assembly_truncated and can never yield full_hit. The injecting plugin freezes expectations after its size guard and marks completeness by containment.
  3. Event identity reuses existing fields: envelope runId, wrapper-stamped requestIndex (run-scoped ordinal, incremented per attempt assembly), egress-closure attemptIndex + payloadVariant. Tests cover same-run multi-request, concurrency isolation, and retry attempt indexing.
  4. Event size measured in UTF-8 bytes (table below).

Measured on the implementing machine (script: packages/ai/src/transports/prompt-presence-measure.mts)

fixture runs median p95 event bytes (UTF-8)
representative: 18 expectations × ~2.2 KiB bodies, 58k-char system region 30 0.111 ms 0.192 ms 2,994
representative: 1 expectation, same region 30 0.008 ms 0.010 ms 249
boundary: 64 expectations × 64 KiB bodies (under limits) 10 128.620 ms 129.286 ms 10,702

Tests

  • packages/ai/src/transports/prompt-presence-check.test.ts — 20 fixtures (containment, roles, parts, no-concatenation, prefix-not-hit, limits, cumulative cap, truncated-assembly rule, exception fail-open, completions roles).
  • src/agents/embedded-agent-runner/provider-prompt-state.presence.test.ts — 6 tests (carrier binding + event stamping, same-run multi-request ordinals, concurrency isolation, absent-expectation untouched events, truncated-assembly rule through the real transport chain, retry attempt indexing).
  • Regressions green: existing observer/transport suites 36/36; runner-side scoped tsc clean for touched files.

Trust boundary

The check runs inside the host process (host-recorded, not third-party). It observes the pre-submission request object — the exact object encodeBody serializes into the wire body via body-override. It does not prove network-peer bytes or model-context inclusion.

roboclaw-bot and others added 30 commits November 1, 2026 03:11
Record the fully repaired 2026.10.10 candidate with the maintainer identity registered for GitHub signature verification.

Co-authored-by: RomneyDa <[email protected]>
FRV repo UI shards run WebKit-owned suites, so provision WebKit alongside the cached Chromium install.

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit a57e5be)
Record the repaired 2026.10.10 candidate after provisioning WebKit for every Control UI E2E shard.

Co-authored-by: RomneyDa <[email protected]>
Use the canonical record guard, remove lint violations in release-owned tests and SDK packing support, and update exact file-size ratchets for the frozen candidate.\n\nCo-authored-by: RomneyDa <[email protected]>
Restores the native Codex recovery scenarios by removing a retired synthetic Gateway setting so their existing lifecycle assertions run.

(cherry picked from commit eb5fe78)
Co-authored-by: RomneyDa <[email protected]>
The complete release UI plan now contains thirteen Control UI shards plus the browser row, so the dispatch manifest contains fourteen entries.\n\nCo-authored-by: RomneyDa <[email protected]>
Repeated provider requests are observational after #177557; update the stale integration expectations to preserve provider ownership while still proving queued work drains after the owner stops.\n\nCo-authored-by: RomneyDa <[email protected]>
)

* fix(test): wait for OpenAI smoke gateway readiness

Reuse the bounded readiness owner before the chat-tools POST so a healthy RPC cannot race required agent database admission. Preserve the final authenticated health check and the single strict client request.

Co-authored-by: vincentkoc <[email protected]>

* fix(e2e): OpenAI smoke fails while agent databases are starting

Worked on by:
- @vincentkoc

Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: 09374d76-3dfc-4525-a010-598402a34e2e

---------

Co-authored-by: vincentkoc <[email protected]>
(cherry picked from commit 74a970d)
Co-authored-by: RomneyDa <[email protected]>
…ove (#174422)

Detect Codex progress-finality in both historical source locations so the release follow-through prompt uses explicit final=false for current candidates. Preserve frozen-candidate behavior and strict reply, work-order, and artifact assertions.

Co-authored-by: vincentkoc <[email protected]>
(cherry picked from commit 1ebcfbf)
Co-authored-by: RomneyDa <[email protected]>
Keep account readiness in startup until Matrix startup maintenance and crypto ownership initialization have settled, preventing hard-restart consumers from interrupting final state handoff.

Co-authored-by: RomneyDa <[email protected]>
Record the fully repaired candidate after pinning the qualified Kova release evaluator.

Co-authored-by: RomneyDa <[email protected]>
Restore multi-version SDK registry typing and republish isolated runtime config before trajectory-backed live-test reads.

Co-authored-by: RomneyDa <[email protected]>
Record the candidate after repairing the exact full-validation SDK and runtime-config ownership failures.

Co-authored-by: RomneyDa <[email protected]>
Record the candidate after repairing exact qualification-artifact validation for GitHub step clock skew.

Co-authored-by: RomneyDa <[email protected]>
Record the candidate with the registered release identity after repairing GitHub step clock skew handling.

Co-authored-by: RomneyDa <[email protected]>
Record the candidate with the registered release identity after repairing GitHub step clock skew handling.

Co-authored-by: RomneyDa <[email protected]>
* fix(release): tolerate DST-skewed artifact timestamps

Co-authored-by: RomneyDa <[email protected]>

* fix(release): tolerate DST-skewed artifact timestamps

OpenClaw-Publication: 14fcd935-d37a-4e14-bc3d-9b915c5b7d32

* test(release): preserve upload-step timestamp fixtures

Co-authored-by: RomneyDa <[email protected]>

---------

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 091884c)
Record the candidate with the registered release identity after backporting the exact upload-step fallback for GitHub DST-skewed job clocks.

Co-authored-by: RomneyDa <[email protected]>
Record the candidate with the registered release identity after backporting the exact upload-step fallback for GitHub DST-skewed job clocks.

Co-authored-by: RomneyDa <[email protected]>
…cation-bound ordinals, overflow facts)

Review-round fixes on the prompt presence forensics:

- Text-part contracts are per API: responses reads input_text parts, chat
  completions reads standard {type:"text"} parts. Cross-API part types no
  longer contribute text; an unreadable legal-role message degrades the whole
  check to unknown (unparseable_content) instead of a silent skip, because the
  target cannot be ruled out.
- Empty/whitespace bodies are invalid (unknown:invalid_body) and can never
  produce a vacuous full_hit via includes("").
- The logical request ordinal now binds to the streamFn invocation boundary:
  the outermost wrapper layer assigns it via an options-keyed request token
  (inner layers propagate), so wrapper stacking counts once per invocation,
  retries keep one requestIndex with incrementing attemptIndex, and a second
  model request after tools advances the ordinal. The assembly-time counter is
  gone; tests drive the real wrapper without touching production counters.
- Producer-side collection overflow is preserved end to end: the hook result,
  merge, whitelist, carrier and event carry injectedExpectationsOverflow, and
  collection stops materializing bodies at the cap (escape/normalize work only
  for kept entries) instead of bounded-after-the-fact.

New capture tests drive the real production transports (openai-responses and
openai-completions) against a fake transport-host fetch and assert the actual
submitted bytes: injection present (full_hit), onPayload replacement reflected
in both bytes and event (checked_missing), fail-open degraded checks still
submit. Existing suites updated for the requestIndex event field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: android App: android app: ios App: ios app: linux app: macos App: macos app: web-ui App: web-ui channel: a2a channel: buzz channel: discord Channel integration: discord channel: feishu Channel integration: feishu channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: irc channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: qa-channel Channel integration: qa-channel channel: raft Channel integration: Raft channel: reef Channel integration: reef channel: signal Channel integration: signal channel: slack Channel integration: slack channel: sms Channel integration: sms channel: synology-chat channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: twitch Channel integration: twitch channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: x channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: acpx extensions: active-memory extensions: admin-http-rpc extensions: advisor extensions: arcee extensions: baseten Extension: baseten extensions: byteplus extensions: cerebras extensions: clawrouter Extension: clawrouter extensions: clickclack extensions: copilot-proxy Extension: copilot-proxy extensions: crabbox extensions: deepseek extensions: diagnostics-otel Extension: diagnostics-otel extensions: diagnostics-prometheus extensions: document-extract extensions: duckduckgo extensions: llama-cpp extensions: llm-task Extension: llm-task extensions: lobster Extension: lobster extensions: memory-core Extension: memory-core extensions: memory-lancedb Extension: memory-lancedb extensions: memory-wiki extensions: oc-path extensions: onepassword 1Password plugin extensions: policy extensions: qa-lab extensions: tokenjuice Changes to the bundled tokenjuice extension extensions: vault Extension: vault extensions: web-readability gateway Gateway runtime plugin: azure-speech Azure Speech plugin plugin: beam Beam session sharing plugin plugin: bonjour Plugin integration: bonjour plugin: code-mode-quickjs plugin: cua-computer plugin: facetime FaceTime plugin plugin: file-transfer plugin: geolocation Geolocation plugin (IP to coarse city) plugin: google-meet plugin: imap plugin: linux-node plugin: logbook Logbook automatic work journal plugin plugin: mcp-events plugin: mcp-relay plugin: migrate-claude plugin: migrate-hermes plugin: muse plugin: mxc plugin: onnx plugin: pixverse plugin: session-share plugin: slack-huddles plugin: team-reports plugin: teams-meetings Teams Meetings plugin plugin: typesafe plugin: visitor-access plugin: workboard plugin: zoom Zoom plugin scripts Repository scripts security Security documentation triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.