Skip to content

fix: use isActive+isStopped instead of isStreaming for steer message injection - #65010

Closed
jetd1 wants to merge 28 commits into
openclaw:mainfrom
jetd1:fix/steer-isactive-gate-clean
Closed

jetd1 wants to merge 28 commits into
openclaw:mainfrom
jetd1:fix/steer-isactive-gate-clean

Conversation

@jetd1

@jetd1 jetd1 commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The isStreaming() guard in queueEmbeddedPiMessage and queueReplyRunMessage is too restrictive — it blocks steer/interrupt messages during tool execution (when isStreaming is false but the agent loop is still running). This prevents legitimate message delivery in steer and interrupt queue modes.

Upstream PRs #52351 and #60604 address related issues but neither has been merged.

Root Cause

isStreaming only reflects whether the LLM is actively streaming tokens. During tool execution, isStreaming is false but the agent loop is still running and can drain steering messages between tool calls. The guard incorrectly rejects steer messages in this window.

Fix

Replace isStreaming() with a precise agent-loop lifecycle check via isStopped():

  • isStopped() returns true when the agent loop is NOT actively running — either before the first prompt starts (startup window) or after the prompt finishes (teardown window).
  • agentLoopStarted flag set immediately before activeSession.prompt() — after all pre-prompt work (image loading, hooks, overflow prechecks).
  • agentLoopStopped flag set in the prompt finally block.
  • isStopped = !started || stopped — guards both startup and teardown windows while allowing steer during the full active agent loop (streaming + tool execution).

In agent-runner.ts, the steer guard changes from shouldSteer && isStreaming to shouldSteer && isActive. The now-dead isStreaming param is removed from runReplyAgent, along with its unused destructure in runPreparedReply that was triggering an oxlint CI failure.

Changes

File Change
runs.ts Add isStopped? to EmbeddedPiQueueHandle; add isStopped guard in queueEmbeddedPiMessage
attempt.ts Add agentLoopStarted/agentLoopStopped flags; expose isStopped() on queue handle
agent-runner.ts Change steer guard from isStreaming to isActive; remove dead isStreaming param
reply-run-registry.ts Add isStopped?() to ReplyBackendHandle; use isStopped in queueReplyRunMessage
get-reply-run.ts Remove dead isStreaming destructure (oxlint fix)
runs.test.ts 6 test cases covering all steer acceptance/rejection states
agent-runner.steer-guard.test.ts 3 test cases for the isActive steer guard
Test call-site cleanup Drop isStreaming: params from 4 existing tests

Testing

  • Targeted tests pass: runs.test.ts (14), agent-runner.steer-guard.test.ts (3), get-reply-run-queue.test.ts (3)
  • oxlint clean (previously failed with unused isStreaming variable)
  • Import cycle / type checks pass
  • Lightly tested with live Telegram interrupt workflow

AI Disclosure

  • AI-assisted (OpenClaw agent + Codex review)
  • Author understands all changes

Fixes #48003

Related

Part of a 3-PR fix set for interrupt/steer message delivery:

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Apr 11, 2026
@greptile-apps

greptile-apps Bot commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a correctness bug where steer/interrupt messages were blocked during tool execution because the guard used isStreaming() (false during tool calls) instead of a proper agent-loop lifecycle check. The fix introduces agentLoopStarted/agentLoopStopped flags in attempt.ts to expose an isStopped() predicate on the queue handle, and switches the agent-runner.ts steer guard from isStreaming to isActive.

The isStreaming parameter of runReplyAgent is now dead code — it remains in the function signature (renamed to _isStreaming) but has no effect on steer behavior. Callers passing this value will silently have it ignored, which could mislead future maintainers.

Confidence Score: 5/5

Safe to merge — the fix is logically sound, well-tested, and the only remaining finding is a dead-parameter style concern.

All P0/P1 issues are absent. The core lifecycle flag logic is correct for single-attempt runs (new flags are scoped per runEmbeddedAttempt invocation), the optional isStopped preserves backward compatibility, and 9 new tests cover the key states. The sole finding is a P2 dead-code concern on the isStreaming parameter.

src/auto-reply/reply/agent-runner.ts — the isStreaming parameter is now unused; worth annotating or removing in a follow-up.

Comments Outside Diff (1)

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

    P2 isStreaming parameter is now dead code

    isStreaming is destructured as _isStreaming and never referenced again in the function body. All callers still pass it, which could lead future maintainers to believe this value influences steer gating. Consider adding a @deprecated JSDoc comment on the parameter or removing it in a follow-up to avoid silent API confusion.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/auto-reply/reply/agent-runner.ts
    Line: 115
    
    Comment:
    **`isStreaming` parameter is now dead code**
    
    `isStreaming` is destructured as `_isStreaming` and never referenced again in the function body. All callers still pass it, which could lead future maintainers to believe this value influences steer gating. Consider adding a `@deprecated` JSDoc comment on the parameter or removing it in a follow-up to avoid silent API confusion.
    
    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: 115

Comment:
**`isStreaming` parameter is now dead code**

`isStreaming` is destructured as `_isStreaming` and never referenced again in the function body. All callers still pass it, which could lead future maintainers to believe this value influences steer gating. Consider adding a `@deprecated` JSDoc comment on the parameter or removing it in a follow-up to avoid silent API confusion.

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

Reviews (1): Last reviewed commit: "fix: use isActive instead of isStreaming..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adb0f588b3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@jetd1
jetd1 force-pushed the fix/steer-isactive-gate-clean branch from adb0f58 to a9a1806 Compare April 12, 2026 07:56
@jetd1

jetd1 commented Apr 12, 2026

Copy link
Copy Markdown
Contributor Author

Ready for review — requesting @tyler6204 and @joshavant for a look when convenient. This is a small, independent fix (1 commit, 5 files) with clean CI on checks-node-auto-reply.

@jetd1
jetd1 force-pushed the fix/steer-isactive-gate-clean branch 2 times, most recently from 42285b0 to 3198898 Compare April 18, 2026 08:48
@jetd1 jetd1 changed the title fix: use isActive instead of isStreaming for steer message injection fix: use isActive+isStopped instead of isStreaming for steer message injection Apr 18, 2026
obviyus and others added 6 commits April 21, 2026 16:39
…dit (openclaw#69581)

* fix(codex): exclude codex-app-server synthetic apiKey from secrets audit

The Codex extension uses the literal string "codex-app-server" as a
hardcoded placeholder apiKey in provider.ts, since the real
authentication is managed by the app-server transport itself.

The secrets audit currently reports this as a real plaintext leak
(PLAINTEXT_FOUND), producing a false positive for any user who has
configured the Codex harness.

Declare it as a plugin-owned non-secret marker in the Codex plugin
manifest, so it flows through the standard
`listKnownNonSecretApiKeyMarkers()` path alongside `ollama-local`,
`lmstudio-local`, `gcp-vertex-credentials`, and `minimax-oauth`.

Also extends the existing `model auth markers` unit tests to lock
in the behavior.

Fixes openclaw#69511

* ci: retrigger checks (no-op)

(cherry picked from commit 081da17)
openclaw#69338)

When ingestDelta returns null (first empty/commentary delta or unchanged
content), the handler returned early, skipping setActivityStatus and
armStreamingWatchdog. If all subsequent deltas were also null (e.g.
due to phase filtering), the watchdog was never armed and the status bar
stayed stale as "idle" while a run was live.

Move setActivityStatus("streaming") and armStreamingWatchdog before
the null-displayText guard so they fire on every received delta event.

Fixes openclaw#34513, openclaw#40824

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
(cherry picked from commit 89b6d02)
@jetd1
jetd1 force-pushed the fix/steer-isactive-gate-clean branch from 3198898 to c7a7df5 Compare April 22, 2026 15:43
…injection

Replace the overly restrictive isStreaming() guard in
queueEmbeddedPiMessage and queueReplyRunMessage with a precise
agent-loop lifecycle check. The old guard blocked steer messages
during tool execution (when isStreaming is false but the agent loop
is still running), preventing legitimate steer/interrupt delivery.

- Add isStopped() method to EmbeddedPiQueueHandle that returns true
  when the agent loop is not actively running (before first prompt or
  after prompt end). During these windows the steering queue is not
  drained, so messages would be silently dropped.
- In attempt.ts, track agentLoopStarted (set immediately before
  activeSession.prompt()) and agentLoopStopped (set in the prompt
  finally block). isStopped = !started || stopped.
- queueEmbeddedPiMessage and queueReplyRunMessage now check isStopped()
  instead of isStreaming(), correctly allowing steer during tool
  execution while rejecting during startup and teardown windows.
- In agent-runner.ts, the steer guard uses isActive (run handle exists)
  instead of isStreaming, matching the broader acceptance window.
- Add isStopped?() to ReplyBackendHandle interface.
- Remove the now-dead isStreaming param from runReplyAgent and its
  destructuring in runPreparedReply.
- 6 new/updated tests covering: not-streaming+running (tool exec),
  stopped (teardown), not-yet-started (startup), compacting, and
  streaming cases.

Fixes openclaw#48003

Co-Authored-By: Cha <[email protected]> via OpenClaw
@jetd1
jetd1 force-pushed the fix/steer-isactive-gate-clean branch from c7a7df5 to 9a3254d Compare April 22, 2026 17:26
@jetd1
jetd1 requested review from a team as code owners April 22, 2026 17:26
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord gateway Gateway runtime cli CLI command changes scripts Repository scripts docker Docker and sandbox tooling extensions: qa-lab extensions: codex size: L and removed size: M labels Apr 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a3254dddf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +121 to +123
if (handle.isStopped?.()) {
diag.debug(`queue message failed: sessionId=${sessionId} reason=agent_stopped`);
return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore streaming guard when stop state is unavailable

queueEmbeddedPiMessage now treats handles without isStopped as injectable, which affects existing embedded backends such as Codex app-server (extensions/codex/src/app-server/run-attempt.ts:216-229). Fresh evidence: that backend marks completed = true on turn/completed before it unregisters the handle (extensions/codex/src/app-server/run-attempt.ts:153-155 vs :275), creating a teardown window where this function returns true even though the run is already finished. In steer mode, runReplyAgent then exits early as if delivery succeeded, but turn/steer can reject against the completed turn and the message is silently lost instead of falling back to follow-up queueing.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as duplicate_or_superseded. Current main still has the old isStreaming-based gates, so this is not implemented on main yet; however, #73365 is an open maintainer replacement that explicitly carries forward this PR’s core fix, credits the contributors, addresses the Codex P1 compatibility finding, and removes the unrelated branch churn.

Best possible solution:

Close this PR in favor of #73365 as the canonical replacement, then review and land that narrower maintainer PR for the active non-streaming steer fix. Keep #65221 and #65222 as separate follow-up work for interrupt scheduling and Telegram delivery behavior.

What I checked:

  • Current main still has old embedded steer gate: On checked-out main, queueEmbeddedPiMessage still rejects when handle.isStreaming() is false, so active non-streaming tool execution remains blocked on this branch of main. (src/agents/pi-embedded-runner/runs.ts:70, 16906780fd2c)
  • Current main still has old reply-agent steer gate: runReplyAgent still gates steer injection on shouldSteer && isStreaming rather than isActive. (src/auto-reply/reply/agent-runner.ts:930, 16906780fd2c)
  • Current main still has old reply-run registry gate: queueReplyRunMessage still requires backend.isStreaming(), so the reply-run path has the same active-but-not-streaming rejection. (src/auto-reply/reply/reply-run-registry.ts:466, 16906780fd2c)
  • Canonical replacement PR exists: fix: allow steer messages during active non-streaming runs #73365 is open, authored by a repo member, labeled maintainer/merge-ready, and its body says it is a clean replacement carrying forward @jetd1’s this PR fix direction while preserving the conservative streaming fallback for handles without isStopped and avoiding unrelated churn. (92baa73c006c)
  • This PR has unresolved compatibility review and broad unrelated scope: The review thread includes a P1 finding that handles without isStopped, such as Codex app-server, would become injectable in a teardown window. The PR also changes 48 files, including postinstall, release-check, E2E install smoke scripts, generated baselines, Discord, QA, media, infra, and TUI files outside the stated steer gate fix. (src/agents/pi-embedded-runner/runs.ts:123, 9a3254dddfcf)

So I’m closing this here and keeping the remaining discussion on the canonical linked item.

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

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

Labels

agents Agent runtime and tooling channel: discord Channel integration: discord cli CLI command changes docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: codex extensions: qa-lab gateway Gateway runtime scripts Repository scripts size: L triage: dirty-candidate Candidate: broad unrelated surfaces; may need splitting or cleanup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Steer mode does not inject messages mid-turn for main sessions

6 participants