Skip to content

OCPBUGS-16633: Track API activity for inactivity timeout - #16851

Open
ericahinkleRH wants to merge 1 commit into
openshift:mainfrom
ericahinkleRH:OCPBUGS-16633-fix-token-timeout
Open

OCPBUGS-16633: Track API activity for inactivity timeout#16851
ericahinkleRH wants to merge 1 commit into
openshift:mainfrom
ericahinkleRH:OCPBUGS-16633-fix-token-timeout

Conversation

@ericahinkleRH

@ericahinkleRH ericahinkleRH commented Jul 27, 2026

Copy link
Copy Markdown

Problem

Console client sessions are being deleted before the OAuth server's inactivityTimeoutSeconds expires. This happens because two independent timers race each other:

  1. Frontend timer - tracks user clicks/keydown, fires after 300s of no UI interaction
  2. OAuth server timer - tracks API requests, gets extended by background polling

The frontend timer fires first and explicitly deletes the token before the OAuth server would naturally expire it, causing premature logouts.

Root Cause

Identified by @rluby in the JIRA:

  • Frontend timer only measured clicks/keydown events
  • Console backend makes continuous API requests (resource watches, polling)
  • These API requests extend the OAuth server's inactivityTimeoutSeconds
  • Frontend timer has no knowledge of this API activity
  • Frontend calls logout → explicitly deletes token despite server timeout being extended

Solution

Track API activity by updating the last activity timestamp on every successful API request. This keeps the frontend inactivity timer in sync with actual API usage.

Changes:

  • Created activity-tracker.ts to centralize activity tracking via localStorage
  • Updated coFetch() to call updateLastConsoleActivity() after each successful request
  • Existing onStorageChange listener in masthead-toolbar.tsx detects updates and resets the timer

This aligns frontend inactivity detection with the OAuth server's behavior.

Testing

Manual testing needed with accessTokenInactivityTimeoutSeconds: 300 set on console OAuthClient:

  • Verify token is not deleted while background API requests are active
  • Verify inactivityTimeoutSeconds continues to be extended by API activity
  • Verify logout still works after true inactivity (no clicks AND no API requests)

Fixes: https://issues.redhat.com/browse/OCPBUGS-16633

Summary by CodeRabbit

  • New Features
    • Added shared activity tracking that stores the timestamp of the most recent console activity for inactivity-timeout coordination.
    • Updated console API requests to automatically refresh this activity timestamp after successful calls.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added jira/severity-important Referenced Jira bug's severity is important for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jul 27, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@ericahinkleRH: This pull request references Jira Issue OCPBUGS-16633, which is invalid:

  • expected the bug to target the "5.0.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Problem

Console client sessions are being deleted before the OAuth server's inactivityTimeoutSeconds expires. This happens because two independent timers race each other:

  1. Frontend timer - tracks user clicks/keydown, fires after 300s of no UI interaction
  2. OAuth server timer - tracks API requests, gets extended by background polling

The frontend timer fires first and explicitly deletes the token before the OAuth server would naturally expire it, causing premature logouts.

Root Cause

Identified by @rluby in the JIRA:

  • Frontend timer only measured clicks/keydown events
  • Console backend makes continuous API requests (resource watches, polling)
  • These API requests extend the OAuth server's inactivityTimeoutSeconds
  • Frontend timer has no knowledge of this API activity
  • Frontend calls logout → explicitly deletes token despite server timeout being extended

Solution

Track API activity by updating the last activity timestamp on every successful API request. This keeps the frontend inactivity timer in sync with actual API usage.

Changes:

  • Created activity-tracker.ts to centralize activity tracking via localStorage
  • Updated coFetch() to call updateLastConsoleActivity() after each successful request
  • Existing onStorageChange listener in masthead-toolbar.tsx detects updates and resets the timer

This aligns frontend inactivity detection with the OAuth server's behavior.

Testing

Manual testing needed with accessTokenInactivityTimeoutSeconds: 300 set on console OAuthClient:

  • Verify token is not deleted while background API requests are active
  • Verify inactivityTimeoutSeconds continues to be extended by API activity
  • Verify logout still works after true inactivity (no clicks AND no API requests)

Fixes: https://issues.redhat.com/browse/OCPBUGS-16633

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from Leo6Leo and spadgett July 27, 2026 18:14
@openshift-ci openshift-ci Bot added the component/shared Related to console-shared label Jul 27, 2026
@openshift-ci

openshift-ci Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ericahinkleRH
Once this PR has been reviewed and has the lgtm label, please assign vojtechszocs for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7e24718c-e568-45b3-a67c-10f76d94a442

📥 Commits

Reviewing files that changed from the base of the PR and between f4a5c56 and a070c6b.

📒 Files selected for processing (2)
  • frontend/packages/console-shared/src/utils/activity-tracker.ts
  • frontend/packages/console-shared/src/utils/console-fetch.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/packages/console-shared/src/utils/activity-tracker.ts
  • frontend/packages/console-shared/src/utils/console-fetch.ts

Walkthrough

Adds shared console activity tracking that stores the current timestamp in localStorage and refreshes it after successful coFetch API requests.

Changes

Console activity tracking

Layer / File(s) Summary
Persist and refresh activity timestamps
frontend/packages/console-shared/src/utils/activity-tracker.ts, frontend/packages/console-shared/src/utils/console-fetch.ts
Defines the activity storage key and update function, then invokes it after validateStatus succeeds in coFetch.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: spadgett, leo6leo

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change and includes the Jira issue prefix required by the repository.
Description check ✅ Passed The PR covers problem, root cause, solution, and testing, with only non-critical template sections like screenshots and browser conformance omitted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed PR only changes two utility files; no test declarations or titles were added or modified, so there are no unstable Ginkgo names to flag.
Test Structure And Quality ✅ Passed Patch only changes two frontend TS utility files; no Go/Ginkgo tests were added or edited, so the test-structure check is not applicable.
Microshift Test Compatibility ✅ Passed Only utility code changed; no new Ginkgo e2e tests or MicroShift-unsafe APIs were added.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR only changes frontend utility TS files; no Ginkgo e2e tests were added, so the SNO compatibility check is not applicable.
Topology-Aware Scheduling Compatibility ✅ Passed Only activity-tracking and fetch utilities changed; no manifests, controllers, replicas, or scheduling constraints were introduced.
Ote Binary Stdout Contract ✅ Passed Changed files are utility modules only; no main/init/TestMain/suite setup or stdout-writing calls were added.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests were added; the PR only changes frontend utility code, with no IPv4 assumptions or external connectivity.
No-Weak-Crypto ✅ Passed Changed files only add localStorage timestamp tracking and a fetch hook; no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret comparisons found.
Container-Privileges ✅ Passed Only TS utility files changed; no container/K8s manifests or privilege settings (privileged, hostPID, hostNetwork, hostIPC, SYS_ADMIN, allowPrivilegeEscalation) are present.
No-Sensitive-Data-In-Logs ✅ Passed PASS: The patch only adds localStorage timestamp tracking; it introduces no new log statements or sensitive fields. The existing console.warn is unchanged.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/packages/console-shared/src/utils/activity-tracker.ts`:
- Line 7: Update updateLastConsoleActivity to catch synchronous errors from
localStorage.setItem while preserving successful coFetch resolution; add a test
covering the storage-error case and verifying the activity update does not
reject.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 44bddb4a-51b6-46b9-947d-2efd1c4f8477

📥 Commits

Reviewing files that changed from the base of the PR and between 8f7cf70 and f4a5c56.

📒 Files selected for processing (2)
  • frontend/packages/console-shared/src/utils/activity-tracker.ts
  • frontend/packages/console-shared/src/utils/console-fetch.ts

const LAST_CONSOLE_ACTIVITY_TIMESTAMP_LOCAL_STORAGE_KEY = 'last-console-activity-timestamp';

export const updateLastConsoleActivity = (): void => {
localStorage.setItem(LAST_CONSOLE_ACTIVITY_TIMESTAMP_LOCAL_STORAGE_KEY, Date.now().toString());

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## File: activity-tracker.ts\n'
cat -n frontend/packages/console-shared/src/utils/activity-tracker.ts

printf '\n## Search references\n'
rg -n "LAST_CONSOLE_ACTIVITY_TIMESTAMP_LOCAL_STORAGE_KEY|activity-tracker|track.*Activity|setItem\\(LAST_CONSOLE_ACTIVITY_TIMESTAMP_LOCAL_STORAGE_KEY" frontend/packages/console-shared -S

printf '\n## Potential tests\n'
rg -n "localStorage|activity tracker|console activity|LAST_CONSOLE_ACTIVITY" frontend/packages/console-shared -S --glob '*.{test,spec}.{ts,tsx,js,jsx}'

Repository: openshift/console

Length of output: 2042


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,120p' frontend/packages/console-shared/src/utils/activity-tracker.ts

Repository: openshift/console

Length of output: 543


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## console-fetch.ts\n'
cat -n frontend/packages/console-shared/src/utils/console-fetch.ts

printf '\n## Search for updateLastConsoleActivity call sites\n'
rg -n "updateLastConsoleActivity\\(" frontend/packages/console-shared -S

printf '\n## Search for existing localStorage failure handling patterns\n'
rg -n "try \\{|catch \\(|localStorage\\.setItem|localStorage\\.getItem" frontend/packages/console-shared/src -S

Repository: openshift/console

Length of output: 11571


Catch storage errors in updateLastConsoleActivity. localStorage.setItem can throw synchronously when storage is blocked or full, and this call sits on the successful coFetch path. Catch that failure so successful responses still resolve, and add a test for the storage-error case.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/packages/console-shared/src/utils/activity-tracker.ts` at line 7,
Update updateLastConsoleActivity to catch synchronous errors from
localStorage.setItem while preserving successful coFetch resolution; add a test
covering the storage-error case and verifying the activity update does not
reject.

The console inactivity timer was only tracking user clicks and keydown
events, but not API requests. This caused premature logouts because:

1. Frontend timer measured time since last click/keydown
2. OAuth server measured time since last token usage (API requests)
3. Background API requests (resource watches, polling) extended the
   OAuth server's token timeout
4. Frontend timer fired first and explicitly deleted the token before
   the OAuth server would have expired it naturally

This fix tracks API activity by updating the last activity timestamp
on every successful API request. The existing storage event listener
detects these updates and resets the inactivity timer, keeping the
frontend timer in sync with actual API activity.

Changes:
- Created activity-tracker.ts to centralize activity tracking
- Updated coFetch() to call updateLastConsoleActivity() after each
  successful API request
- Existing onStorageChange listener in masthead-toolbar.tsx handles
  the timestamp updates and resets the timeout

This aligns the frontend inactivity detection with the OAuth server's
behavior, preventing tokens from being deleted while they're still
actively being used by background API requests.
@ericahinkleRH
ericahinkleRH force-pushed the OCPBUGS-16633-fix-token-timeout branch from f4a5c56 to a070c6b Compare July 27, 2026 18:44
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@ericahinkleRH: This pull request references Jira Issue OCPBUGS-16633, which is invalid:

  • expected the bug to target the "5.0.0" version, but no target version was set
  • expected the bug to be in one of the following states: NEW, ASSIGNED, POST, but it is MODIFIED instead

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

Details

In response to this:

Problem

Console client sessions are being deleted before the OAuth server's inactivityTimeoutSeconds expires. This happens because two independent timers race each other:

  1. Frontend timer - tracks user clicks/keydown, fires after 300s of no UI interaction
  2. OAuth server timer - tracks API requests, gets extended by background polling

The frontend timer fires first and explicitly deletes the token before the OAuth server would naturally expire it, causing premature logouts.

Root Cause

Identified by @rluby in the JIRA:

  • Frontend timer only measured clicks/keydown events
  • Console backend makes continuous API requests (resource watches, polling)
  • These API requests extend the OAuth server's inactivityTimeoutSeconds
  • Frontend timer has no knowledge of this API activity
  • Frontend calls logout → explicitly deletes token despite server timeout being extended

Solution

Track API activity by updating the last activity timestamp on every successful API request. This keeps the frontend inactivity timer in sync with actual API usage.

Changes:

  • Created activity-tracker.ts to centralize activity tracking via localStorage
  • Updated coFetch() to call updateLastConsoleActivity() after each successful request
  • Existing onStorageChange listener in masthead-toolbar.tsx detects updates and resets the timer

This aligns frontend inactivity detection with the OAuth server's behavior.

Testing

Manual testing needed with accessTokenInactivityTimeoutSeconds: 300 set on console OAuthClient:

  • Verify token is not deleted while background API requests are active
  • Verify inactivityTimeoutSeconds continues to be extended by API activity
  • Verify logout still works after true inactivity (no clicks AND no API requests)

Fixes: https://issues.redhat.com/browse/OCPBUGS-16633

Summary by CodeRabbit

  • New Features
  • Added shared activity tracking that stores the timestamp of the most recent console activity for inactivity-timeout coordination.
  • Updated console API requests to automatically refresh this activity timestamp after successful calls.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@ericahinkleRH

Copy link
Copy Markdown
Author

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jul 27, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@ericahinkleRH: This pull request references Jira Issue OCPBUGS-16633, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

No GitHub users were found matching the public email listed for the QA contact in Jira (yapei@redhat.com), skipping review request.

Details

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@Leo6Leo

Leo6Leo commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

/ok-to-test

@openshift-ci openshift-ci Bot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Jul 28, 2026
@openshift-ci

openshift-ci Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@ericahinkleRH: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@Leo6Leo

Leo6Leo commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

/pipeline required

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-gcp-console
/test e2e-playwright

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

Labels

component/shared Related to console-shared jira/severity-important Referenced Jira bug's severity is important for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants