Skip to content

feat: add fast-lane override for immediate response execution#57239

Closed
vasujain00 wants to merge 8 commits into
openclaw:mainfrom
vasujain00:feature/session-fast-lane-replies
Closed

feat: add fast-lane override for immediate response execution#57239
vasujain00 wants to merge 8 commits into
openclaw:mainfrom
vasujain00:feature/session-fast-lane-replies

Conversation

@vasujain00

Copy link
Copy Markdown

Summary

  • add a fast-lane path for short inbound messages when a session already has an active run
  • bypass followup queueing for eligible quick messages and execute them immediately using an isolated transient run context
  • keep existing queue behavior as default and gate fast-lane behavior behind strict message heuristics
  • add queue-policy support for explicit "run now while active" override and unit coverage

Why

Long-running turns currently block quick follow-up messages in the same session, which creates high perceived latency in fast chat channels (especially Discord). This change preserves the existing safe queue model for normal traffic while allowing low-risk, short messages to get timely responses during busy turns.

What changed

  • src/auto-reply/reply/get-reply-run.ts
    • detect fast-lane candidates (short, single-line, non-command quick phrases)
    • when a run is active and message would be queued, create a transient fast-lane run context
    • append a fast-lane system instruction to keep replies concise and avoid unnecessary tools
    • force immediate execution instead of enqueue-followup for these candidate messages
  • src/auto-reply/reply/agent-runner.ts
    • thread a forceRunNowWhenActive flag into queue-action selection
  • src/auto-reply/reply/queue-policy.ts
    • honor forceRunNowWhenActive by returning run-now even while active
  • src/auto-reply/reply/queue-policy.test.ts
    • add test coverage for the fast-lane override path

Behavior notes

  • default queue behavior remains unchanged for non-fast-lane messages
  • fast-lane only applies when all conditions are met:
    • active run exists
    • current queue mode would follow up
    • active run is not currently streaming
    • message matches quick-message heuristics and is not a control command

Verification

  • pnpm tsgo
  • lints on touched files via IDE diagnostics ✅
  • attempted targeted test:
    • pnpm test -- src/auto-reply/reply/queue-policy.test.ts
    • currently hangs in this local environment before case output (same in serial profile); process was stopped after no progress

Risk / follow-up

  • low-to-moderate: introduces a new execution path under active-session contention
  • follow-up recommended:
    • add integration tests around busy-session fast-lane behavior in get-reply-run / reply-flow
    • validate behavior in Discord channel smoke test (long turn + quick follow-up)

References

Closes #56880

- Introduced `forceRunNowWhenActive` parameter to enable immediate execution of replies when certain conditions are met.
- Implemented logic to determine fast-lane candidates based on message characteristics.
- Updated queue policy to respect the new fast-lane behavior.
- Added tests to verify the immediate run functionality when the fast-lane override is enabled.

@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: cba0777c03

ℹ️ 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 thread src/auto-reply/reply/get-reply-run.ts Outdated
Comment thread src/auto-reply/reply/get-reply-run.ts Outdated
@greptile-apps

greptile-apps Bot commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a fast-lane execution path that lets short, well-known messages (e.g. "yes", "no", "ok", "cancel") bypass the normal followup queue and respond immediately even while a long-running session turn is active. The mechanism creates a transient session context with a fresh session ID and appends a conciseness system prompt, then forces resolveActiveRunQueueAction to return "run-now" via a new forceRunNowWhenActive flag.

The intent is sound and the guard heuristics (FAST_LANE_QUICK_MESSAGE_PATTERN, streaming check, control-command exclusion) are conservative. However two correctness issues need attention before merge:

  • Followup queue drain race (get-reply-run.ts lines 607–634): The fast-lane run and the primary run share the same queueKey. When the fast-lane finishes it calls finalizeWithFollowupscheduleFollowupDrain, which can start draining messages that were safely queued for after the primary run completes — while the primary run is still live.
  • Heartbeat bypass ordering (queue-policy.ts lines 15–17): forceRunNowWhenActive is evaluated before the isHeartbeat → "drop" guard. In a "collect"-mode session a heartbeat that matches the quick-message pattern would escape the drop path and be executed immediately.

Two lower-priority observations:

  • Transient fastlane-<uuid>.jsonl transcript files accumulate on disk with no cleanup path.
  • "what time is it" in FAST_LANE_QUICK_MESSAGE_PATTERN appears to be a leftover test phrase.

Confidence Score: 3/5

Not safe to merge as-is: two P1 logic issues need to be resolved first.

The fast-lane queue drain race is a present concurrency defect on the changed path that can cause two concurrent embedded-agent runs against the same session key. The heartbeat ordering inversion in queue-policy.ts is a secondary but real logic error. Both P1 findings are in newly introduced code paths with no integration test coverage, consistent with the PR author's own risk acknowledgment.

src/auto-reply/reply/get-reply-run.ts (queue drain race, transient file cleanup) and src/auto-reply/reply/queue-policy.ts (heartbeat check ordering)

Important Files Changed

Filename Overview
src/auto-reply/reply/get-reply-run.ts Adds fast-lane detection and transient session construction; two P1-adjacent issues: shared queueKey on fast-lane completion can prematurely drain the followup queue while the main run is still active, and transient transcript files are never cleaned up.
src/auto-reply/reply/queue-policy.ts Adds forceRunNowWhenActive override; the new check is inserted before the isHeartbeat drop guard, allowing heartbeat messages that match the fast-lane pattern to bypass the intended drop behavior.
src/auto-reply/reply/agent-runner.ts Minimal change: threads forceRunNowWhenActive through the params interface and passes it to resolveActiveRunQueueAction. No logic changes in this file itself.
src/auto-reply/reply/queue-policy.test.ts Adds one unit test covering the forceRunNowWhenActive → run-now path; test is correct and well-structured.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/queue-policy.ts
Line: 15-17

Comment:
**Fast-lane bypass precedes heartbeat drop check**

`forceRunNowWhenActive` is checked before `isHeartbeat`, so a heartbeat message that qualifies as a fast-lane candidate (e.g. if its body happens to match `FAST_LANE_QUICK_MESSAGE_PATTERN`) would return `"run-now"` instead of `"drop"`. In `get-reply-run.ts` there is no `!isHeartbeat` guard on `shouldUseFastLane`, only a `shouldFollowup` guard — but `shouldFollowup` can be `true` in `"collect"` mode even for heartbeats, leaving the heartbeat drop path unreachable for any fast-lane candidate.

The `isHeartbeat``"drop"` branch is a safety valve for stale pings; bypassing it via `forceRunNowWhenActive` is unintended.

```suggestion
  if (!params.isActive) {
    return "run-now";
  }
  if (params.isHeartbeat) {
    return "drop";
  }
  if (params.forceRunNowWhenActive) {
    return "run-now";
  }
```

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/auto-reply/reply/get-reply-run.ts
Line: 607-634

Comment:
**Fast-lane completion can prematurely drain the shared followup queue**

When the fast-lane run completes it calls `finalizeWithFollowup(result, queueKey, runFollowupTurn)` using the same `queueKey` as the still-active main run. `finalizeWithFollowup``scheduleFollowupDrain` will start processing any items already enqueued under that key if the queue is not yet in a `draining` state — which it won't be, because the main run hasn't finished yet.

The result is that queued followup messages that were safely held until the main run completed can now be dispatched to the embedded runner while the main run is still live, creating two concurrent sessions on the same key.

A minimal mitigation would be to skip scheduling the drain when the caller knows the main run is still active, e.g. by passing `isRunActive` into `finalizeWithFollowup` for the fast-lane path, or by using a separate queue key for the transient run so its drain does not touch the primary lane.

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/auto-reply/reply/get-reply-run.ts
Line: 62-63

Comment:
**`"what time is it"` phrase seems out of place in the pattern**

The regex bundles generic conversational affirmations/cancellations (`yes`, `no`, `ok`, `cancel`, `stop`, etc.) with the oddly specific question `what time is it\??`. It appears to be a test phrase that was accidentally left in the production pattern. If intentional, a comment explaining why this one question warrants fast-lane treatment would help; if not, it should be removed.

```suggestion
const FAST_LANE_QUICK_MESSAGE_PATTERN =
  /^(?:yes|no|ok|okay|sure|thanks|thx|got it|cancel|stop|never mind|nevermind)$/i;
```

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/auto-reply/reply/get-reply-run.ts
Line: 614-619

Comment:
**Transient session transcript files are never cleaned up**

`transientSessionFile` resolves to a `fastlane-<uuid>-topic-<...>.jsonl` file in the sessions directory. There is no TTL, post-run cleanup, or sweep mechanism for these files. In high-traffic Discord channels where many short messages arrive during long turns, these orphaned transcript files will accumulate on disk indefinitely.

Consider deleting the transient transcript after the fast-lane run finishes (in a `finally` block), or marking it with a prefix/suffix that a periodic pruning job can target.

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

Reviews (1): Last reviewed commit: "feat: add fast-lane override for immedia..." | Re-trigger Greptile

Comment thread src/auto-reply/reply/queue-policy.ts Outdated
Comment thread src/auto-reply/reply/get-reply-run.ts
Comment thread src/auto-reply/reply/get-reply-run.ts Outdated
Comment thread src/auto-reply/reply/get-reply-run.ts
- Added file system cleanup for transient fast-lane session files after execution.
- Updated queue policy to ensure heartbeat conditions take precedence over fast-lane overrides.
- Modified the runPreparedReply function to handle session management more effectively during fast-lane execution.
- Added a test case to validate the new heartbeat precedence behavior.

@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: 1cf3a995d5

ℹ️ 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 thread src/auto-reply/reply/get-reply-run.ts
- Replaced single fast-lane session file variable with an array to handle multiple files for cleanup.
- Updated cleanup logic to iterate over the array of transient fast-lane files.
- Maintained session key for proper system-event routing during fast-lane execution.

@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: 33b7b7b0e1

ℹ️ 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 thread src/auto-reply/reply/get-reply-run.ts

@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: 33b7b7b0e1

ℹ️ 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 thread src/auto-reply/reply/get-reply-run.ts

@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: da8b1e8a99

ℹ️ 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 thread src/auto-reply/reply/get-reply-run.ts
- Introduced `sessionLaneKey` to `RunEmbeddedPiAgentParams` for optional command-lane key overrides.
- Updated `runEmbeddedPiAgent` to utilize `sessionLaneKey` for improved session lane resolution.
- Modified context building in `buildEmbeddedContextFromTemplate` to include `sessionLaneKey`.
- Enhanced `runPreparedReply` to isolate command-lane serialization using `sessionLaneKey` for better queue management.
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Mar 30, 2026
…reparedReply

- Added `fastMode` property to `FollowupRun` type for improved configuration options.
- Updated `runPreparedReply` to explicitly type `followupRun` as `FollowupRun` for better type safety.
@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.

Keep open: this is a useful implementation candidate for active-session reply latency, but current main has not implemented the requested fast-lane behavior, the linked design issue is still open, and this branch is conflicting with current reply-run contracts while lacking real behavior proof.

Canonical path: Close this PR as superseded by #85709.

So I’m closing this here and keeping the remaining discussion on #85709.

Review details

Best possible solution:

Close this PR as superseded by #85709.

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

Yes for the PR blockers: source inspection of the PR head against current main shows the removed reset contract, parent reply-operation key reuse, and sandbox key replacement. I did not run tests because this was a read-only review.

Is this the best way to solve the issue?

No. The fast-lane idea may be useful, but this implementation is not the narrow maintainable solution until it preserves current reply/session/runtime-policy contracts, enforces tool limits in code, and proves real active-session behavior.

Security review:

Security review needs attention: The diff introduces a parallel quick-turn path while changing sandbox/runtime-policy identity and relying on prompt-only tool suppression.

  • [medium] Sandbox identity replaced by scheduling identity — src/agents/pi-embedded-runner/run/params.ts:41
    The PR removes sandboxSessionKey from embedded-runner params and threads sessionLaneKey instead, but current main uses sandboxSessionKey for sandbox/tool-policy resolution and process tool scoping.
    Confidence: 0.9
  • [medium] Tool suppression is prompt-only — src/auto-reply/reply/get-reply-run.ts:1171
    The fast-lane system prompt asks the model not to call tools, but it does not set disableTools or a tool allowlist, so a concurrent quick turn can still receive normal tool access.
    Confidence: 0.84

What I checked:

  • linked superseding PR: fix(telegram): serialize topic dispatch replies #85709 (fix(telegram): serialize topic dispatch replies) is merged at 2026-05-24T10:49:49Z.
  • cluster evidence: the durable review links that PR in the work cluster or recommended risk path.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Current blame and merged PR history show Peter Steinberger authored the current queue policy, reply admission, reset handling, sandbox identity, and much of the recent reply-run contract this branch conflicts with. (role: recent area contributor and merger; confidence: high; commits: 2cd93f1c0d91, ddbbfda8269b, 60623c2212cf; files: src/auto-reply/reply/queue-policy.ts, src/auto-reply/reply/get-reply-run.ts, src/auto-reply/reply/agent-runner.ts)
  • jalehman: Josh Lehman authored the recently merged topic dispatch and reply-admission work that changed active reply-operation ownership, followup drains, and busy-session behavior near this PR's surface. (role: recent adjacent contributor; confidence: high; commits: 62b51a6295ee, c2ee1ee9c924; files: src/auto-reply/reply/get-reply-run.ts, src/auto-reply/reply/agent-runner.ts, src/auto-reply/reply/followup-runner.ts)

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

@openclaw-barnacle openclaw-barnacle Bot added size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed size: S labels May 18, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 18, 2026
@clawsweeper

clawsweeper Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@clawsweeper

clawsweeper Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Concurrent message handling per session (async agent turns)

2 participants