Skip to content

feat(mantis): programmable proof boundaries with recipe library - #127782

Merged
obviyus merged 4 commits into
mainfrom
t3code/improve-mantis-proof-testing
Aug 22, 2026
Merged

obviyus merged 4 commits into
mainfrom
t3code/improve-mantis-proof-testing

Conversation

@obviyus

@obviyus obviyus commented Aug 22, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Mantis (the automated Telegram Desktop PR proof agent) currently blocks on three recurring scenario classes because its harness boundaries are static:

  1. No way to inject Bot API failures (429/5xx/connection drops), so retry/error-path PRs cannot be exercised.
  2. One global mock-provider response makes multi-turn scenarios racy — concurrent turns consume the wrong response.
  3. PRs whose real difference is outbound Bot API payload bytes (e.g. callback_data) produce pixel-identical lanes, forcing block even when the change is provable.

All three blocked runs in the recent evidence archive fail at exactly these seams.

Why This Change Was Made

Instead of letting the proof agent author harness code (which would break the trusted evidence chain), the boundaries become data-programmable: the agent supplies declarative JSON (fault rules, ordered provider response scripts, observe-until predicates) through the existing sudo-wrapped lane CLI, and trusted root/mantis-sut-owned code interprets it and records bounded facts into the lane facts file. The prompt gains a recipes library (.github/codex/prompts/mantis-recipes/) mirroring the Telegram E2E userbot skill's feature-recipe pattern, so working scenarios accumulate; the agent can propose new ones via a quarantined recipe-suggestion.md artifact.

The trust boundary is unchanged: the unprivileged codex user gains no new writable paths, controls land in mantis-sut-owned mode-0700 directories, workflow validation of lane facts is strengthened (Bot API request facts are now required), and no sudoers changes. The candidate SUT container cannot see the proxy's record sink: an inaccessible tmpfs shadows proxy-control/ inside the runtime mount, so the lane under test cannot rewrite its own recorded Bot API evidence, and the prompt treats SUT-co-located provider request logs as diagnostic rather than standalone comparison evidence. Follow-up worth naming: moving the mock OpenAI server out of the SUT container (its own container like the Bot API proxy) would make provider request facts trustworthy against candidate code too.

User Impact

Maintainers get Mantis proofs for whole PR classes that previously ended in block: Bot API failure/retry behavior, ordered multi-turn provider scenarios, and payload-level differences with pixel-identical UI. Runs also finish faster: observe --until-* predicates replace fixed 60-second windows (~14 minutes of dead waiting in one archived run), and agent effort rises to high (verified against the Codex runtime source: codex-rs/protocol/src/openai_models.rs:62, sdk/typescript/src/exec.ts:129).

New primitives (all declarative, executed by trusted code):

  • botapi-fail <method> [--times N] [--status CODE | --drop] / botapi-clear / botapi-requests — injected faults plus bounded outbound Bot API payload/status recording (32 KiB body cap, token-redacted), always published in lane facts.
  • mock --script <file> <sha256> — ordered per-request provider responses (text, raw events file, or injected failure), with default/last-entry exhaustion semantics.
  • observe --until-events/--until-text/--until-provider-requests — AND-semantics early return, 60 s cap retained.
  • Prompt doctrine update: trusted payload/status/ordering facts can prove a lane difference even when pixels are identical.

Evidence

  • node scripts/run-vitest.mjs test/scripts/telegram-bot-api-proxy.test.ts test/scripts/e2e-mock-config-limits.test.ts test/scripts/telegram-mantis-lane.test.ts test/scripts/mantis-build-telegram-desktop-proof-evidence.test.ts test/scripts/mantis-telegram-desktop-proof-workflow.test.ts — 5 files, 79/79 passed.
  • node scripts/check-changed.mjs -- <all touched files> — formatting, lint, Node erasability, and type checks passed.
  • git diff --check clean.
  • Workflow jq validation is additive-strict: .botApiRequests array is now required in lane facts (empty array required for infra-error lanes); recipe-suggestion quarantine copy enforces regular-file/no-link/size bounds with root installation.
  • Not run: a live GitHub Mantis workflow run (requires a PR to target); the changed proxy/mock/lane/evidence paths are covered by the focused tests above, and the first Mantis run on a subsequent PR exercises the workflow end to end.

@clawsweeper

clawsweeper Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@obviyus
obviyus marked this pull request as ready for review August 22, 2026 04:55
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: XL maintainer Maintainer-authored PR labels Aug 22, 2026
--until-text and --until-events evaluated the whole lane timeline, so a
reused marker or any prior event satisfied the early return before the
observed action produced evidence. Event predicates now count only
events after the requested cursor; provider-request counts stay
cumulative because the provider log has no per-observe cursor.
Regression: nonzero-cursor observe with stale matching history times out
instead of returning early.
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 22, 2026
@clawsweeper

clawsweeper Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 22, 2026, 1:20 AM ET / 05:20 UTC.

ClawSweeper review

What this changes

This PR adds declarative Mantis scenario controls for provider scripts, Telegram Bot API faults and request facts, early observation, and reusable proof recipes.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep this PR open: its new callback-payload recipe cannot target the bot message or inspect the requests that carry callback bytes, so it does not deliver the advertised proof path.

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

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation has useful focused coverage, but one advertised recipe is incorrect and the privileged workflow has not been exercised end to end.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable to this member-authored PR, but its body confirms that no real Mantis workflow run has yet exercised the new sudo, Docker-mount, lane-fact, and artifact path.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to this member-authored PR, but its body confirms that no real Mantis workflow run has yet exercised the new sudo, Docker-mount, lane-fact, and artifact path.
Evidence reviewed 6 items Callback recipe has no bot message identifier: The recipe uses $bot_message_id without assigning it, while the lane's turn result exposes revealedMessageId for the sent QA-user message, not the SUT's button message.
Recipe omits callback-bearing requests: The recipe inspects answerCallbackQuery and editMessageText, but Telegram callback bytes are carried in inline reply markup such as sendMessage or editMessageReplyMarkup; answerCallbackQuery consumes a callback id and optional text.
Candidate record-sink isolation is source-backed: The proxy gets the writable control mount separately, while the candidate container shadows that directory with a mode-0000 tmpfs after mounting its runtime; lane facts read the host-side record file.
Findings 1 actionable finding [P2] Capture the bot ID and callback-bearing Bot API request
Security None None.

Live Verification

Command: node --import tsx scripts/e2e/telegram-mantis-lane.ts --help

Result: PASS (completed)

node --import tsx scripts/e2e/telegram-mantis-lane.ts --help
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127782-uWFAjF/target$ node --import tsx scripts/e2e/telegram-mantis-lane.ts --help
node --import tsx scripts/e2e/telegram-mantis-lane.ts --help
Usage: openclaw-telegram-mantis-lane ‹command› --lane ‹baseline|candidate› ...
Commands: abort, block, botapi-clear, botapi-fail, botapi-requests, delete, desktop, finish, mock, observe, press, requests, screenshot, send, start, turn, view
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127782-uWFAjF/target$ node --import tsx scripts/e2e/telegram-mantis-lane.ts --help
Usage: openclaw-telegram-mantis-lane ‹command› --lane ‹baseline|candidate› ...
Commands: abort, block, botapi-clear, botapi-fail, botapi-requests, delete, desktop, finish, mock, observe, press, requests, screenshot, send, start, turn, view
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127782-uWFAjF/target$










































Assertions:

  • PASS expect_output: Usage: openclaw-telegram-mantis-lane

How this fits together

Mantis runs isolated Telegram Desktop comparison lanes for a baseline and a candidate revision. Its lane helper configures the test environment, a separate proxy records Bot API calls, and the workflow publishes validated evidence artifacts.

flowchart LR
  Agent[Unprivileged proof agent] --> Controls[Declarative scenario controls]
  Controls --> Lane[Trusted lane helper]
  Lane --> SUT[Isolated baseline or candidate]
  SUT --> Proxy[Separate Bot API proxy]
  Proxy --> Facts[Recorded lane facts]
  Lane --> Facts
  Facts --> Validation[Workflow validation]
  Validation --> Evidence[PR proof artifacts]
Loading

Decision needed

Question Recommendation
Should this privileged proof-boundary expansion land only after an end-to-end Mantis run proves proxy-record isolation and the Codex high-effort contract is checked directly? Require boundary proof before merge: Fix the recipe, run a fault-injection Mantis scenario, and show that candidate-side writes cannot affect the trusted proxy record.

Why: Static source supports the intended isolation, but the final Docker mount behavior and the dependency-backed effort setting cannot be established from this read-only checkout.

Before merge

  • Capture the bot ID and callback-bearing Bot API request (P2) - This recipe never assigns $bot_message_id; turn returns sent.revealedMessageId, which is the QA user's message, not the bot button. It also filters only answerCallbackQuery and editMessageText, neither of which is the general carrier for the original callback_data. Capture the SUT message ID from the observed event and compare sendMessage and/or editMessageReplyMarkup request bodies, with focused coverage for that recipe path.
  • Resolve merge risk (P1) - The privileged proof boundary has no end-to-end Docker run proving that a candidate cannot alter proxy records before trusted publication.
  • Resolve merge risk (P1) - The changed Codex effort setting lacks the required direct upstream runtime-contract verification.
  • Complete next step (P2) - The callback recipe defect has a narrow mechanical repair, while the remaining hosted-boundary proof stays a maintainer merge gate.

Findings

  • [P2] Capture the bot ID and callback-bearing Bot API request — .github/codex/prompts/mantis-recipes/callback-data-payload-proof.md:9-19
Agent review details

Security

None.

PR surface

Tests +539, Docs +102, Config +12, Other +810. Total +1463 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 5 546 7 +539
Docs 5 106 4 +102
Config 1 14 2 +12
Generated 0 0 0 0
Other 6 850 40 +810
Total 17 1516 53 +1463

Review metrics

Metric Value Why it matters
Production versus test LOC production/tooling +970/-46; tests +546/-7 Most of the substantial change is privileged proof infrastructure, so focused tests do not replace hosted boundary validation.

Stored data model

Persistent data-model change detected: database schema: test/scripts/mantis-build-telegram-desktop-proof-evidence.test.ts, serialized state: scripts/e2e/mock-openai-server.mjs, serialized state: test/scripts/e2e-mock-config-limits.test.ts, serialized state: test/scripts/mantis-build-telegram-desktop-proof-evidence.test.ts, serialized state: test/scripts/telegram-bot-api-proxy.test.ts, vector/embedding metadata: scripts/mantis/build-telegram-desktop-proof-evidence.mts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair and prove the trusted path (recommended)
    Correct the recipe and run an end-to-end Mantis case that injects a Bot API fault while confirming the candidate cannot rewrite the recorded facts.
  2. Accept source-only evidence
    Merge without hosted boundary proof, accepting uncertainty in Docker mount behavior and the changed Codex execution setting.

Technical review

Best possible solution:

Repair the callback recipe to derive the SUT message ID and inspect callback-bearing markup requests, then prove proxy isolation and trusted evidence publishing in a real Mantis workflow run before merge.

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

Yes, source reproducible: the callback recipe references an unset bot-message variable and filters out the requests that normally carry callback_data.

Is this the best way to solve the issue?

No: the programmable boundaries are a plausible direction, but the callback recipe must first capture the actual bot message and inspect sendMessage or editMessageReplyMarkup facts.

Full review comments:

  • [P2] Capture the bot ID and callback-bearing Bot API request — .github/codex/prompts/mantis-recipes/callback-data-payload-proof.md:9-19
    This recipe never assigns $bot_message_id; turn returns sent.revealedMessageId, which is the QA user's message, not the bot button. It also filters only answerCallbackQuery and editMessageText, neither of which is the general carrier for the original callback_data. Capture the SUT message ID from the observed event and compare sendMessage and/or editMessageReplyMarkup request bodies, with focused coverage for that recipe path.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 500bb6031d17.

Labels

Label changes:

  • add merge-risk: 🚨 security-boundary: The workflow records evidence across an untrusted candidate and a privileged proxy, and the critical mount isolation has not been exercised end to end.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Not applicable to this member-authored PR, but its body confirms that no real Mantis workflow run has yet exercised the new sudo, Docker-mount, lane-fact, and artifact path.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: The broken recipe blocks one of the PR's advertised callback-payload proof scenarios but does not affect ordinary user runtime behavior.
  • merge-risk: 🚨 automation: The PR changes a GitHub Actions proof workflow and its Codex execution configuration without a completed hosted run.
  • merge-risk: 🚨 security-boundary: The workflow records evidence across an untrusted candidate and a privileged proxy, and the critical mount isolation has not been exercised end to end.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Not applicable to this member-authored PR, but its body confirms that no real Mantis workflow run has yet exercised the new sudo, Docker-mount, lane-fact, and artifact path.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs test/scripts/telegram-mantis-lane.test.ts test/scripts/telegram-bot-api-proxy.test.ts test/scripts/mantis-telegram-desktop-proof-workflow.test.ts.
  • [P1] node scripts/check-changed.mjs --dry-run -- .github/codex/prompts/mantis-recipes/callback-data-payload-proof.md test/scripts/mantis-telegram-desktop-proof-workflow.test.ts.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • Peter Steinberger: Recent history covers the isolated proof harness and its lifecycle hardening. (role: recent Mantis isolation and hardening contributor; confidence: high; commits: 89bb601b9171, 01cd0a48dbf1, 1695854877ff; files: scripts/mantis/mantis-sut-container.sh, .github/workflows/mantis-telegram-desktop-proof.yml, scripts/e2e/telegram-mantis-sut.ts)
  • obviyus: The author also appears in earlier Mantis feature history, not solely on this proposed branch. (role: Mantis feature contributor; confidence: medium; commits: b7b7eec5ee7b, 49c6e6bb4152; files: scripts/e2e/telegram-mantis-lane.ts, .github/codex/prompts/mantis-telegram-desktop-proof.md)

Rank-up moves

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

  • Capture the SUT message ID and inspect the Bot API request that carries callback_data.
  • Run a real Mantis workflow with a fault-injection scenario and verify proxy records remain inaccessible to candidate code.
  • Verify the Codex high-effort setting against the direct upstream runtime source.

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-08-22T05:09:28.668Z sha 7254b65 :: needs maintainer review before merge. :: none

The SUT container bind-mounts the whole runtime read-write as the
mantis-sut UID, which included proxy-control/ — the trusted Bot API
fault rules and recorded request facts the proxy container writes.
Untrusted candidate code could rewrite its own evidence before finish
published it. An inaccessible tmpfs now shadows proxy-control inside
the SUT container (cap-drop ALL prevents unmounting), and the prompt
no longer presents SUT-co-located provider request logs as standalone
comparison evidence.
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 22, 2026
@obviyus

obviyus commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-land review disposition (head 49c6e6b)

Local ClawSweeper round 3 (gpt-5.6-terra, high reasoning) on head 49c6e6bb415: patch is correct, zero findings; security review left two proof next-steps. The hosted review at 7254b65 (gold shrimp) listed two optional Rank-up moves. All four dispositions:

1. Final-effect proof: candidate code cannot access proxy-control/ while the proxy still records — done

Docker proof reproducing the exact SUT mount layout from scripts/mantis/mantis-sut-container.sh (rw runtime bind + type=tmpfs,dst=<runtime>/proxy-control,tmpfs-size=65536,tmpfs-mode=0000, non-root user sharing the record-sink uid — the actual threat model — plus --cap-drop ALL and --security-opt no-new-privileges):

=== [1] SUT-analog container: same uid as record-sink owner, exact mount layout ===
-- read requests.ndjson:    cat: .../proxy-control/requests.ndjson: No such file or directory   exit=1
-- overwrite requests.ndjson: bash: .../proxy-control/requests.ndjson: Permission denied        exit=1
-- create forged file:      touch: cannot touch '.../proxy-control/forged': Permission denied   exit=1
-- unmount the shadow:      umount: .../proxy-control: must be superuser to unmount.            exit=32
-- sanity, runtime itself rw: exit=0

=== [2] Proxy-analog container: direct proxy-control bind (the mount the real proxy gets), same uid ===
append ok, exit=0

=== [3] Host view after both containers ===
PROXY-FACT-1
PROXY-FACT-2        <- proxy append landed; no forged entries; record intact

Candidate-uid code sees only an empty tmpfs (the real record is hidden entirely), cannot write into it, and cannot unmount the shadow, while the runtime mount stays rw for the SUT and the proxy keeps recording through its own bind.

2. "Rebase and run the controlled Mantis workflow on the exact merge head" / "Run one redacted Mantis workflow demonstrating the new control classes" — skipped pre-merge; structurally cannot exercise this PR

The proof workflow checks out its harness at ${{ github.workflow_sha }} (.github/workflows/mantis-telegram-desktop-proof.yml:288), so any pre-merge dispatch runs main's harness and none of this PR's changes. The first post-merge Mantis run is the live demonstration; this is the known evidence gap already stated in the PR body.

3. "Verify the exact pinned Codex runtime/action accepts the configured high effort" — done, sources inspected

  • Workflow: .github/workflows/mantis-telegram-desktop-proof.yml:763 pins openai/codex-action@52fe01ec70a42f454c9d2ebd47598f9fd6893d56; line 781 sets effort: high.
  • Pinned action source (src/runCodexExec.ts:158 at that SHA): forwards the input as --config model_reasoning_effort="high" to codex exec.
  • Codex runtime (openai/codex): codex-rs/core/src/config/mod.rs:896 declares model_reasoning_effort: Option<ReasoningEffort>; codex-rs/protocol/src/openai_models.rs:50-56 defines ReasoningEffort::{None, Minimal, Low, Medium (default), High} — "high" deserializes to a supported variant.

Pre-merge proof summary

  • Exact-head CI green on 49c6e6bb415: run 32553780638
  • Local: 80/80 tests across the two touched suites, including the two new regression tests (stale-cursor observe early-return; shadow-mount ordering assertions); check-changed full plan green; git diff --check clean
  • The diff touches only the Mantis harness, prompts, recipes, and their tests — no channel-visible product code — so the Telegram userbot gate uses the generic default-turn probe: passed — leased QA user sent a DM turn through TDLib against a gateway built from this head; recorded timeline shows user message → SUT typing → SUT reply OPENCLAW_E2E_OK at 4.4s, recordingComplete: true.

@obviyus
obviyus merged commit 10e0e69 into main Aug 22, 2026
158 of 160 checks passed
@obviyus
obviyus deleted the t3code/improve-mantis-proof-testing branch August 22, 2026 05:36
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 23, 2026
…claw#127782)

Makes the Mantis Telegram Desktop proof agent programmable at its trust boundaries: declarative Bot API fault rules (drop/status per method), per-request scripted mock-provider responses, observe-until predicates (post-cursor events/text, cumulative provider count), and bounded proxy-side recording of outbound Bot API requests as trusted lane facts. Adds a reusable recipe library under .github/codex/prompts/mantis-recipes/ and raises the proof agent's reasoning effort to high.

Security: the SUT container shadows proxy-control with an inaccessible tmpfs so candidate PR code sharing the mantis-sut uid cannot read or rewrite the proxy's recorded evidence; unmount is blocked by cap-drop/no-new-privileges. Proof doctrine now treats proxy-recorded Bot API facts as trusted comparison evidence and provider request logs as diagnostics.

Follow-up named in PR: move the mock OpenAI server out of the SUT container so provider request facts also become candidate-tamper-proof.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant