Skip to content

fix: preserve tasks following text directives - #138545

Merged
steipete merged 3 commits into
mainfrom
codex/r3-text-commands
Sep 5, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/r3-text-commands

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #138530

Additional instructions

This branch is in openclaw/openclaw, available for maintainers to edit directly.

Problem and fix

A text directive followed by a task could finish with an argument error or a settings acknowledgment instead of an agent reply. For example, /exec security=deny ask=always Explain the output. rejected Explain, while putting the task on the next line produced only an acknowledgment. The release Gateway regression also reproduced /think high followed by a multiline task completing without any provider request.

Text directives had acquired native commands' exclusive argument ownership and were parsed from canonical command text that discards later lines. This repair preserves complete text arguments during alias and bot-address normalization, then uses the existing inline directive parser. Native commands retain strict argument validation. The argument validator and metadata now describe command ownership rather than treating text as native.

Malformed text /exec arguments are classified from the original input before sibling directives can consume them. This prevents /exec /think high and /exec /think high host=gateway from applying sibling settings instead of rejecting /think. Leading spaces or newline indentation no longer produce an empty unexpected-argument diagnostic. Only the displayed diagnostic token is trimmed; task bytes remain intact.

Behavior and scope

Valid text directives can precede same-line or multiline tasks, with code indentation, tabs, repeated spaces, and trailing whitespace preserved. Coverage includes colon syntax, aliases, addressed commands, multiple directives, disabled-text routing, per-turn overrides, and directives addressed to another bot. Invalid positional /exec gateway still receives a command error. No configuration, protocol, or persistence format changes.

Production grows by 20 lines and tests by 176 lines across the complete PR. The final follow-up contributes production +7 and tests +60: the parser adds six net lines to establish raw-argument ownership before destructive extraction, and the diagnostic expression wraps by one line. The preliminary parse reuses the canonical exec extractor and removes late classification; no separate argument policy is introduced. The QA scenario reference follows the validator rename to directive-handling.arguments.ts.

Verification

Final source: d0b816bc081317b60fe43d2a7fb9b608042fe6ba. This is the exact tree tested before commit as base 5c6fbc77406dcb797bbc5c3af9ab65e73a7ef435 plus patch SHA-256 4d394b0ef1b3097ec48430d86ca854d9b0f5f948d4c5462fcc82035bd52237bb.

  • The unchanged real Gateway whitespace test fails on frozen main 2329399cf6a9a2ca0c19d6c620b713a2768f9125: the run returns ok, a thinking-level acknowledgment is recorded, and the first provider request is absent. It passes after the repair.
  • Four malformed-exec regressions fail on the prior PR implementation; all pass with the final follow-up. The original policy-plus-task full-reply regressions also remain covered.
  • Frozen dependency install and the complete changed-file gate pass, including core and test types, lint, dead exports, and repository guards. The first final gate caught a test-table no-map-spread violation; explicit fields fixed it, and the complete gate passed on retry.
  • Canonical private-QA and AI runtime builds pass. All 300 tests across six directive/normalizer/native/full-reply files and all eight unchanged Gateway chat RPC tests pass: three shards in 400.27 seconds.
  • Fresh isolated Codex review is scoped-clean through P2. Independent owner-boundary review found both malformed-exec defects resolved without a duplicate policy path.

The Gateway test uses a real ephemeral Gateway and a mock OpenAI-compatible HTTP provider. Two turns verify the first provider request's raw task whitespace, immediate directive removal, canonical chat history, and original directive replay on the second turn. Sibling Gateway cases cover explicit agent ownership, attachments, native dispatch, final-effect settings, and stale-send rejection.

The following is a maintainer summary of observed harness results, not a verdict file emitted by the harness:

{
  "sourceCommit": "d0b816bc081317b60fe43d2a7fb9b608042fe6ba",
  "testedBase": "5c6fbc77406dcb797bbc5c3af9ab65e73a7ef435",
  "patchSha256": "4d394b0ef1b3097ec48430d86ca854d9b0f5f948d4c5462fcc82035bd52237bb",
  "build": "canonical private-QA and AI runtime passed",
  "unitTestsPassed": 300,
  "gatewayTestsPassed": 8,
  "gateway": "real ephemeral process",
  "provider": "mock HTTP provider",
  "firstRequestWhitespaceAndHistoryReplay": "passed across two turns",
  "telegramLive": "not run"
}

Reproduction and final proof commands:

CI=true pnpm install --frozen-lockfile
node scripts/check-changed.mjs --base 5c6fbc77406dcb797bbc5c3af9ab65e73a7ef435 --timed
OPENCLAW_E2E_WORKERS=1 node scripts/run-vitest.mjs \
  src/auto-reply/reply/get-reply-text-slash-directives.test.ts \
  src/auto-reply/commands-registry.test.ts \
  src/auto-reply/reply/get-reply-native-slash-fast-path.test.ts \
  src/auto-reply/reply.directive.parse.test.ts \
  src/auto-reply/reply/directive-handling.mixed-inline.test.ts \
  src/auto-reply/reply/get-reply.text-directives.test.ts \
  test/e2e/qa-lab/runtime/gateway-rpc-chat.e2e.test.ts

The parent-relative patch in #137562 (2f6a3d8fb126707b3661299894388a8c4f4e1d81, parent f959cc71e28ee298fdcf41119f5dac5092347f5c) establishes the regression's source provenance. Existing directive documentation already describes the restored behavior.

Remaining channel proof

ClawSweeper's latest review requested a Telegram Test Server event timeline and a rationale for production growth. The ownership rationale is above. Authenticated Telegram Test Server broker access was unavailable, so Telegram live proof was not run; no Telegram event proof or proof exception is claimed. Real Gateway/mock-provider evidence is identified separately above.

Named follow-up: preserve multiline Telegram command projection at ingress. Telegram separately normalizes its command body before this core boundary (extensions/telegram/src/bot-message-context.session.ts). That preexisting producer behavior can discard later setting lines. This PR's multiline directive proof uses intact core command text and does not claim to repair Telegram multiline settings.

Keep native argument ownership strict while preserving complete text directive arguments and mixed tasks. Retain positional exec rejection and cover the full reply pipeline.

Closes #138530
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 19:30
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 8:04 PM ET / September 5, 2026, 00:04 UTC.

ClawSweeper review

What this changes

Preserves tasks and their whitespace after text slash directives, while retaining strict native-command validation and rejecting malformed positional /exec arguments.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

No blocking findings. This remains a necessary repair for the source-proven regression on pinned main; the linked issue should remain open until the repair lands.

Priority: P1
Reviewed head: d0b816bc081317b60fe43d2a7fb9b608042fe6ba

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with useful regression coverage and reported Gateway results, without claiming unperformed Telegram verification.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR. Its exact-head maintainer report maps real Gateway chat.send execution to first-provider-request whitespace and history assertions; Telegram execution is explicitly unclaimed, with broker-access infeasibility and the separate ingress follow-up documented. This is not classified as a Telegram harness verdict.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR. Its exact-head maintainer report maps real Gateway chat.send execution to first-provider-request whitespace and history assertions; Telegram execution is explicitly unclaimed, with broker-access infeasibility and the separate ingress follow-up documented. This is not classified as a Telegram harness verdict.
Evidence reviewed 11 items Verified review scope: The checkout is the pinned original head, with raw parent 5c6fbc7. The locally inspected merge-base-to-head delta matches the supplied introduced-file list. The stale test merge and endpoint drift were not used to attribute changes.
Pinned main still needs the repair: Main still supplies first-line-normalized text and native command ownership for explicit text directives. This explains the same-line argument rejection and multiline task loss. The relevant normalizer, parser, and coordinator match the PR merge-base versions.
Existing product contract: The documented contract preserves remaining task spacing and line endings, limits execution security/approval options to the current message, and restricts directive application to authorized senders. This is an existing-behavior repair rather than a new directive mode.
Findings None None.
Security None None.

How this fits together

The shared reply pipeline interprets authorized chat directives before deciding whether to acknowledge settings or run an agent. Its output includes the remaining task text, per-message execution policy, and any session-setting changes.

flowchart TD
  A[Incoming chat text] --> B[Existing sender authorization]
  B --> C[Text or native command]
  C --> D[Command normalization and directive parsing]
  D --> E{Settings only or task remains}
  E --> F[Settings acknowledgment or argument error]
  E --> G[Agent task with per-message policy]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +20, Tests +176, Other 0. Total +196 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 11 88 68 +20
Tests 3 196 20 +176
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 15 285 89 +196

Review metrics

Metric Value Why it matters
Production versus test growth Production +20 net; tests +176 net; QA scenario metadata net 0 After discounting the validator rename, the production growth supports lossless normalization and raw-argument ownership using existing extractors rather than a parallel parser.
Normalization API 1 optional API parameter added; 0 user-config options or default changes The SDK-exported helper retains its existing behavior unless the directive owner explicitly requests argument preservation.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138530
Summary: This PR is the implementation candidate for the open task-loss report; earlier positional-exec validation is related work, not a replacement fix.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep one inline parser with opt-in lossless text normalization and early malformed-exec classification; the small production increase protects distinct text/native contracts without replacing existing plugin defaults.

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

Yes, source establishes a high-confidence path on pinned main: submit an authorized text /exec policy followed by a task on the same line or next line. The supplied failing full-reply and Gateway results corroborate that mechanism; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes, this repairs the shared owner using existing extractors rather than adding a competing parser. Globally changing normalization would affect standalone commands, while removing strict ownership entirely would reopen malformed positional-exec handling.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 62ff6248557c.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 message-delivery: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: Pinned main can reject or silently omit an authorized task following a text directive, breaking an existing agent workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored PR. Its exact-head maintainer report maps real Gateway chat.send execution to first-provider-request whitespace and history assertions; Telegram execution is explicitly unclaimed, with broker-access infeasibility and the separate ingress follow-up documented. This is not classified as a Telegram harness verdict.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Task-versus-error replies are Telegram-visible when text-command routing is used; the Test Server proof lane applies, although the PR documents why it was not run.

