Workspace reconciliation logic

This document shows how different events change the database records and how the communication between rails and agentk reflects these events.

Two kinds of workspace reconciliation updates exist: full and partial. For more information, see Types of messages.

Modeling scenarios for partial synchronization

  • request - The event that occurs. CURRENT_DB_STATE describes the state of the database before any event occurs.
  • include config_to_apply in workspace_rails_info response?
    • For events CURRENT_DB_STATE and USER_ACTION, this is not applicable. Signified by a -.
    • For events AGENT_ACTION - Based on the state of the database before the database is updated by the information received from agentk about the workspace, should Rails send the config_to_apply information to agentk based on the condition desired_state_updated_at >= responded_to_agent_at?
  • include deployment_resource_version in workspace_rails_info response? - Should Rails send the deployment_resource_version information to agentk?
    • This field is not shown in the table below for brevity as it always evaluates to true in the scenarios below (except for the one scenario where it is called out).
    • Rules of evaluation:
      • If information about the workspace was received from agentk, then Yes
      • If configuration to apply for the workspace is being sent to agentk, then Yes
      • Else, No
  • desired_state_updated_at, responded_to_agent_at, desired_state, actual_state - The state of the database after the event occurs
  • responded_to_agent_at is always updated to the current timestamp when Rails responds to agent with information about the workspace. The information can include config_to_apply or deployment_resource_version or both.

desired: Running / actual: CreationRequested → desired: Running / actual: Running

New workspace is requested by the user which results in a Running actual state.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Empty database-
USER_ACTION - User has requested a new workspace-RunningCreationRequested05:00
AGENT_ACTION - agentk reports no infoYRunningCreationRequested05:0005:01
AGENT_ACTION - agentk reports it as StartingNRunningStarting05:0005:02
AGENT_ACTION - agentk reports it as RunningNRunningRunning05:0005:03

desired: Running / actual: CreationRequested → desired: Running / actual: Failed

New workspace is requested by the user which results in a Failed actual state (for example, the container is crashing).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Empty database-
USER_ACTION - User has requested a new workspace-RunningCreationRequested05:00
AGENT_ACTION - agentk reports no infoYRunningCreationRequested05:0005:01
AGENT_ACTION - agentk reports it as StartingNRunningStarting05:0005:02
AGENT_ACTION - agentk reports it as FailingNRunningFailed05:0005:03

desired: Running / actual: CreationRequested → desired: Running / actual: Error

New workspace is requested by the user which results in an Error actual state (for example, failed to apply Kubernetes resources).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Empty database-
USER_ACTION - User has requested a new workspace-RunningCreationRequested05:00
AGENT_ACTION - agentk reports no infoYRunningCreationRequested05:0005:01
AGENT_ACTION - agentk reports it as ErrorNRunningError05:0005:02

desired: Running / actual: Running → desired: Stopped / actual: Stopped

Running workspace is stopped by the user which results in a Stopped actual state.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Running state-RunningRunning05:0005:01
USER_ACTION - User stops the workspace-StoppedRunning05:0205:01
AGENT_ACTION - agentk reports no infoYStoppedRunning05:0205:03
AGENT_ACTION - agentk reports it as StoppingNStoppedStopping05:0205:04
AGENT_ACTION - agentk reports it as StoppedNStoppedStopped05:0205:05

desired: Running / actual: Running → desired: Stopped / actual: Failed

Running workspace is stopped by the user which results in a Failed actual state (for example, could not unmount volume and stop the workspace).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Running state-RunningRunning05:0005:01
USER_ACTION - User stops the workspace-StoppedRunning05:0205:01
AGENT_ACTION - agentk reports no infoYStoppedRunning05:0205:03
AGENT_ACTION - agentk reports it as StoppingNStoppedStopping05:0205:04
AGENT_ACTION - agentk reports it as FailedNStoppedFailed05:0205:05

desired: Running / actual: Running → desired: Stopped / actual: Error

Running workspace is stopped by the user which results in an Error actual state (for example, failed to apply Kubernetes resources).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Running state-RunningRunning05:0005:01
USER_ACTION - User stops the workspace-StoppedRunning05:0205:01
AGENT_ACTION - agentk reports no infoYStoppedRunning05:0205:03
AGENT_ACTION - agentk reports it as ErrorNStoppedError05:0205:04

desired: Running / actual: Running → desired: Terminated / actual: Terminated

Running workspace is terminated by the user which results in a Terminated actual state.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Running state-RunningRunning05:0005:01
USER_ACTION - User terminates the workspace-TerminatedRunning05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedRunning05:0205:03
AGENT_ACTION - agentk reports it as TerminatedNTerminatedTerminated05:0205:04

desired: Running / actual: Running → desired: Terminated / actual: Failed

Running workspace is terminated by the user which results in a Failed actual state (for example, could not unmount volume and terminate the workspace).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Running state-RunningRunning05:0005:01
USER_ACTION - User terminates the workspace-TerminatedRunning05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedRunning05:0205:03
AGENT_ACTION - agentk reports it as FailedNTerminatedFailed05:0205:04

desired: Running / actual: Running → desired: Terminated / actual: Error

Running workspace is terminated by the user which results in an Error actual state (for example, failed to apply Kubernetes resources).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Running state-RunningRunning05:0005:01
USER_ACTION - User terminates the workspace-TerminatedRunning05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedRunning05:0205:03
AGENT_ACTION - agentk reports it as ErrorNTerminatedError05:0205:04

desired: Stopped / actual: Stopped → desired: Running / actual: Running

Stopped workspace is started by the user which results in a Running actual state.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Stopped state-StoppedStopped05:0005:01
USER_ACTION - User starts the workspace-RunningStopped05:0205:01
AGENT_ACTION - agentk reports no infoYRunningStopped05:0205:03
AGENT_ACTION - agentk reports it as StartingNRunningStarting05:0205:04
AGENT_ACTION - agentk reports it as RunningNRunningRunning05:0205:05

desired: Stopped / actual: Stopped → desired: Running / actual: Failed

Stopped workspace is started by the user which results in a Failed actual state (for example, container is crashing).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Stopped state-StoppedStopped05:0005:01
USER_ACTION - User starts the workspace-RunningStopped05:0205:01
AGENT_ACTION - agentk reports no infoYRunningStopped05:0205:03
AGENT_ACTION - agentk reports it as StartingNRunningStarting05:0205:04
AGENT_ACTION - agentk reports it as FailedNRunningFailed05:0205:05

desired: Stopped / actual: Stopped → desired: Running / actual: Error

Stopped workspace is started by the user which results in an Error actual state (for example, failed to apply Kubernetes resources).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Stopped state-StoppedStopped05:0005:01
USER_ACTION - User starts the workspace-RunningStopped05:0205:01
AGENT_ACTION - agentk reports no infoYRunningStopped05:0205:03
AGENT_ACTION - agentk reports it as ErrorNRunningError05:0205:04

desired: Stopped / actual: Stopped → desired: Terminated / actual: Terminated

Stopped workspace is terminated by the user which results in a Terminated actual state.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Stopped state-StoppedStopped05:0005:01
USER_ACTION - User terminates the workspace-TerminatedStopped05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedStopped05:0205:03
AGENT_ACTION - agentk reports it as TerminatedNTerminatedTerminated05:0205:04

desired: Stopped / actual: Stopped → desired: Terminated / actual: Failed

Stopped workspace is terminated by the user which results in a Failed actual state (for example, could not unmount volume and terminate the workspace).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Stopped state-StoppedStopped05:0005:01
USER_ACTION - User terminates the workspace-TerminatedStopped05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedStopped05:0205:03
AGENT_ACTION - agentk reports it as FailedNTerminatedFailed05:0205:04

desired: Stopped / actual: Stopped → desired: Terminated / actual: Error

Stopped workspace is terminated by the user which results in an Error actual state (for example, failed to apply Kubernetes resources).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Stopped state-StoppedStopped05:0005:01
USER_ACTION - User terminates the workspace-TerminatedStopped05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedStopped05:0205:03
AGENT_ACTION - agentk reports it as ErrorNTerminatedError05:0205:04

desired: Running / actual: Failed → desired: Running / actual: Running

Failed workspace becomes ready which results in a Running actual state (for example, container is no longer crashing).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Failed state-RunningFailed05:0005:01
AGENT_ACTION - agentk reports it as StartingNRunningStarting05:0005:02
AGENT_ACTION - agentk reports it as RunningNRunningRunning05:0005:03

desired: Running / actual: Failed → desired: Stopped / actual: Stopped

Failed workspace is stopped by the user which results in a Stopped actual state.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Failed state-RunningFailed05:0005:01
USER_ACTION - User stops the workspace-StoppedFailed05:0205:01
AGENT_ACTION - agentk reports no infoYStoppedFailed05:0205:03
AGENT_ACTION - agentk reports it as StoppingNStoppedStopping05:0205:04
AGENT_ACTION - agentk reports it as StoppedNStoppedStopped05:0205:05

desired: Running / actual: Failed → desired: Stopped / actual: Failed

Failed workspace is stopped by the user which results in a Failed actual state (for example, could not unmount the volume and stop the workspace).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Failed state-RunningFailed05:0005:01
USER_ACTION - User stops the workspace-StoppedFailed05:0205:01
AGENT_ACTION - agentk reports no infoYStoppedFailed05:0205:03
AGENT_ACTION - agentk reports it as FailedNStoppedFailed05:0205:04

desired: Running / actual: Failed → desired: Stopped / actual: Error

Failed workspace is stopped by the user which results in an Error actual state (for example, failed to apply Kubernetes resources).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Failed state-RunningFailed05:0005:01
USER_ACTION - User stops the workspace-StoppedFailed05:0205:01
AGENT_ACTION - agentk reports no infoYStoppedFailed05:0205:03
AGENT_ACTION - agentk reports it as ErrorNStoppedError05:0205:04

desired: Running / actual: Failed → desired: Terminated / actual: Terminated

Failed workspace is terminated by the user which results in a Terminated actual state.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Failed state-RunningFailed05:0005:01
USER_ACTION - User terminates the workspace-TerminatedFailed05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedFailed05:0205:03
AGENT_ACTION - agentk reports it as TerminatedNTerminatedTerminated05:0205:04

desired: Running / actual: Failed → desired: Terminated / actual: Failed

Failed workspace is terminated by the user which results in a Failed actual state (for example, could not unmount volume and terminate the workspace).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Failed state-RunningFailed05:0005:01
USER_ACTION - User terminates the workspace-TerminatedFailed05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedFailed05:0205:03
AGENT_ACTION - agentk reports it as FailedNTerminatedFailed05:0205:04

desired: Running / actual: Failed → desired: Terminated / actual: Error

Failed workspace is terminated by the user which results in an Error actual state (for example, failed to apply Kubernetes resources).

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Failed state-RunningFailed05:0005:01
USER_ACTION - User terminates the workspace-TerminatedFailed05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedFailed05:0205:03
AGENT_ACTION - agentk reports it as ErrorNTerminatedError05:0205:04

desired: Running / actual: Error → desired: Stopped / actual: Error

Error workspace is stopped by the user which results in an Error actual state (for example, failed to apply Kubernetes resources).

This transition might not be allowed.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Failed state-RunningFailed05:0005:01
USER_ACTION - User terminates the workspace-TerminatedFailed05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedFailed05:0205:03
AGENT_ACTION - agentk reports it as ErrorNTerminatedError05:0205:04

desired: Running / actual: Error → desired: Terminated / actual: Error

Error workspace is terminated by the user which results in an Error actual state (for example, failed to apply Kubernetes resources).

This transition might not be allowed. Further evaluation is needed to determine if uncleaned state is left behind if this isn’t allowed. Consider what happens if the workspace was never created in the first place, or if the workspace was successfully created but entered the Error state while it was being stopped.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Failed state-RunningFailed05:0005:01
USER_ACTION - User terminates the workspace-TerminatedFailed05:0205:01
AGENT_ACTION - agentk reports no infoYTerminatedFailed05:0205:03
AGENT_ACTION - agentk reports it as ErrorNTerminatedError05:0205:04

Other scenarios

Agent reports update for a workspace and user has also updated desired state of the workspace

This scenario shows when agentk is reporting on a workspace and the user has also performed an action on the workspace. This highlights that this logic works even in cases where there is new information on both sides (agent and Rails).

Details of the scenario:

  • Workspace was earlier running
  • Workspace has now started crashing (Failed state)
  • User stops the workspace because they no longer need it (without being aware that the workspace has started crashing)
requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Running state-RunningRunning05:0005:01
USER_ACTION - User stops the workspace-StoppedRunning05:0205:01
AGENT_ACTION - agentk reports it as FailedYStoppedFailed05:0205:03
AGENT_ACTION - agentk reports it as StoppingNStoppedStopping05:0205:04
AGENT_ACTION - agentk reports it as StoppedNStoppedStopped05:0205:05

Restarting a workspace

Running workspace is restarted by the user which results in a Running actual state.

requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Running state-RunningRunning05:0005:01
User restarts the workspace-RestartRequestedRunning05:0205:01
AGENT_ACTION - agentk reports no infoYRestartRequestedRunning05:0205:03
AGENT_ACTION - agentk reports it as StoppingNRestartRequestedStopping05:0205:04
AGENT_ACTION - agentk reports it as Stopped, desired_state automatically changed to RunningYRunningStopped05:0505:05
AGENT_ACTION - agentk reports it as StartingNRunningStarting05:0505:07
AGENT_ACTION - agentk reports it as RunningNRunningRunning05:0505:08

No update for workspace from agentk or from user

Since Rails does not information about this workspace in the response to agentk:

  • include deployment_resource_version in workspace_rails_info response? is set to N
  • responded_to_agent_at is not updated
requestinclude config_to_apply in workspace_rails_info response?desired_stateactual_statedesired_state_updated_atresponded_to_agent_at
CURRENT_DB_STATE - Workspace is in Running state-RunningRunning05:0005:01
AGENT_ACTION - agentk reports no infoNRunningRunning05:0005:01

The Unknown actual state has not been modeled yet because when that would occur and what would happen is not known. Unknown is a fail-safe state which should never occur ideally.