fix: contain authentication failures and reconnect resource use - #2393
Merged
Conversation
yuezengwu
marked this pull request as draft
September 10, 2026 11:57
yuezengwu
marked this pull request as ready for review
September 10, 2026 13:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A terminal authentication failure during daemon startup could exit the process and let the supervisor restart it, repeating refresh requests and WebSocket handshakes. Connections now pause until credentials recover. CLI recovery compares current credentials with the failed attempt, including a login saved before an old rejection arrives. Standalone
AgentRuntimeexposes a pause callback, pause status, andresumeAfterCredentialsChange()so its host can recover the same runtime; synchronous and asynchronous observer failures cannot interrupt cleanup.Successful registration is the single boundary for starting or resuming capability work. The CLI no longer derives readiness from welcome frames or separately reopens the gate after agent startup. Attempt credentials explicitly distinguish the transmitted access token from a pre-provider snapshot; snapshots ignore file formatting and unrelated fields. Existing
onReconnectconsumers remain supported.Refresh callers share identical credential snapshots, retain a bounded terminal-401 latch, and discard obsolete outcomes. Server WebSocket authentication runs one attempt per connection and ignores completions after close or timeout. Log rendering is separated from sink admission and loss accounting, preserving the 64 KiB record cap and 256 KiB destination queue cap. Only admitted normal records enter the trace bridge. The logging refactor is a separate commit for review and rollback.
Validation
pnpm checkandpnpm typecheckpassed for986b24334fbd7378594670931e1ce1a2277d5518.pnpm test --concurrency=1passed: 12,521 passed, 8 existing conditional skips. Source hashes remained unchanged through validation and match the committed files. Unchanged build/test tasks used content caches.Regression coverage includes initial handshake and token-provider rejection, explicit standalone recovery and terminal stop, synchronous/asynchronous host observer failures, early login recovery, unchanged and self-rotated rejected credentials, metadata-only credential writes, registration-gated capability work, obsolete refresh outcomes, duplicate auth frames, retired connection completions/timers, and failed/stalled logging sinks. Existing logging-bound assertions were preserved.
Scope and remaining acceptance
@types/ws@8.18.1only for loopback regression tests.ws-client-auth-frame-enforcementandauthenticated-ws-inbox-deliverymatch the affected release boundary; case disposition: no-change. Deployment, owner login, real registration, and business WebSocket delivery remain release acceptance work.