Evidence

What I checked:

  • Verified review scope: The checkout is the pinned original head, with raw parent 5c6fbc7. The locally inspected merge-base-to-head delta matches the supplied introduced-file list. The stale test merge and endpoint drift were not used to attribute changes. (d0b816bc0813)
  • Pinned main still needs the repair: Main still supplies first-line-normalized text and native command ownership for explicit text directives. This explains the same-line argument rejection and multiline task loss. The relevant normalizer, parser, and coordinator match the PR merge-base versions. (src/auto-reply/reply/get-reply-directives.ts:322, 62ff6248557c)
  • Existing product contract: The documented contract preserves remaining task spacing and line endings, limits execution security/approval options to the current message, and restricts directive application to authorized senders. This is an existing-behavior repair rather than a new directive mode. Public docs: docs/tools/slash-commands.md. (docs/tools/slash-commands.md:39, d0b816bc0813)
  • Canonical owner-boundary repair: The coordinator selects lossless normalization only for explicit text directives. The parser reuses the existing exec extractor on original arguments before sibling extraction, retaining command ownership for malformed positional exec input and native commands. The full reply caller consumes the resulting task and execution overrides. (src/auto-reply/reply/directive-handling.parse.ts:126, d0b816bc0813)
  • Regression and sibling coverage: The added cases cover same-line and multiline tasks, aliases, addressed commands, whitespace, malformed exec arguments, and disabled text routing. Full-reply cases assert one agent invocation with the task and deny/always overrides. Existing native tests retain strict trailing-argument rejection; mixed-inline coverage checks that execution policy does not persist into the following turn. These tests were inspected, not executed during this review. (src/auto-reply/reply/get-reply.text-directives.test.ts:44, d0b816bc0813)
  • Reported Gateway evidence maps to the changed behavior: The supplied PR snapshot, sourceRevision a55bd5d8a1f00ac04bda7f6dca731c3298025c012c11b52ae35fb95b75b18947, reports an exact-head real ephemeral Gateway run against a mock HTTP provider. The inspected unchanged test calls chat.send, verifies the first provider request's raw whitespace, waits for the assistant reply in history, and checks directive removal followed by original-history replay on a second turn. The body identifies its JSON as a maintainer summary, not a harness-emitted verdict or Telegram event trace. (test/e2e/qa-lab/runtime/gateway-rpc-chat.e2e.test.ts:323, d0b816bc0813)

Likely related people:

  • jalehman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-09-04T19:38:23.467Z sha 1051fc5 :: blocked before merge. :: none
  • reviewed 2026-09-04T20:47:33.969Z sha 5c6fbc7 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 4, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Sep 5, 2026
@steipete
steipete merged commit 805c6fb into main Sep 5, 2026
188 checks passed
@steipete
steipete deleted the codex/r3-text-commands branch September 5, 2026 00:16
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
* fix: preserve tasks following text directives

Keep native argument ownership strict while preserving complete text directive arguments and mixed tasks. Retain positional exec rejection and cover the full reply pipeline.

Closes openclaw#138530

* fix(qa): follow canonical directive argument helper

* fix: validate raw text exec argument boundaries
ruel225 added a commit to ruel225/openclaw that referenced this pull request Sep 5, 2026
…tch turns

An inline reply directive that rejects before any model run starts — a
restricted explicit /model request, a locked model selection, conflicting
scope flags, an unsupported runtime, a native command with leftover
arguments, or a session transaction that loses its compare-and-swap —
returned the error reply to the sender while the dispatch terminal
outcome still reported `completed` with no reason. The `message.processed`
diagnostic event therefore showed a normal successful turn and
investigators had no trace to correlate the rejection against (openclaw#137198).

The rejection facts already existed at the directive owners; they were
dropped once the reply left the directive layer. Rather than emitting a
parallel event, this records the rejection on the existing
`ReplyOperationRunState` reply-option channel — the same pattern
`messageInjectionAborted` already uses — and lets the dispatch finalize
step, which already owns the terminal outcome, read it:

- `applyInlineDirectiveOverrides` returns a `preRunRejection` (closed
  `ReplyPreRunRejectionCode` + reply text) from each of its 7 rejection
  sites through one shared `directiveRejection` helper.
- The `ModelSelectionLockedError` catch sites in `get-reply.ts` record the
  same closed `model-selection-locked` code through one canonical
  `recordReplyPreRunRejection` helper on the run state.
- The dispatch finalizer reports `skipped` with the closed code as the
  `reason` and the reply text as `error` on `message.processed`.

Rebuilt onto current `main` after openclaw#138545's directive-handling refactor:
the unexpected-argument rejection rides the renamed
`maybeHandleUnexpectedDirectiveArguments` (return type narrowed so the
closed code carries the reply text), directive inspection uses the
refactored `directives.command` shape, the real-stream test passes the
now-required prepared conversation, and the queue-disposition binder the
refactor left caller-less is not carried over. On current `main` the
unexpected-argument branch still returns a bare reply without recording
a rejection, so the reported gap remains real.

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: qa-lab maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Text exec directives reject or drop the following task

1 participant