Skip to content

[Amber] Long running sessions have ServiceAccount tokens expire #445

Closed

Description

@bobbravo2

Issue Description

Fix WebSocket Reconnection Errors for Long-Running Sessions
Problem Analysis
The HTTP 500 error occurs when:

Long-running sessions (>45 minutes) have expired ServiceAccount tokens
User switches devices (desktop to mobile), triggering WebSocket reconnection
Backend returns HTTP 500 instead of proper 401 for expired tokens
Runner cannot recover from authentication failures
Root Causes Identified
Token Expiration: Runner ServiceAccount tokens expire after 45 minutes (runnerTokenRefreshTTL in components/operator/internal/handlers/helpers.go)
Backend Error Handling: SSAR failures return HTTP 500 instead of 401 (components/backend/handlers/middleware.go:309)
No Token Refresh: Runner doesn't refresh tokens during reconnection attempts (components/runners/runner-shell/runner_shell/core/transport_ws.py)
Implementation Plan
Phase 1: Immediate Fix - Backend Error Handling
Update components/backend/handlers/middleware.go ValidateProjectContext:

Return HTTP 401 for authentication failures instead of HTTP 500
Add specific error messages to distinguish token expiration from other SSAR failures
Log token validation failures with context

Files to Fix (optional)

components/backend/handlers/middleware.go

Fix Type

Code Formatting

Confirmation

  • I understand this will create an automated PR
  • The changes are low-risk and reversible
  • All tests should continue to pass after fixes

Activity

  1. self-assigned this
    on Dec 5, 2025
  2. added
    ambient-code:auto-fix
    on Dec 5, 2025
  3. github-actions commented on Dec 5, 2025

    @github-actions
    Contributor

    Amber Change Summary

    The following files were modified:

     components/operator/internal/handlers/sessions.go  | 45 +++++++++++++---------
     .../runner-shell/runner_shell/core/transport_ws.py | 23 +++++++++--
     2 files changed, 46 insertions(+), 22 deletions(-)
    
    

    Next Steps:

    • Review that changes match the issue description
    • Verify no scope creep or unintended modifications
    • A PR will be created shortly for formal review

    🔍 View AI decision process (logs available for 90 days)

  4. added a commit that references this issue on Dec 5, 2025
    6fd6440
  5. github-actions commented on Dec 5, 2025

    @github-actions
    Contributor

    🤖 Amber has created a pull request to address this issue: #446

    The changes are ready for review. All automated checks will run on the PR.


    🔍 View AI decision process (logs available for 90 days)

  6. added a commit that references this issue on Feb 7, 2026
    f877c7a
  7. added a commit that references this issue on Feb 24, 2026
    ecbd9cd
  8. added a commit that references this issue on Feb 24, 2026
    bc98688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ambient-code:auto-fix

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions