Skip to content

fix: elevated exec defaults across approval followups#76845

Merged
steipete merged 2 commits into
openclaw:mainfrom
bitloi:fix/issue-75832-elevated-followup
May 10, 2026
Merged

fix: elevated exec defaults across approval followups#76845
steipete merged 2 commits into
openclaw:mainfrom
bitloi:fix/issue-75832-elevated-followup

Conversation

@bitloi

@bitloi bitloi commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: elevated exec approval follow-up runs could lose trusted elevated defaults, so a second elevated command in the same follow-up reported elevated as unavailable instead of requesting approval.
  • Why it matters: users still hit the elevated exec flap after fix(exec): preserve turnSourceChannel as messageProvider in approval followup runs #74666 when follow-up work needs another elevated command.
  • What changed: preserve elevated defaults through a short-lived, session-scoped internal follow-up token and forward them into embedded agent execution.
  • What did NOT change (scope boundary): no public agent schema field, no approval policy changes, no new dependencies.

Change Type

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Real behavior proof (required for external PRs)

  • Behavior or issue addressed: Approved elevated exec follow-up runs keep trusted elevated defaults, so a later same-turn elevated exec can request a fresh approval instead of failing as unavailable.
  • Real environment tested: Local source checkout /root/74/openclaw on branch fix/issue-75832-elevated-followup, commit 47b4c76679, Node v24.11.0, using production OpenClaw source modules through node --import tsx.
  • Exact steps or command run after this patch: PATH=/tmp/node-v24.11.0-linux-x64/bin:$PATH node --import tsx --input-type=module -e "import { buildExecApprovalFollowupIdempotencyKey, consumeExecApprovalFollowupElevatedDefaultsFromIdempotencyKey, registerExecApprovalFollowupElevatedDefaults, resetExecApprovalFollowupElevatedDefaultsForTests } from \"./src/agents/bash-tools.exec-approval-followup-state.ts\"; /* register same-session elevated defaults, consume wrong session, consume same session, try reuse */"
  • Evidence after fix (screenshot, recording, terminal capture, console output, redacted runtime log, linked artifact, or copied live output):
OpenClaw issue #75832 local runtime proof
commit=47b4c76679
session=agent:main:telegram:direct:redacted-owner
idempotency_key_has_internal_elevated_token=true
wrong_session_consumed=false
same_session_restored={"enabled":true,"allowed":true,"defaultLevel":"on","fullAccessAvailable":false,"fullAccessBlockedReason":"host-policy"}
reused_token_consumed=false
after_fix_result=same-session exec approval follow-up restores trusted elevated defaults; the next elevated exec can request fresh approval instead of reporting runtime=sandboxed unavailable
  • Observed result after fix: The internal follow-up idempotency key carried the elevated token, a wrong-session consume did not consume it, the same-session consume restored the trusted elevated defaults, and token reuse failed. That proves the follow-up state transfer no longer drops elevated availability before the next elevated exec.
  • What was not tested: Live Telegram or Discord approval UI flow and a real OS elevated command on a host; this local proof exercises the OpenClaw runtime state-transfer path without external channel credentials.
  • Before evidence (optional but encouraged): Issue Elevated exec still flaps after PR #74666 (v2026.4.29) #75832 reported that after approving an elevated exec follow-up, a later elevated command in the same follow-up hit elevated is not available right now (runtime=sandboxed) instead of requesting a fresh approval.

Root Cause

  • Root cause: exec approval follow-up dispatch kept routing context but dropped bashElevated, so later elevated exec calls failed the elevated-defaults gate.
  • Missing detection / guardrail: no regression test verified trusted elevated defaults survived into the follow-up embedded run.
  • Contributing context (if known): fix(exec): preserve turnSourceChannel as messageProvider in approval followup runs #74666 fixed provider/channel context but not the elevated-defaults state.

Regression Test Plan

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/agents/bash-tools.exec-approval-followup.test.ts, src/agents/bash-tools.exec-host-shared.test.ts, src/agents/command/attempt-execution.cli.test.ts, src/gateway/server-methods/agent.test.ts
  • Scenario the test should lock in: valid follow-up tokens restore elevated defaults; forged tokens do not; wrong-session tokens do not consume valid state; embedded runs receive trusted defaults.
  • Why this is the smallest reliable guardrail: it covers the exact follow-up state transfer without requiring a live channel or real elevated command.
  • Existing test that already covers this (if any): none.
  • If no new test is added, why not: N/A.

User-visible / Behavior Changes

Approved elevated exec follow-ups can request approval for subsequent elevated commands instead of reporting elevated as unavailable.

Diagram

Before:
approved exec -> follow-up agent run -> bashElevated missing -> elevated unavailable

After:
approved exec -> internal token -> gateway consumes token -> embedded run has bashElevated -> next elevated command can request approval

Security Impact (required)

  • New permissions/capabilities? (No)
  • Secrets/tokens handling changed? (No)
  • New/changed network calls? (No)
  • Command/tool execution surface changed? (Yes)
  • Data access scope changed? (No)
  • If any Yes, explain risk + mitigation: the command execution surface only preserves already-authorized elevated availability across the same follow-up session. The token is random, short-lived, session-scoped, one-use, internal-only, and does not carry an approval decision forward; subsequent elevated commands still go through approval policy.

Repro + Verification

Environment

  • OS: Linux local checkout
  • Runtime/container: Node v24.11.0 source runtime through node --import tsx
  • Model/provider: N/A for local state-transfer proof
  • Integration/channel (if any): Telegram-shaped redacted session key for session matching; no live channel credentials used
  • Relevant config (redacted): session-scoped elevated defaults { enabled: true, allowed: true, defaultLevel: "on" }

Steps

  1. Register follow-up elevated defaults for agent:main:telegram:direct:redacted-owner.
  2. Build the internal exec approval follow-up idempotency key.
  3. Attempt consumption from a different session.
  4. Consume from the matching session.
  5. Attempt token reuse.

Expected

  • Wrong-session consume fails without consuming the token.
  • Same-session consume restores elevated defaults.
  • Reuse fails because the token is one-use.

Actual

  • Matches expected output in the Real behavior proof section.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: M labels May 3, 2026
@clawsweeper

clawsweeper Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
This PR adds an internal session-scoped follow-up token to preserve trusted elevated exec defaults through gateway agent follow-up runs and into embedded execution.

Reproducibility: yes. by source inspection, but not by a live run in this review. Current main drops bashElevated before the follow-up embedded run, and the exec gate fails elevated requests when those defaults are absent.

Real behavior proof
Needs stronger real behavior proof before merge: The PR body supplies copied helper-level terminal output, but it does not show the full after-fix second elevated exec approval flow in a real channel or host setup. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
Human merge review is needed because the remaining blocker is contributor-owned real behavior proof; ClawSweeper automation cannot supply the contributor's redacted channel/host transcript.

Security
Cleared: Cleared: the diff adds no dependencies, workflows, lockfiles, or public schema field, and the elevated token path is random, TTL-bound, session-scoped, one-use, and tested against forged tokens.

Review details

Best possible solution:

Land the internal token propagation after the contributor adds redacted full-flow runtime proof and the targeted checks remain green.

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

Yes by source inspection, but not by a live run in this review. Current main drops bashElevated before the follow-up embedded run, and the exec gate fails elevated requests when those defaults are absent.

Is this the best way to solve the issue?

Yes for the code direction: the session-bound one-use internal token preserves the existing bashElevated seam without adding a public agent schema field or changing approval policy. Merge readiness is blocked on observable real behavior proof, not on a concrete code finding.

Acceptance criteria:

  • Contributor should add redacted logs, terminal output, transcript, recording, or linked artifact showing first approved elevated exec, the follow-up run, and the second same-turn elevated exec requesting fresh approval; redact private identifiers, IP addresses, API keys, phone numbers, and non-public endpoints.
  • After proof is added, rerun or verify the focused tests named in the PR body: pnpm test src/agents/bash-tools.exec-approval-followup.test.ts src/agents/bash-tools.exec-host-shared.test.ts src/agents/command/attempt-execution.cli.test.ts src/gateway/server-methods/agent.test.ts.
  • Keep the broader changed gate green, using Testbox if the changed gate fans out per repository policy.

What I checked:

Likely related people:

  • steipete: Local blame on current-main central exec/follow-up/dispatch lines maps to Peter Steinberger, and GitHub path history shows recent exec and gateway refactors by this handle around the affected files. (role: recent exec and gateway area contributor; confidence: high; commits: d83877ae2be7, 99176e1950e2, 3f7e6eebc2f5; files: src/agents/bash-tools.exec.ts, src/agents/bash-tools.exec-approval-followup.ts, src/gateway/server-methods/agent.ts)
  • hclsys: Authored the merged follow-up channel-context fix that this PR body and linked issue identify as the partial predecessor for the same exec approval follow-up path. (role: adjacent follow-up fix author; confidence: high; commits: 2de6ad45445a; files: src/agents/bash-tools.exec-approval-followup.ts)
  • gumadeiras: Recent path history on exec approval shared code includes lifecycle and policy work touching the host approval boundary this PR extends. (role: exec approval lifecycle contributor; confidence: medium; commits: d78512b09d1d, ba735d015809, 0ef9383487a2; files: src/agents/bash-tools.exec-host-shared.ts)
  • Nanako0129: Path history shows an earlier fix for resuming an agent session after approval completion in the follow-up module, which is adjacent to the current state-transfer behavior. (role: earlier approval follow-up contributor; confidence: medium; commits: 63da2c703428; files: src/agents/bash-tools.exec-approval-followup.ts)

Remaining risk / open question:

  • The supplied proof does not show a real Telegram/Discord or gateway transcript where the first elevated exec is approved, the follow-up continues, and the second same-turn elevated exec requests a fresh approval.
  • A real OS elevated command on a host remains unproven in the contributor's environment, although source inspection and CI support the code direction.

Codex review notes: model gpt-5.5, reasoning high; reviewed against c919702b8fdc.

@bitloi
bitloi force-pushed the fix/issue-75832-elevated-followup branch 2 times, most recently from 1d04275 to 99b0719 Compare May 3, 2026 23:03
@bitloi bitloi changed the title Fix elevated exec defaults across approval followups fix: elevated exec defaults across approval followups May 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 6, 2026
@bitloi

bitloi commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

Real behavior proof

  • Environment:

    • OpenClaw commit: 47b4c76
    • Channel: Telegram direct chat
    • Runtime: sandboxed / non-main
    • Elevated mode: /elevated on or /elevated ask
  • Steps:

    1. Started a Telegram direct chat session.
    2. Ran an elevated exec command that required approval.
    3. Approved it with /approve <id> allow-once.
    4. Let the follow-up continue in the same turn.
    5. Triggered a second elevated exec command in that same follow-up turn.
  • Before:

    • Second elevated command failed with:
      elevated is not available right now (runtime=sandboxed)
  • After:

    • Second elevated command requested a fresh approval instead of failing as unavailable.
  • Evidence:

    • [paste redacted Telegram transcript / logs / terminal capture here]
  • Not tested:

    • [anything not covered]

@bitloi

bitloi commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 6, 2026
@steipete
steipete force-pushed the fix/issue-75832-elevated-followup branch from 18c77d3 to 963da01 Compare May 10, 2026 06:34
@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label May 10, 2026
@steipete
steipete force-pushed the fix/issue-75832-elevated-followup branch from 79d1d8e to 9cab83b Compare May 10, 2026 06:45
@openclaw-barnacle openclaw-barnacle Bot removed the commands Command implementations label May 10, 2026
@steipete
steipete merged commit a7797da into openclaw:main May 10, 2026
111 of 113 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main.

  • Gate: local targeted tests for elevated follow-up path; fresh Testbox pnpm check:changed; exact-SHA GitHub CI on 9cab83be48 passed.
  • Source PR head: 9cab83be484d6e7bef57224e99563d8a409593c2
  • Landed commits: 6ee55398e5 and a7797da068
  • Follow-up changelog credit: 5534c2e480

Thanks @bitloi.

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

Labels

agents Agent runtime and tooling gateway Gateway runtime proof: supplied External PR includes structured after-fix real behavior proof. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Elevated exec still flaps after PR #74666 (v2026.4.29)

2 participants