Skip to content

Conversation

@deacon-mp
Copy link
Collaborator

@deacon-mp deacon-mp commented Sep 26, 2025

Description

In certain instances the browser for access and the server running Caldera were on two machines thus creating a delta in time. In my testing it actually represented minutes and if the beacon window for an agent was less than that delta it would always show that agent as dead.

I rewrote the logic for the alive, dead, and pending kill to be solely calculated browser side.

This is purely ... I think a UI, user interaction bug fix and does not mess the actual functionality of the agent.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a client-server time synchronization issue affecting agent status display by moving agent status calculations entirely to the browser side. The change addresses cases where time delta between browser and server would incorrectly show agents as dead when the beacon window was smaller than the time difference.

Key changes:

  • Refactored agent status logic to use server-provided timestamps and browser-side calculations
  • Enhanced time parsing utilities to handle various timestamp formats consistently
  • Improved agent lifecycle management with better pending kill state tracking

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/views/AgentsView.vue Main view restructured to compute agent status client-side using server time and config
src/utils/agentUtil.js Rewritten status calculation function to accept server time and config parameters
src/utils/utils.js Enhanced time utilities with robust parsing and conversion functions
src/stores/agentStore.js Added server time capture and pending kill state management
src/components/agents/DetailsModal.vue Updated to use centralized status calculation with proper time handling
src/components/agents/AgentChartStatus.vue Modified chart component to use consistent status calculation approach

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@deacon-mp deacon-mp requested a review from Copilot September 26, 2025 23:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

: a
);
// Flag agent as pending kill immediately
this.agents[idx]._pendingKill = true;
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The agent is being flagged as pending kill twice - once through the map operation and once by direct assignment. The direct assignment on line 113 is redundant since the map operation already handles this.

Suggested change
this.agents[idx]._pendingKill = true;

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it though; I'm not sure during my testing that worked.

Comment on lines +40 to +41
const yesterday = givenMs >= Date.now() - day;
if (yesterday) {
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition is incorrect - it should check if the given timestamp is within the last day, not if it's greater than or equal to yesterday's timestamp. This should be givenMs >= Date.now() - 2 * day.

Suggested change
const yesterday = givenMs >= Date.now() - day;
if (yesterday) {
const now = new Date();
const yesterdayDate = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 1));
const isYesterday =
d.getUTCFullYear() === yesterdayDate.getUTCFullYear() &&
d.getUTCMonth() === yesterdayDate.getUTCMonth() &&
d.getUTCDate() === yesterdayDate.getUTCDate();
if (isYesterday) {

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we go with this suggestion then?

@uruwhy
Copy link
Collaborator

uruwhy commented Oct 6, 2025

@deacon-mp
Does it make sense to calculate agent status browser-side? Since the server is the one receiving all the beacons and has its own clock, shouldn't it be the single source of truth regarding agent status? That way it's not up to the user's browser to do all the calculating - the UI component could just regularly poll for agent status updates to get the latest status information. Seems like a much safer way and less prone to edge cases.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants