Skip to content

fix: answer /login cancel during chat sign-in on channels without command source - #175345

Closed
masatohoshino wants to merge 8 commits into
openclaw:mainfrom
masatohoshino:fix/login-adopt-ingress
Closed

masatohoshino wants to merge 8 commits into
openclaw:mainfrom
masatohoshino:fix/login-adopt-ingress

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #175344

What Problem This Solves

Fixes: /login cancel goes unanswered until the chat sign-in is dropped, about 5 minutes after /login (4 minutes after the cancel in the run below), when an owner starts /login github-copilot (or another device sign-in) on a channel that does not mark typed commands, such as IRC, Signal, LINE, Feishu, MS Teams or Nextcloud Talk.

User Impact

User impact: during a chat sign-in on these channels, /login cancel answers within a second, as the sign-in prompt promises, and the sign-in no longer stalls the sender's channel lane.

On these channels, every authorized typed active-run-safe command now runs beside an active turn, as it already does on channels that mark commands (Discord, Mattermost, Matrix, iMessage, Tlon, SMS). That set includes the state-changing /new, /reset and /stop, not only /status and /help. Unauthorized senders, ordinary messages, and typed commands on a surface with commands.text: false still wait in order.

Why This Change Was Made

The cancel was held back in two places, and both are needed for it to get through:

  • Ingress adoption. The channel /login turn waits for the provider inside the turn without marking its durable ingress claim adopted. The claim keeps the sender's ingress lane until the 5-minute adoption watchdog releases it for retry. runChannelProviderLogin now adopts after the authorization check and before the provider flow, the same way /compact does. The flow still rechecks current authority first. Once the claim is adopted, a Gateway restart during the sign-in does not replay /login; the user sends it again.
  • Reply admission. Reply admission (it picks the command_resolution phase, which may run beside the active turn) and the foreground reply FIFO let an active-run-safe command pass only when it is a native or text-slash turn. A channel that passes command authorization without setting CommandSource yields a normal turn, so the cancel queued behind the sign-in. The two checks now resolve the turn with resolveExplicitCommandTurnContext, which treats an authorized control command from an unmarked channel as an authorized text-slash turn. It reuses the existing isExplicitCommandTurnContext fallback that the first check already used as its outer gate, and promotes only where shouldHandleTextCommands accepts typed commands for the turn's surface.

Design note: the turn resolution owns this decision, so isActiveRunSafeCommandTurn and its unit contract stay unchanged, and no /login cancel-only branch is added to the callers. Marking commands in each channel would also work, but it touches every unmarked channel plugin.

Evidence

Tested at 4f132e1b82c, which merges upstream/main 287b38a78d2 into this branch. Before and After both ran on 2026-10-23 with Node 24.22.1.

Re-run on 2026-10-30 at 42f4fd443e9, which merges upstream/main 885e57e9f9d: the After run below, rebuilt with the same setup, gave the same result. The prompt and code arrived at +79.4 s, /login cancel (sent at +135.0 s) got Provider login cancelled for this chat. at +136.8 s on a host under heavy load, the sign-in turn ended right after (totalMs=59419), and the 720 s run logged no claim→adoption stalled and no stuck session line. The Before run was not repeated: the merge conflicts were only in test files, and the four production changes merged without conflict.

Built CLI, openclaw gateway run with an isolated state directory and no outside network. The real IRC channel plugin connects to a loopback IRC server. A local stand-in for the GitHub device-code endpoints hands out a code and never approves it. The owner sends /login github-copilot (owner joins at +75 s), then /login cancel 60 s later.

Before (upstream/main 287b38a78d2):

+75.0s >> PRIVMSG ocbot :/login github-copilot
+76.0s << ... :Sign in with Copilot. Return here after approving access. Send /login cancel to cancel. https://github.com/login/device
+76.0s << ... :Authorize GitHub Copilot  ... Code: FAKE-0409 Code expires in 15 minutes. ...
+135.0s >> PRIVMSG ocbot :/login cancel
+376.9s << ... :No provider login is active in this chat.

[diagnostic] stuck session: … sessionKey=agent:main:main state=processing age=130s … recovery=controller_owned
[irc] Channel ingress claim→adoption stalled for event local:…:000000000001 on lane direct:owner after 300001ms; applying retry policy (handler-timeout).

The cancel ran only after the stall watchdog ended the sign-in turn (totalMs=299546), so it found no sign-in to cancel.

After (this PR):

+75.0s >> PRIVMSG ocbot :/login github-copilot
+76.1s << ... :Sign in with Copilot. Return here after approving access. Send /login cancel to cancel. https://github.com/login/device
+76.1s << ... :Authorize GitHub Copilot  ... Code: FAKE-0645 Code expires in 15 minutes. ...
+135.0s >> PRIVMSG ocbot :/login cancel
+135.2s << ... :Provider login cancelled for this chat.
+135.2s << ... :Copilot login did not complete. Send `/login github-copilot/github-copilot` to try again.

Observed result: the cancel answers in 0.2 s, and the sign-in turn ends right after it (totalMs=59673). The 720 s run logs no claim→adoption stalled and no stuck session line. The After run used 26b392b3789; the later amend to 4f132e1b82c changed only a test file, and so does 3a5b9ce67e0.

In the first run of this PR (base 19c5e58c2e8), the same run with only the adoption fix still waited reply.wait_admission_ticket:434111ms for the cancel. Both fixes are needed.

Checks at 4f132e1b82c, repeated at 3a5b9ce67e0 for the one test file it changes (that file, oxlint, oxfmt, tsgo on every src test shard and the ratchet): the touched tests and the other auto-reply and channel-turn tests that import the four changed production files (21 files), type-aware oxlint (scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json, as CI runs it) and oxfmt --check on the changed files, tsgo on the core project and every src test shard, and check-test-timeout-race-ratchet (baseline unchanged). One of the 21 files, route-reply.delivery-result.test.ts > preserves session writer authority through route normalization, fails the same way on upstream/main 287b38a78d2 without this change. These ran through the repo scripts directly.

Each changed test file, timed with node scripts/test-projects.mts <file> --maxWorkers=1 (what pnpm test runs) and a warm transform cache:

Test file --maxWorkers=1 wall CI seconds
src/auto-reply/reply/commands-login.ingress.test.ts 24.7 s (test 0.4 s) 0.62 s of test time in src/auto-reply/reply/commands-login.ingress.test.ts (1 file, Vitest 11.43 s), CI run 39865252560
src/auto-reply/command-turn-context.test.ts 5.9 s (new cases < 1 ms) 0.004 s of test time in src/auto-reply/command-turn-context.test.ts (1 file, Vitest 4.13 s), CI run 39865252560
src/auto-reply/reply/dispatch-from-config.active-command.test.ts 8.9 s (new case 0.10 s) 2.02 s of test time in src/auto-reply/reply/dispatch-from-config.active-command.test.ts (1 file, Vitest 6.62 s), CI run 39865252560
src/auto-reply/dispatch.delivery-order.test.ts 7.8 s (new cases < 10 ms) 0.056 s of test time in src/auto-reply/dispatch.delivery-order.test.ts (1 file, Vitest 4.66 s), CI run 39865252560

The CI seconds come from the CI run on the pre-merge head 3a5b9ce67e0, where each file ran as its own shard in the changed-test jobs. At 42f4fd443e9 the four files pass again: 1, 12, 13 and 12 tests. Their wall times on a loaded host were 17.7 s, 15.1 s, 29.8 s and 22.1 s.

The merge follows two main changes. The reply admission ticket is gone (#175837, #176447), so the admission case moved from dispatch-from-config.acp-abort.test.ts to dispatch-from-config.active-command.test.ts, next to main's /login cancel admission cases. Main also rewrote the same-session /status fence test, which now covers the marked command, so this PR keeps only its unmarked rows.

The merge of 885e57e9f9d had two conflicts, both in test files. In dispatch.delivery-order.test.ts, main added a queued row to the fence-retention case next to this PR's unmarked /status rows; both are kept. In vitest.database-worker-core-paths.mjs, main added dispatch-from-config.reply-dispatch-scope.test.ts beside this PR's commands-login.ingress.test.ts entry; both entries are kept. At 42f4fd443e9, the 21 related test files plus main's reply-dispatch-scope test (22 files, 305 tests) all pass, including the route-reply.delivery-result.test.ts case that failed on 287b38a78d2. tsgo passes on the core project and on every src test shard. Type-aware oxlint and oxfmt --check pass on the changed files.

Tests (before/after run of 42f4fd443e9 against 885e57e9f9d: 6 fail on the base and pass here, 32 guard tests pass on both; no added test uses a wall-clock race):

  • commands-login.ingress.test.ts (new): drives the real channel ingress drain and its SQLite queue into handleLoginCommand on a fake clock. It fails on the base because the stall watchdog releases the /login claim (expected "release" to not be called at all).
  • dispatch-from-config.active-command.test.ts: with a turn active on the session, an authorized unmarked IRC /login cancel reaches its reply resolver and gets its reply while that turn stays active. The case waits on a deferred the resolver settles, within the test signal. On the base, the command waits behind the active turn, so the resolver is never reached and the case runs into the test timeout.
  • dispatch.delivery-order.test.ts: the same-session /status fence case runs for an unmarked command and for an unmarked command with commands.text: false. The older turn is released when /status sends its final. The unmarked case fails on the base (expected [ 'old', 'status' ] to deeply equal [ 'status', 'old' ]); the disabled-text case expects ['old', 'status'].
  • command-turn-context.test.ts: the resolver promotes an authorized unmarked control command, keeps an unauthorized one a normal turn, and leaves a marked turn unchanged.

Simplification pass: production +38/−4 in 4 files, tests +238/−3 in 4 files, plus one Vitest database-worker list entry. The admission fix is one resolver plus two one-line call changes. A /login cancel-only branch at both callers was dropped for it. Main's reply admission has a third active-run-safe check (dispatch-from-config.lifecycle.ts); the run above shows the cancel already gets through without changing it, so it is left alone. command_resolution admission returns ready while another turn holds the mailbox (allowActiveResolution), so the third check is not reached for this turn.

Not covered:

  • Ordinary messages (hello) sent during the sign-in still wait until the sign-in turn ends or is cancelled. This is the existing order for normal turns. In the run above, hello reached the agent but could not answer, since no model was reachable.
  • Ordinary turns that queue behind a sign-in that is neither approved nor cancelled keep waiting behind it. Detaching the wait from the turn, as the Telegram native login does, is a separate change.
  • On unmarked channels (IRC, Signal, LINE, Feishu, MS Teams, Nextcloud Talk and others), all authorized active-run-safe commands now run beside an active turn, including the state-changing /new, /reset and /stop. This is intended: it matches channels that mark commands.
  • Having each channel pass command facts to the shared inbound builder would retire the fallback, and is left for a separate change.

Adopt channel ingress before the provider sign-in wait, as manual
compaction does. The device-code wait can outlive the claim-to-adoption
stall watchdog; adopting first frees the lane so `/login cancel` and
other messages get through, and the claim cannot be retried into a
second sign-in.
… channels

Channels such as IRC and Slack pass command authorization without marking
the command source, so their command turns resolve as normal turns. The
admission ticket and the foreground reply FIFO only skip native or
text-slash turns, so a typed `/login cancel` (or `/status`) waited behind
the running sign-in turn.

Resolve the turn for both checks through the existing fallback that
already treats an authorized control-command body as an explicit command
turn. Unauthorized senders and ordinary messages still wait in order.
@clawsweeper

clawsweeper Bot commented Oct 17, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adopt login ingress before device sign-in waits and recognize authorized typed control commands on channels without command-source metadata.

Example: An IRC owner sends /login github-copilot, then /login cancel while approval is pending.

  • Before: Cancellation waits behind sign-in until the watchdog interrupts it, then reports no active login.
  • After: Cancellation receives a prompt acknowledgement and ends the pending sign-in.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, useful fix with shipped-entry-point before/after evidence, distinct regression coverage, and no actionable correctness or security findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied Linux built-CLI Gateway run exercises the real IRC plugin against loopback IRC and synthetic device-code endpoints: an owner starts Copilot sign-in, cancels while approval is pending, receives the cancellation acknowledgement, and the login turn ends without watchdog recovery; the PR records this again at the reviewed head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An owner follows the sign-in prompt's /login cancel instruction but receives no acknowledgement until the pending sign-in is interrupted.
Reason: Responsive cancellation restores an existing promised interaction using existing owners and contracts, without adding configuration or a parallel login mechanism.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a current login-cancellation bug with relevant runtime evidence and no actionable findings; current-head CI remains in progress.

Priority: P2
Reviewed head: 42f4fd443e98a884136a77201710f067ff1ce07f

Before merge

None.

Findings

None.

Agent review details

How this fits together

Channel ingress feeds authorized messages into shared command admission and buffered reply delivery; provider login waits asynchronously while cancellation must reach the same chat's flow.

flowchart LR
  A[Channel message] --> B[Durable ingress]
  B --> C[Command turn resolution]
  C --> D[Session admission]
  D --> E[Login flow owner]
  E --> F[Buffered reply delivery]
  F --> G[Channel acknowledgement]
Loading

Technical review

Best possible solution:

Use the existing ingress-adoption lifecycle and shared command resolver to make cancellation responsive without changing ordinary-message ordering.

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

Current-main source retains both reported waits, and the contributor supplies a concrete built-Gateway IRC reproduction; no target code or tests were executed during this read-only review.

Is this the best way to solve the issue?

The patch fixes both owning boundaries with one shared resolver and the existing adoption operation, preserving command policy, authorization, and text-command settings.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against cd8290c2f6a9.

Provenance checked

  • Channel login lifecycle changes intended behavior with a stated reason (b342541: The shared provider flow separates credential connection from model activation and waits for the login outcome before reporting completion.)
  • Active-run-safe command admission keeps the original intent (f7756fe: Allow registry-approved commands to resolve during active runs while executable commands and replies without command provenance remain serialized.)
  • Foreground command reply fencing keeps the original intent (e5c1751: Already-authorized active-run-safe commands must deliver without waiting behind the active foreground turn.)
  • Unmarked command detection keeps the original intent (2899560: Derive explicit authorized control-command intent centrally so channels need not repeat source-tagging logic.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +34, Tests +236. Total +270 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 38 4 +34
Tests 5 239 3 +236
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 277 7 +270

Review metrics

Metric Value Why it matters
Production versus regression-test growth Production +38/-4; tests +238/-3 The added coverage addresses distinct ingress-watchdog, admission, authorization, disabled-text, and delivery-order boundaries while reusing existing fixtures.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The bug delays cancellation during device sign-in on unmarked-command channels, with limited scope and a focused repair.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-17T08:50:41.022Z sha c6a9d2b :: needs changes before merge. :: [P2] Honor disabled text commands before promoting an unmarked turn | [P2] Replace both added timeout races with owned completion signals
  • reviewed 2026-10-17T10:26:01.225Z sha ad9e959 :: needs changes before merge. :: none
  • reviewed 2026-10-17T15:09:18.972Z sha e837e8f :: needs maintainer review before merge. :: none
  • reviewed 2026-10-22T22:04:25.063Z sha 4f132e1 :: needs changes before merge. :: [P3] Replace real-time polling with an owned completion signal
  • reviewed 2026-10-23T03:44:00.997Z sha 3a5b9ce :: needs maintainer review before merge. :: none

Reviewed October 30, 2026, 2:09 PM ET / 18:09 UTC (Revision 6).

The unmarked-turn fallback promoted an authorized typed control command
even on a surface that does not handle text commands (`commands.text:
false` on a native-command channel), so a literal `/status` skipped the
admission ticket and the foreground FIFO. Gate the promotion with
`shouldHandleTextCommands` for the turn's surface.

The admission and FIFO tests now observe the owner signals (the
inherited admission ticket's wait, the delivery order behind the earlier
turn) instead of 200 ms timeout races, and cover the disabled-text case.
@masatohoshino

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 17, 2026
The type-aware lint rule prefer-promise-reject-errors flags rejecting
with the untyped abort reason. Reject with an Error, as the sibling
commands-login test does.
Resolve the conflict in src/auto-reply/dispatch.delivery-order.test.ts by
porting the marked, unmarked and disabled-text /status ordering cases to
the reworked helpers (mockReplies, pause, sendFinal, finals).

The upstream rewrite of command-turn-context.test.ts dropped the shared
emptyConfig constant; the resolver cases now pass {} inline as the rest
of that file does.
@masatohoshino

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 17, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 22, 2026
… case

The admission case polled the dispatcher with vi.waitFor. Resolve a deferred
from the reply resolver instead and wait on it within the test signal, as the
neighboring /steer case does.
@masatohoshino

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@masatohoshino

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

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

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant