Skip to content

fix(slm): REST calls authenticate like the WebSocket; handshake timeouts take the reconnect backoff (#20943, #20938) - #21054

Closed
mrveiss wants to merge 5 commits into
mainfrom
issue-20943-slm-client-auth-ws
Closed

mrveiss wants to merge 5 commits into
mainfrom
issue-20943-slm-client-auth-ws

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Thinking Path

The SLM client authenticated its WebSocket but not its REST calls, and a WebSocket handshake timeout skipped the reconnect backoff. Both are fixed in the client itself, using the credential path that already exists.

What Changed

  • The REST session uses SLMClient._resolve_auth_token(): the static token, else a service JWT minted through the existing _mint_service_jwt and the SSOT secret. It is re-resolved on every session use. No new credential path or env var.
  • The WebSocket handshake TimeoutError and other OSErrors go to _on_ws_failure: a WARNING, then the existing backoff pinned at _max_reconnect_delay. ssl.SSLError deliberately stays at ERROR as a configuration fault.
  • slm_client.py stays at its 979-line pin.

Verification

  • 6 + 4 new tests; 53 + 38 passed locally. CI is authoritative.
  • Host behaviour is not yet verified on a host, hence "Refs" and no Closes.

Risks

A token re-resolved per session use costs one lookup per use; no credential is stored in a new place.

Model Used

Claude Sonnet 5.5 (claude-sonnet-5-5)

Issue Link

Refs #20943
Refs #20938

Changelog fragment

  • N/A (internal change)

Checklist

  • Code follows AutoBot patterns from CLAUDE.md
  • Tests added or updated
  • Documentation updated if behavior changed (N/A)
  • PR targets main (not release)
  • No secrets or credentials in the diff

Single-issue rationale

Both issues are the same client file and the same connection path, so one change covers them.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@mrveiss mrveiss added bug Something isn't working priority: medium backend phase:M1.4 Wizard and SLM: choose a mode, apply it, default models work labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at 1d05dc2

Verdict: APPROVE

Branch is 0 behind main. 3 changed files (limit 100). No unresolved review threads. No fixed sleeps (the backoff test patches asyncio.sleep and records the delays), and no new line-number comments. slm_client.py stays at its 979-line pin (net 0 lines), which is a frozen exception rather than a new breach.

# Severity Where Finding Fix
1 LOW _get_session REST auth covers every path: _fetch_all_agents, the agent fetch at the second _get_session call site, the deployments mixin (slm_deployments.py calls _get_session) and the module-level discovery helper all go through the one method, and no other ClientSession in the SLM client path bypasses it. When there is neither a static token nor a signing secret, REST sends no Authorization and logs nothing (the WebSocket path logs a WARNING). This is an unauthenticated fallback by design, pinned by test_no_token_and_no_secret_sends_no_authorization. Log one WARNING for the no-credential REST case so the 401 is explained. Not blocking.
2 LOW _get_session The bearer is written onto the shared session's default headers on every call. Safe today because there is no await between the pop and the set, but per-request headers would not depend on that. Optional: pass the header per request.
3 LOW _ws_connect_and_listen The handshake timeout is not env-backed: no open_timeout is passed, so the websockets library default applies. #20938 does not require a knob, so this is not an AC miss. On timeout the async with unwinds with nothing to clean up, then _on_ws_failure counts it, logs a WARNING and applies the existing backoff. After 3 consecutive failures the delay is pinned at the maximum, so a short startup outage can delay reconnect by that maximum. There is no user-visible error, only the log. Optional follow-up: an env-backed handshake timeout constant.
4 LOW _ws_connect_and_listen The function is still about 87 lines (97 on main), over the 30-line rule, but this PR shortens it and the long-function debt predates it. Decompose in a later PR (#560).

Checks that passed:

  • Token handling: the token comes from _resolve_auth_token (static token, else _mint_service_jwt over _get_slm_signing_secret, which reads the SSOT config). There is no new credential path or env var. The token is never logged; the test asserts neither the secret nor the bearer appears in captured logs.
  • Handshake TimeoutError and other OSErrors are routed to _on_ws_failure; ssl.SSLError stays at ERROR; any other exception stays at ERROR and is not counted.
  • Tests: 6 auth tests, including a control showing the stand-in server returns 401 without a credential, and 4 timeout tests including the pinned-delay sequence 1.0, 2.0, max.

#20943 ACs, all met in the diff and tests:

  • REST uses the WebSocket's token resolution, re-minted on every session use.
  • _fetch_all_agents succeeds against an auth-requiring server with no static token.
  • The no-static-token test exists.

#20938 ACs, all met:

  • TimeoutError and OSError go through failure accounting, with one WARNING and then the pinned delay.
  • Only unexpected exceptions stay at ERROR.
  • A timeout test asserts counter == 1 and no ERROR.

The Refs (not Closes) in the PR body is right: host behaviour is not verified yet.

Threads: none open, so nothing to resolve.

@mrveiss

mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Landed via merge train #21184, merge commit 209d547 (frozen head 08f7953 is an ancestor of it).

@mrveiss mrveiss closed this Nov 8, 2026
timothybrush pushed a commit to timothybrush/AutoBot-AI that referenced this pull request Nov 9, 2026
@mrveiss mrveiss reopened this Nov 18, 2026
@mrveiss

mrveiss commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Branch audit (zero-change deletion). This PR shows 0 changed files against main (head 5ee5f4be62): every change it carried is already in main. Closing and deleting the branch through this PR; it can be restored with the Restore branch button below.

@mrveiss mrveiss closed this Nov 18, 2026
@mrveiss
mrveiss deleted the issue-20943-slm-client-auth-ws branch November 18, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working phase:M1.4 Wizard and SLM: choose a mode, apply it, default models work priority: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant