Skip to content

fix: allow steer messages during active non-streaming runs - #73365

Closed
vincentkoc wants to merge 5 commits into
mainfrom
clownfish/ghcrawl-156681-autonomous-smoke
Closed

vincentkoc wants to merge 5 commits into
mainfrom
clownfish/ghcrawl-156681-autonomous-smoke

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • Replace the isStreaming-only steer/interrupt injection gate with lifecycle-aware active/stopped handling for embedded and reply runs.
  • Preserve the old conservative streaming fallback for handles that do not expose isStopped, addressing the latest Codex P1 review finding on fix: use isActive+isStopped instead of isStreaming for steer message injection #65010.
  • Keep the patch narrow and avoid unrelated release, docs, generated baseline, Discord, QA, Docker, and script churn from the source branch.

Credit

This carries forward the focused fix direction from @jetd1 in #65010 and the earlier steer-mode approach from @scottyallen in #52351. Thanks to both contributors; this PR is a clean replacement branch so attribution is preserved while keeping review scope small.

Validation

  • pnpm -s vitest run src/agents/pi-embedded-runner/runs.test.ts src/auto-reply/reply/agent-runner.steer-guard.test.ts
  • pnpm check:changed

Notes

Covers the core duplicate reports #48003 and #50880. Telegram-specific delivery bypass (#65222) and interrupt scheduling race work (#65221) remain related follow-up subclusters.

ProjectClownfish replacement details:

@vincentkoc vincentkoc added clownfish:human-review clawsweeper Tracked by ClawSweeper automation labels Apr 28, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Apr 28, 2026
@greptile-apps

greptile-apps Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces the isStreaming-only steer/interrupt injection gate with a lifecycle-aware check using an optional isStopped hook on both embedded and reply-run handles, allowing steer messages to reach agent loops that are active but not currently streaming. Handles without isStopped retain the old conservative isStreaming() fallback.

The changes are well-scoped and the new test cases cover all three injection branches. Two minor cleanup items remain: the isStreaming parameter in runReplyAgent's function signature is no longer used (the implementation no longer destructures it) and the diagnostic log message reason=not_streaming in queueEmbeddedPiMessage is now stale when a stopped handle is the actual cause.

Confidence Score: 4/5

Safe to merge; all findings are P2 style/cleanup items with no impact on runtime correctness.

Logic is sound — the new isStopped-aware ternary is applied consistently in both queueEmbeddedPiMessage and queueReplyRunMessage, the abort signal wiring in attempt.ts is correct, and existing compat handles are unaffected. Only P2 issues remain: a dead isStreaming parameter in the function signature and a stale diagnostic reason string.

src/auto-reply/reply/agent-runner.ts — the unused isStreaming field in the params type and its call-site in get-reply-run.ts should be removed.

Comments Outside Diff (1)

  1. src/auto-reply/reply/agent-runner.ts, line 828 (link)

    P2 Dead isStreaming parameter in function signature

    isStreaming was removed from the destructuring (the shouldSteer && isStreaming condition was replaced with shouldSteer && isActive) but the parameter remains declared in the params type on this line. The field is still populated and passed by callers in get-reply-run.ts (line 899). Since the function no longer reads it, both the signature and the call-site assignment can be removed to avoid confusion for future readers.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/auto-reply/reply/agent-runner.ts
    Line: 828
    
    Comment:
    **Dead `isStreaming` parameter in function signature**
    
    `isStreaming` was removed from the destructuring (the `shouldSteer && isStreaming` condition was replaced with `shouldSteer && isActive`) but the parameter remains declared in the `params` type on this line. The field is still populated and passed by callers in `get-reply-run.ts` (line 899). Since the function no longer reads it, both the signature and the call-site assignment can be removed to avoid confusion for future readers.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/agent-runner.ts
Line: 828

Comment:
**Dead `isStreaming` parameter in function signature**

`isStreaming` was removed from the destructuring (the `shouldSteer && isStreaming` condition was replaced with `shouldSteer && isActive`) but the parameter remains declared in the `params` type on this line. The field is still populated and passed by callers in `get-reply-run.ts` (line 899). Since the function no longer reads it, both the signature and the call-site assignment can be removed to avoid confusion for future readers.

```suggestion
  isActive: boolean;
  isRunActive?: () => boolean;
  opts?: GetReplyOptions;
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/runs.ts
Line: 73

Comment:
**Stale diagnostic reason string**

The debug message still says `reason=not_streaming` but with the new gate it can also fire because the handle is stopped (`isStopped()` returned `true`). Keeping the old message makes it harder to distinguish the two failure modes in logs. Consider something like `reason=not_injectable`.

```suggestion
    diag.debug(`queue message failed: sessionId=${sessionId} reason=not_injectable`);
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix: allow steer messages during active ..." | Re-trigger Greptile

Comment thread src/agents/pi-embedded-runner/runs.ts Resolved
@vincentkoc vincentkoc self-assigned this Apr 28, 2026
@vincentkoc
vincentkoc force-pushed the clownfish/ghcrawl-156681-autonomous-smoke branch 4 times, most recently from 53e2f01 to c02ca40 Compare April 28, 2026 08:59
@vincentkoc

Copy link
Copy Markdown
Member Author

Thanks, both findings are handled now.

  • the embedded handle now treats the post-prompt lifecycle window as non-injectable, so steer/interrupt cannot slip in after the active prompt has ended but before cleanup
  • embedded/reply injectability checks now fail closed when state hooks throw
  • direct steer injection now has entry-point abuse controls: max 4000 chars and a 2s per-session rate gate before forwarding to the backend
  • Greptile cleanup is fixed: removed the dead runReplyAgent.isStreaming param/call-site usage and changed the stale reason=not_streaming diagnostic to reason=not_injectable

Validation:

  • OPENCLAW_TESTBOX=1 pnpm test:serial src/shared/steer-message-injection-policy.test.ts src/agents/pi-embedded-runner/runs.test.ts src/auto-reply/reply/reply-run-registry.test.ts src/auto-reply/reply/agent-runner.steer-guard.test.ts passed in Testbox tbx_01kq9n1fq1hef1mej1n3kr098c.
  • OPENCLAW_TESTBOX=1 pnpm check:changed passed in the same Testbox.

@vincentkoc
vincentkoc force-pushed the clownfish/ghcrawl-156681-autonomous-smoke branch from c02ca40 to 92baa73 Compare April 28, 2026 09:06
@vincentkoc
vincentkoc force-pushed the clownfish/ghcrawl-156681-autonomous-smoke branch from 92baa73 to 5e92b57 Compare April 28, 2026 18:39
@clawsweeper

clawsweeper Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 3, 2026, 4:58 PM ET / 20:58 UTC.

Summary
This PR changes active-run steer admission for embedded and reply runs, adds a shared steer injection policy with tests, and edits CHANGELOG.md.

PR surface: Source +64, Tests +289, Docs +1. Total +354 across 16 files.

Reproducibility: yes. source-level: PR head adds a default-on steer throttle and targets a removed embedded runner path, while current main already has active/not-stopped admission on the live embedded-agent and reply-run paths. I did not run a live Discord, Telegram, or WebChat replay in this read-only review.

Review metrics: 2 noteworthy metrics.

  • Steer Admission Throttle: 1 default-on runtime rate limit added. The new limit changes whether close-together user guidance can enter an active run, which focused tests do not settle for existing workflows.
  • Current Runtime Path Coverage: 0 current embedded-agent-runner files changed; 4 removed pi-embedded-runner files changed. The stated embedded admission fix is already on current runtime paths, while this branch still edits the stale path.

Root-cause cluster
Relationship: superseded
Canonical: #98126
Summary: This PR's central active non-streaming admission slice is superseded by the merged current-path replacement, while broader ordinary-message ingress remains under separate open work.

Members:

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

Merge readiness
Overall: 🧂 unranked krab
Proof: 🌊 off-meta tidepool
Patch quality: 🧂 unranked krab
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Use the merged current-main replacement unless a maintainer identifies a unique remainder.
  • If revived, rebuild from current main, target current embedded-agent-runner paths, remove the throttle, and drop the changelog edit.

Mantis proof suggestion
A native Telegram proof would directly show whether steering guidance reaches an active run instead of waiting behind the current turn. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: verify steer guidance sent during an active run reaches the running session instead of waiting for the turn to finish.

Risk before merge

  • [P1] The default-on two-second steer throttle can reject close-together valid guidance before it reaches an active run, changing existing steering behavior.
  • [P1] The branch edits the removed src/agents/pi-embedded-runner path instead of the current src/agents/embedded-agent-runner runtime path used on main.
  • [P1] The CHANGELOG.md edit conflicts with OpenClaw's release-owned changelog flow for normal PRs.
  • [P1] The broader ordinary-message active-run steering tracker remains open at Steer mode does not inject messages mid-turn for main sessions #48003, so this stale branch should not be treated as the complete fix.

Maintainer options:

  1. Retire In Favor Of Current Main (recommended)
    A maintainer can close this protected branch because the central active non-streaming admission fix already landed on current runtime paths through Restore Telegram /steer for active Codex runs #98126.
  2. Rebuild From Current Main
    If maintainers want a unique remainder, rebuild against current main, target src/agents/embedded-agent-runner, remove the default steer throttle, and drop the normal PR changelog edit.
  3. Accept The Throttle Deliberately
    Maintainers could intentionally add steer rate limiting, but that needs explicit compatibility and product approval because it changes which messages reach active sessions.

Next step before merge

  • [P2] Protected MEMBER and maintainer labels require maintainer handling; the likely action is closing or replacing the superseded branch, not automated repair.

Security
Cleared: No concrete security or supply-chain issue was found; the diff is runtime, test, and changelog code with compatibility and message-delivery blockers.

Review findings

  • [P1] Keep burst steering lossless — src/shared/steer-message-injection-policy.ts:18-26
  • [P1] Target the current embedded runner — src/agents/pi-embedded-runner/runs.ts:71-79
  • [P2] Remove the release-owned changelog edit — CHANGELOG.md:15
Review details

Best possible solution:

Use the merged current-main replacement as the source of truth; a maintainer should close this protected branch or request a narrow rebuild only for a proven unique remainder without the throttle or changelog edit.

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

Yes, source-level: PR head adds a default-on steer throttle and targets a removed embedded runner path, while current main already has active/not-stopped admission on the live embedded-agent and reply-run paths. I did not run a live Discord, Telegram, or WebChat replay in this read-only review.

Is this the best way to solve the issue?

No. The active/not-stopped fix shape is right, but this branch is no longer the best landing path because current main has the replacement on current files and this PR adds throttle, changelog, and stale-path risk.

Full review comments:

  • [P1] Keep burst steering lossless — src/shared/steer-message-injection-policy.ts:18-26
    This helper enables a two-second per-session rate limit by default outside Vitest, and both PR queue entry points return false when it rejects. A second valid steer message sent during the same active tool run can miss the active turn even though steering is meant to preserve guidance at runtime boundaries.
    Confidence: 0.93
  • [P1] Target the current embedded runner — src/agents/pi-embedded-runner/runs.ts:71-79
    This branch changes src/agents/pi-embedded-runner, but current main uses src/agents/embedded-agent-runner and already has the active/not-stopped admission shape there. Rebuilding this branch as-is is not a safe landing path for the runtime users run today.
    Confidence: 0.91
  • [P2] Remove the release-owned changelog edit — CHANGELOG.md:15
    OpenClaw release generation owns CHANGELOG.md, but this normal PR adds a release entry directly. If the branch is rebuilt, keep release-note context in the PR body or commit message and drop this file change.
    Confidence: 0.88

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 010b61746379.

Label changes

Label justifications:

  • P1: The PR targets active agent steering, where dropped or delayed guidance breaks a real user workflow.
  • merge-risk: 🚨 compatibility: The new default-on steer throttle changes existing steering behavior for users who send close-together guidance.
  • merge-risk: 🚨 message-delivery: Rate-limited or stale-path steer admission can delay or suppress guidance instead of injecting it into the active run.
  • merge-risk: 🚨 session-state: The changed active/stopped checks affect which active session context receives mid-run steering text.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored, maintainer-labeled PR.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The PR affects visible active-run steering delivery that can be demonstrated in a short Telegram Desktop proof, even though the direct diff is in shared reply/runtime code.
Evidence reviewed

PR surface:

Source +64, Tests +289, Docs +1. Total +354 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 7 73 9 +64
Tests 8 316 27 +289
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 390 36 +354

What I checked:

  • Repository policy read: Root AGENTS.md was read fully, and its review-depth, protected-item, and release-owned changelog guidance affected this review. (AGENTS.md:13, 010b61746379)
  • Scoped agents policy read: The relevant scoped agents guidance was read; it did not override the runtime/message-delivery findings. (src/agents/AGENTS.md:1, 010b61746379)
  • Protected live PR state: Live GitHub state reports author vincentkoc, assignee vincentkoc, author association MEMBER in context, maintainer label, mergeable CONFLICTING, and mergeStateStatus DIRTY, so this workflow must not auto-close it. (b29ea4e33486)
  • Default-on throttle in PR head: PR head adds a two-second per-session rate limit that is enabled by default outside Vitest and returns rate_limited before delivery. (src/shared/steer-message-injection-policy.ts:18, b29ea4e33486)
  • PR targets removed embedded path: PR head changes src/agents/pi-embedded-runner/runs.ts, but current main has no src/agents/pi-embedded-runner files and uses src/agents/embedded-agent-runner instead. (src/agents/pi-embedded-runner/runs.ts:71, b29ea4e33486)
  • Current main already has active/not-stopped admission: Current main's live embedded-agent runner already uses optional isStopped with isStreaming fallback for queue admission. (src/agents/embedded-agent-runner/runs.ts:339, 010b61746379)

Likely related people:

  • 100yenadmin: Authored the merged replacement PR that put active non-streaming steer admission on the current embedded-agent and reply-run paths. (role: merged replacement author; confidence: high; commits: 6912ef43f0f4, 8d9a7ab2cab6; files: src/agents/embedded-agent-runner/runs.ts, src/auto-reply/reply/agent-runner.ts, src/auto-reply/reply/reply-run-registry.ts)
  • obviyus: Merged the replacement PR and posted the landing/proof comment with the land and merge commits. (role: merger of replacement; confidence: high; commits: 6912ef43f0f4, 8d9a7ab2cab6; files: src/agents/embedded-agent-runner/runs.ts, src/auto-reply/reply/agent-runner.ts, src/auto-reply/reply/reply-run-registry.ts)
  • vincentkoc: Current git history shows repeated prior work in the reply runner and embedded steering area, and this protected branch is assigned to the same person. (role: recent area contributor; confidence: medium; commits: 2db10fb1d404, 3de42e946a2b, b29ea4e33486; files: src/auto-reply/reply/agent-runner.ts, src/agents/embedded-agent-runner/runs.ts, src/auto-reply/reply/reply-run-registry.ts)
  • Peter Steinberger: Recent path history shows repeated adjacent reply-runner, queue, and lifecycle changes in the same auto-reply surfaces before the replacement landed. (role: adjacent reply/queue area contributor; confidence: medium; commits: 1b69d9ee1a51, 9b7002ee5971, bb0bfabec85d; files: src/auto-reply/reply/agent-runner.ts, src/auto-reply/reply/reply-run-registry.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Jun 17, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Jun 17, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. mantis: telegram-visible-proof Mantis should capture Telegram visible proof. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 17, 2026
@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label Jun 20, 2026
@100yenadmin

Copy link
Copy Markdown
Contributor

@vincentkoc also just submitted this PR a few hours ago on this: #98126

@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. and removed mantis: telegram-visible-proof Mantis should capture Telegram visible proof. labels Jul 3, 2026
@steipete

steipete commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded by merged #98126 (8d9a7ab2cab6dd3151f90c655011cf48b236c5a5).

#98126 includes this active/non-stopped steer admission fix and adds the Telegram/Codex command-routing and active-run lookup needed for the reported user path. This older replacement branch no longer has a unique fix to land.

If a non-Telegram runtime still reproduces after #98126, please open a focused regression against current main. Thanks, @vincentkoc.

@steipete steipete closed this Jul 5, 2026
@shakkernerd
shakkernerd deleted the clownfish/ghcrawl-156681-autonomous-smoke branch October 19, 2026 23:14

This branch had an error being deployed

1 failed deployment
qa-live-shared — b29ea4e3 Deployed Jul 3, 2026 by clawsweeper[bot] via Run agentic native Telegram proof #271625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper Tracked by ClawSweeper automation maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M 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.

3 participants